【GIS】【shapely】【trimLine】

from shapely.geometry import Point, LineString
from shapely.ops import split

def trimLine(line, p1, p2):
# 根据p1,p2截取line上的一段
# 这里要求p1, p2在线line上
gs = split(line, p1)
gs = [split(_, p2) for _ in gs if _.intersects(p2)][0]
res = [_ for _ in gs if _.intersects(p1)][0]

return res


if __name__ == '__main__':

arr = [[0, 0], [10, 0]]
brr = [3, 0]
crr = [7, 0]
line = LineString(arr)
p1 = Point(brr)
p2 = Point(crr)

res = trimLine(line, p1, p2)
posted @ 2021-04-25 15:21  ddzhen  阅读(123)  评论(0编辑  收藏  举报