我得到了以下代码:
from shapely.geometry import LineString, Point
xs = range(10)
ys = range(10)
points = [Point(x, y) for x, y in zip(x, y)]
line = LineString(points)现在我想编辑这样的点,如果两个相邻的点比MIN_DISTANCE更近,那么我想删除后一个:即从line=[(1, 1), (1.1, 1.1), (3, 3)], MIN_DISTANCE=2中我将获得line=[(1, 1), (3, 3)]。
是否可以编写一个强力解决方案(例如,for point in line)并覆盖直线上的点,或者是否有一个内置的函数?
发布于 2019-10-07 17:31:15
您可以使用simplify方法来实现此目的:
new_line = line.simplify(tolerance=MIN_DISTANCE)对于您的示例,它将是:
from shapely.geometry import LineString, Point
xs = range(10)
ys = range(10)
x, y = zip(*[(1, 1), (1.1, 1.1), (3, 3)])
points = [Point(x, y) for x, y in zip(x, y)]
line = LineString(points)
MIN_DISTANCE = 2
new_line = line.simplify(tolerance=MIN_DISTANCE)
print(f"Original coordinates: {line.xy}")
print(f"Simplified coordinates: {new_line.xy}")
# Original coordinates: (array('d', [1.0, 1.1, 3.0]), array('d', [1.0, 1.1, 3.0]))
# Simplified coordinates: (array('d', [1.0, 3.0]), array('d', [1.0, 3.0]))https://stackoverflow.com/questions/56164410
复制相似问题