I have one GeoDataFrame which contains two geometry fields - one is polygon and one is the polygon centroids. The table has also other fields.

I have run spatial join between the gdf and another shapefile of the regions (e.g the shapefile has many polygons of different regions). I have used "op='within' in order to speed it up (and it did):

join=gpd.sjoin(gdf, regions, how='left',op='within')

The problem is that the join didn't work when the polygons touched the borders of the regions' polygons.

For example, here you can see that polygons that are inside specific region have a peach color, the ones outside are green but the ones touching the border are purple:
enter image description here

I believe that if I would use the centroids instead of the full polygons, I could get better results.
Is it possible to tell GeoPandas which geometry column to use?

I have tried to use the set geometry, then do the spatial join and then change it as well:

join=gpd.sjoin(df, regions, how='left',op='within')

but I still got the same results.


1 Answer 1


In the end what worked was to use the set_geometry() to the centroids, do the spatial join and then to set_geometry to the original geometry :

join=gpd.sjoin(df, regions, how='left',predicate='within')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.