Skip to content
Advertisement

TopologicalError: The operation ‘GEOSIntersection_r’ could not be performed

Hi Guys, I am trying to map the district shapefile into assembly constituencies. I have shape files for Both.Basically I have to map all the variables given at district level in census data to assembly constituency level. So I am following a pycon talk. Everything is working fine but I am getting error in get_intersection function.Error for that is TopologicalError: The operation 'GEOSIntersection_r' could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x7f460250ce10>.

I have tried to use both pygeos and rtree. There were some links which said that problem is in pygeos. So,I used rtree.But of no avail.Please help Thanks in advance.

Code tried by me is

JavaScript
JavaScript

Advertisement

Answer

The error message tells you exactly what is going on. Some of your geometries are not valid, so you have to make them valid before doing your apply. The simple trick, which works in most of the cases is using buffer(0).

JavaScript

Since the issue is with geometry validity and is raised by GEOS, it does not matter if you use shapely/rtree backend or pygeos.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement