确定Shapely点是否在LineString/MultiLineString中 [英] Determine if Shapely point is within a LineString/MultiLineString

查看:244
本文介绍了确定Shapely点是否在LineString/MultiLineString中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Shapely的within函数对LineString和Point文件进行空间连接"(仅供参考,point文件是使用LineString上的interpolate函数生成的).问题是-什么也没有退回.

I am trying to use Shapely's within function to do a 'spatial join' of a LineString and a Point file (FYI, the point file was generated using the interpolate function on the LineString). Problem is - nothing is being returned.

# this condition is never satisfied
if point.within(line):
    # here I write stuff to a file

其中:

point = POINT (-9763788.9782693591000000 5488878.3678984242000000)
line = LINESTRING (-9765787.998118492 5488940.974948905, -9748582.801636808 5488402.127570709)

我想念什么?

推荐答案

在直线上找到点时,存在浮点精度错误.改用适当的阈值距离.

There are floating point precision errors when finding a point on a line. Use the distance with an appropriate threshold instead.

from shapely.geometry import Point, LineString

line = LineString([(-9765787.9981184918, 5488940.9749489054), (-9748582.8016368076, 5488402.1275707092)])
point = Point(-9763788.9782693591, 5488878.3678984242)

line.within(point)  # False
line.distance(point)  # 7.765244949417793e-11
line.distance(point) < 1e-8  # True

这篇关于确定Shapely点是否在LineString/MultiLineString中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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