I have two polylines whose endpoints are near to each other, but do not overlap. I've put them into this shapefile. I want to use shapely's ops.snap() to snap their endpoints, but it's not working as expected.
from shapely import ops
import geopandas as gpd
wontsnap = gpd.read_file(path_to_wontsnap)
g1 = wontsnap.geometry.values[0]
g2 = wontsnap.geometry.values[1]
If I check the distance between the geometries, I get
g1.distance(g2)
Out[661]: 0.0006421029901831172
This agrees (roughly) with the measure tool in QGIS:
Now if I try to snap the two geometries with a tolerance that is greater than the distance between their endpoints:
snapped = ops.snap(g1, g2, 0.001)
The snapped object contains only the g1 geometry. I.e., they don't snap.
If I increase the tolerance by 10x:
snapped = ops.snap(g1, g2, 0.01)
The snapped object includes both geometries, snapped correctly.
If I trim the g1 and g2 geometries to the last and first 10 points, respectively, snapping works as expected.
I have tried various tolerances between 0.001 and 0.01--the geometries will snap at 0.003 but not 0.002. At this point I can only assume this is a bug in shapely--any ideas?
I have posted this as a bug report in the shapely repository. It appears to be a bug.
