Python – How to Find Intersection of Two GeoDataFrames Using GeoPandas

geopandasintersectionoverlapping-featurespolygonpython

I have two GeoDataFrames:

  • The first one is a large grid (many small bounding boxes), each row is a bounding box saved as a polygon.
  • The second one contains just a few polygons (one polygon per row).

I would like to keep only the bounding boxes that intersect with the polygons of the second dataset (see image below).

enter image description here

Best Answer

Assuming you want to keep the grid polygons intact and just select out those that intersect with the other polygons and not just the part of each grid polygon that intersects with the other polygons.

You can use a spatial join (sjoin with predicate = "inner") or a spatial selection (intersects):

poly_grid = grid.sjoin(polys, how="inner")

poly_grid = grid[grid.intersects(polys.dissolve().geometry.iloc[0])]