获取Point的任一侧的LineString上的顶点 [英] Get the vertices on a LineString either side of a Point

查看:667
本文介绍了获取Point的任一侧的LineString上的顶点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个漂亮的 LineString ,并且定义了一个很形状的 Point ,它位于 LineString



如何找到位于任一侧的 LineString 的顶点的观点? (将行分成两部分)

解决方案

LineString 重点在哪里。然后相应地将 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上的顶点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆