I want to join a GeoDataFrame with Polygons (circular, were created from Points with buffer) with a GeoDataFrame that has Linestrings. These polygons and lines do not necessarily intersect nor contain each other (might have a polygon in between two lines), and I would like to join them based on which polygon is closest to a linestring.
Is there a way to do so using GeoPandas (not using ArcPy)?
df_pts: df_lines: id | geometry id | geometry p1 | POLYGON( .. ) l8 | LINESTRING( .. ) p2 | POLYGON( .. ) l11| LINESTRING( .. )
What I have tried so far:
import geopandas as gpd from shapely.geometry import Point, LineString df_pts['buffer'] = df_pts.geometry.buffer(2) df_lines = gpd.read_file('from_shape_file.shp') df_join = gpd.sjoin(df_pts, df_lines, how="inner", op='intersects')
The problem with my current code is that it will miss cases where the buffered points in df_pts aren't 'touching' the lines.