NDR - RuntimeError: In Task: mask runoff proxy raster

What is the issue or question you have? Hello,

I can’t run the NDR model, this error appears RuntimeError: In Task: mask runoff proxy raster.
I already have the latest Invest version and redownloaded sample data several times.
Here is my logfile
InVEST-natcap.invest.ndr.ndr-log-2023-09-13–12_00_21.txt (4.3 KB)

Than you for your patient.

Hello, good afternoon. I imagine it’s an error in the raster files, which contain polygon and multipolygon features, perhaps one is overlapping the other. I suggest you check this again. Also, check the attribute table and the correspondence with the csv file. I hope I’ve helped.

1 Like

Hi @AnaCastro -

Thanks for posting your log file. It shows these warnings and errors:

2023-09-13 12:00:22,745 (osgeo) utils._log_gdal_errors(97) WARNING [errno 1] Ring Self-intersection at or near point 12344.008690871298 218998.69285557925
2023-09-13 12:00:22,747 (osgeo) utils._log_gdal_errors(97) ERROR [errno 1] Cutline polygon is invalid.
2023-09-13 12:00:22,747 (taskgraph.Task) Task.add_task(706) ERROR Something went wrong when adding task mask runoff proxy raster (2)

If you search this forum, you’ll find several threads related to this, for example this one, which includes several methods for fixing polygon geometries.

~ Stacie

1 Like

The thing is that this same map runs with no problem in the other ES (water yield, SDR, CS), so I don’t understand why it doesn’t work in this one specifically…

I fixed the geometries of my map in QGIS but the error persists.
InVEST-natcap.invest.ndr.ndr-log-2023-09-14–08_51_36.txt (4.3 KB)

1 Like

The failure is happening in this model and not others because of the specific way that the input rasters are being masked to the polygon boundary. This is an unfortunate technical detail of the underlying library we use for interfacing with many spatial file formats.

@AnaCastro could you share your complete set of inputs for this model with us so we can take a closer look? I think this will be easier to debug by looking at the actual data, and this will help us find a more general solution as well.


1 Like

Than you for you help!
Here is my data: Invest_NDR - Google Drive
I am using “swat_subbasins” as “watersheds”, “precipitation.tif” as “Nutrient Runnof Proxy” ,Threshold FLow Accumulation = 1000 and Borselli K parameter=2.
The objective is to map this ecosystem service fot two LULC scenarios (COS2018 and future).
Thank you!

Hello @AnaCastro ,

It turns out that GDAL is complaining (and failing the runoff proxy masking step) because there are 3 watersheds that have ring self-intersections, which GDAL considers invalid. Using QGIS’s validity checker (in GEOS mode, which is consistent with how GDAL uses geometries), there are 3 watersheds with self-intersections, plotted as points here:

And a closeup of the eastern-most one:

I fixed this geometry using a python environment and geopandas using the following:

>>> gdf = geopandas.read_file('swat_subbasins.shp')
>>> bgdf = gdf['geometry'].buffer(0)
>>> bgdf.to_file('subbasins_buf0.shp')

And the resulting vector (attached below) works fine.

subbasins_buf0.zip (139.9 KB)

Having said that, this part of the NDR model could be more resilient to minor geometry errors like these, and I will see about updating it.

Hope this helps!

1 Like

It helped!
Thank you, I am so relieved :sweat_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.