I have a shapely LineString and have defined a shapely Point which lies along the LineString.
How can I find the vertices of t
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:]