Skip to content
Advertisement

geopandas known intersection returns False

I have two sets of multipolygons. I want to select one polygon from one dataset (by using the matplotlib click event which works) and then select all polygons from the second dataset that intersect with it. When I plot the datasets they clearly overlap (see below) but my intersection always returns False.

The datasets look like this:

enter image description here

I select one of the red polygons using a click event which I have simulated here:

JavaScript

This returns:

JavaScript

But when I try intersecting with my second dataset (black boxes) like this:

JavaScript

this returns False for all records of Dataset 2, but shouldn’t at least one of them be True?:

JavaScript

I do get the warning:

JavaScript

but I don’t know if this is causing this. I’m effectively trying to intersect a df with one row with another df with lots of rows to end up with intersecting polygons only. Am I Missing something?

Advertisement

Answer

You do not select one polygon but one row of the GeoDataFrame. Therefore you are using an intersects on a Series, not a Polygon. As shown in the documentation, geopandas aligns those series and do row-wise 1:1 operation. You need to pass a shapely.geometry if you want to check all rows against a single geometry.

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