shapely.snap#

snap(geometry, reference, tolerance, **kwargs)#

Snaps an input geometry to reference geometry’s vertices.

The tolerance is used to control where snapping is performed. The result geometry is the input geometry with the vertices snapped. If no snapping occurs then the input geometry is returned unchanged.

Parameters
geometryGeometry or array_like
referenceGeometry or array_like
tolerancefloat or array_like
**kwargs

For other keyword-only arguments, see the NumPy ufunc docs.

Examples

>>> from shapely import LineString, Point, Polygon
>>> point = Point(0.5, 2.5)
>>> target_point = Point(0, 2)
>>> snap(point, target_point, tolerance=1)
<POINT (0 2)>
>>> snap(point, target_point, tolerance=0.49)
<POINT (0.5 2.5)>
>>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> snap(polygon, Point(8, 10), tolerance=5)
<POLYGON ((0 0, 0 10, 8 10, 10 0, 0 0))>
>>> snap(polygon, LineString([(8, 10), (8, 0)]), tolerance=5)
<POLYGON ((0 0, 0 10, 8 10, 8 0, 0 0))>