本文介绍了获取Point的任一侧的LineString上的顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个漂亮的
在 LineString $ c $中找到线段c>重点在哪里。然后相应地将 LineString 的顶点分成两组。要找到线段,只需对每个线段应用点/线段交点测试。
from shapely.geometry import点, LineString
def split(line_string,point):
coords = line_string.coords
j = None
我在范围内(len(coords) - 1):
如果LineString(coords [i:i + 2])。intersects(point):
j = i
break
assert j不是None
#如果Point(coords [j + 1:j + 2])。equals(point):
返回coords,请务必在第一组
中包含该点[ :j + 2],coords [j + 1:]
else:
返回coords [:j + 1],coords [j:]
pre>I have a shapely LineString and have defined a shapely Point which lies along the LineString.
How can I find the vertices of the LineString which lie either side of the point? (split the line in two)
解决方案Locate the line segment in the LineString where the point lies. Then split in two groups the vertices of the LineString accordingly. To locate the line segment, simply apply a point / line segment intersection test to each segment.
from shapely.geometry import Point,LineString def split(line_string, point): coords = line_string.coords j = None for i in range(len(coords) - 1): if LineString(coords[i:i + 2]).intersects(point): j = i break assert j is not None # Make sure to always include the point in the first group if Point(coords[j + 1:j + 2]).equals(point): return coords[:j + 2], coords[j + 1:] else: return coords[:j + 1], coords[j:]
这篇关于获取Point的任一侧的LineString上的顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!