【问题标题】:calculate the intersection point of a line to a Linestring and define the Linestring segment using shapely计算线与线串的交点并使用 shapely 定义线串段
【发布时间】:2014-11-28 16:24:15
【问题描述】:
Line1_string=LineString([(1,4),(3,4),(3,3),(3.5,2),(4.5,1),(6,1)])

line2_string=LineString([(5,4),(2,1)])

这两个对象是使用来自shapely.geometryLineString创建的

我可以使用Line1_string.intersection(line2_string).coords 找到交点,但我还想定义Line_string1 的线段,这两条线的交点是以自动方式发生的。

到目前为止,我遇到了这个答案 [a link] (Get the vertices on a LineString either side of a Point),但我从定义的拆分函数中得到了一个无输出。

有什么可能出错的想法或任何其他建议吗?

【问题讨论】:

    标签: python shapely


    【解决方案1】:

    Line1_string分解成一个简单的线段列表,并检查每个线段是否相交。

    使用pairwise recipe from itertools

    from itertools import tee
    def pairwise(iterable):
        "s -> (s0,s1), (s1,s2), (s2, s3), ..."
        a, b = tee(iterable)
        next(b, None)
        return izip(a, b)
    
    # Convert input line into list of line segments
    Line1_segs = [LineString(p) for p in pairwise(Line1_string.coords[:])]
    
    # Find the intersections
    intersect_segs = [i for i, s in enumerate(Line1_segs) if line2_string.intersects(s)]
    print(intersect_segs)  # [2]
    

    交叉点发生在第 2 项或第三段。请注意,您可能会遇到多个交点,尤其是当交点位于连接两个或多个线段的顶点时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-25
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2015-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多