I am trying to implement an undershoot fixer using GeoPandas and Shapely like the solution from Snapping in Geopandas
My other thought is that it might reasonable to identify and extend the undershot segments so that the line geometries extend that way.... My sample geodataframe has 2 linestrings. I would like to have OBJECTID 2248 snapped to 2374. I'm not sure if I'm approaching this correctly.
Sample data - dfSamp:
OBJECTID = [2248, 2374]
geometry = [<LINESTRING Z (-80.477 35.667 0, -80.476 35.667 0, -80.476 35.667 0)>, <LINESTRING Z (-80.476 35.667 0, -80.476 35.667 0, -80.478 35.667 0)>]
Code I've tried from Snapping in Geopandas returns a results very similar to the original formatted sample data:
import geopandas as gpd
from shapely.ops import snap
tolerance = 0.0001
for index, row in dfSamp.iterrows():
tmp_gdf = dfSamp.copy()
tmp_gdf['distance'] = tmp_gdf.distance(row['geometry'])
closest_geom = list(tmp_gdf.sort_values('distance')['geometry'])[2]
snapped_geom = snap(row['geometry'], closest_geom, tolerance)
dfSamp.loc[index, 'geometry'] = snapped_geom