The snap()
function in shapely.ops snaps the vertices in one geometry to the vertices in a second geometry with a given tolerance.
shapely.ops中的snap()函数将一个几何体中的顶点与第二个几何体中的顶点以给定的容差对齐。
- shapely.ops.snap(geom1, geom2, tolerance)
Snaps vertices in geom1 to vertices in the geom2. A copy of the snapped geometry is returned. The input geometries are not modified.
将geom1中的顶点与geom2中的顶点对齐。被捕捉的几何体对象副本会被返回。输入的几何对象不会被修改。
The tolerance argument specifies the minimum distance between vertices for them to be snapped.
容差参数指定了执行对齐操作的顶点之间的最小距离。
New in version 1.5.0
>>> from shapely.ops import snap
>>> square = Polygon([(1,1), (2, 1), (2, 2), (1, 2), (1, 1)])
>>> line = LineString([(0,0), (0.8, 0.8), (1.8, 0.95), (2.6, 0.5)])
>>> result = snap(line, square, 0.5)
>>> result.wkt
'LINESTRING (0 0, 1 1, 2 1, 2.6 0.5)'