The nearest_points() function in shapely.ops calculates the nearest points in a pair of geometries.
shapely.ops中的nearest_points()函数计算得到一对几何对象中最近的点。
- shapely.ops.nearest_points(geom1, geom2)
Returns a tuple of the nearest points in the input geometries. The points are returned in the same order as the input geometries.
返回输入几何对象中最近的一组点组成的元组。这些点的返回顺序与输入几何对象的顺序相同。
New in version 1.4.0.
>>> from shapely.ops import nearest_points
>>> triangle = Polygon([(0, 0), (1, 0), (0.5, 1), (0, 0)])
>>> square = Polygon([(0, 2), (1, 2), (1, 3), (0, 3), (0, 2)])
>>> [o.wkt for o in nearest_points(triangle, square)]
['POINT (0.5 1)', 'POINT (0.5 2)']
Note that the nearest points may not be existing vertices in the geometries.
注意,最近的点可能不是几何对象中现有的顶点。