UFRM - The operation 'GEOSIntersection_r' could not be performed

Hi everyone,

I am struggling with my Urban Flood Risk Mitigation model. I always receive “TopologicalError: The operation ‘GEOSIntersection_r’ could not be performed. Likely cause is invalidity of the geometry” when running my model.

I checked the log and found the problem is the Built Infrastructure vector.
So, I tried Repair Geometry in ArcGIS, didn’t help.
Tried Fix Geometries in QGIS, didn’t help.
Tried Fix Geometries + Dissolve in QGIS, didn’t help.
Tried Repair Geometry + Dissolve in ArcGIS, didn’t help.
Tried Fix Geometries in QGIS + Dissolve in ArcGIS, didn’t’ help.

Could please you give me a hand?

Below is my log:

2021-04-28 10:56:56,123 geoprocessing.zonal_statistics(1460) DEBUG remaining unset_fids: 0 of 2
2021-04-28 10:56:56,123 geoprocessing.zonal_statistics(1468) INFO all done processing polygon sets for reprojected_aoi.gpkg
2021-04-28 10:56:56,159 geoprocessing.reproject_vector(1711) INFO starting reprojection
2021-04-28 10:56:56,221 geoprocessing.reproject_vector(1754) INFO reprojection 100.0% complete on structures_reprojected.gpkg
2021-04-28 10:56:56,371 geos.callback(252) ERROR TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point 120.19836341801903 30.324019001062968 at 120.19836341801903 30.324019001062968
2021-04-28 10:56:56,371 geos.callback(252) INFO Ring Self-intersection at or near point 120.19836341801903 30.324019001062968
2021-04-28 10:56:56,371 Task.add_task(781) ERROR Something went wrong when adding task calculate damage to infrastructure in aoi (12), terminating taskgraph.
Traceback (most recent call last):
File “site-packages\taskgraph\Task.py”, line 747, in add_task
File “site-packages\taskgraph\Task.py”, line 1234, in _call
File “site-packages\natcap\invest\urban_flood_risk_mitigation.py”, line 607, in _calculate_damage_to_infrastructure_in_aoi
File “site-packages\shapely\geometry\base.py”, line 676, in intersection
File “site-packages\shapely\topology.py”, line 70, in call
File “site-packages\shapely\topology.py”, line 38, in _check_topology
shapely.errors.TopologicalError: The operation ‘GEOSIntersection_r’ could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x0000018E3422C4C8>
2021-04-28 10:56:56,372 model._logged_target(1652) ERROR Exception while executing <function execute at 0x0000018E2DBCB9D8>
Traceback (most recent call last):
File “site-packages\natcap\invest\ui\model.py”, line 1649, in _logged_target
File “site-packages\natcap\invest\urban_flood_risk_mitigation.py”, line 387, in execute
File “site-packages\taskgraph\Task.py”, line 747, in add_task
File “site-packages\taskgraph\Task.py”, line 1234, in _call
File “site-packages\natcap\invest\urban_flood_risk_mitigation.py”, line 607, in _calculate_damage_to_infrastructure_in_aoi
File “site-packages\shapely\geometry\base.py”, line 676, in intersection
File “site-packages\shapely\topology.py”, line 70, in call
File “site-packages\shapely\topology.py”, line 38, in _check_topology
shapely.errors.TopologicalError: The operation ‘GEOSIntersection_r’ could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x0000018E3422C4C8>
2021-04-28 10:56:56,374 model._logged_target(1655) INFO Execution finished
2021-04-28 10:56:56,375 utils.prepare_workspace(129) INFO Elapsed time: 25.18s

Hi @WHZ1207 , thanks for posting. I agree these problems can be a struggle. Everything you’ve tried was a good idea and it’s a bit frustrating that none of it worked. Here’s a couple more ideas that have worked for me in the past (though each situation is a little different)

  • Run a buffer with a width of 0. QGIS can do this, historically Arc could not. I think it works because it has a side-effect of introducing a new vertex at the self-intersection point. And it won’t otherwise change the geometry at all.
  • Since there seems to be only one very precise location with invalid geometry, it should be possible to zoom wayyyy into that point and actually see the problem and correct it by editing the geometry manually. In QGIS/Arc editing mode, either add a vertex at the self-intersection point or delete/move other vertices so there is no self-intersection.

If none of that works, feel free to upload the offending file here and I can take a look. Good luck!

1 Like

Dave, thanks for your reply!!! :grinning:
The first suggestion works for me! (Also, I checked the geometry validity of my watershed vector.)
Thanks again!

1 Like

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