确定Shapely点是否在LineString / MultiLineString中
发布于 2021-01-29 17:29:25
我正在尝试使用Shapely的within
函数对LineString和Point文件进行“空间连接”(仅供参考,point文件是使用上的interpolate
函数生成的LineString
)。问题是-
什么也没有退还。
# 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)
我想念什么?
关注者
0
被浏览
46
1 个回答
-
在直线上找到点时,会出现浮点精度错误。而是使用具有适当阈值的距离。
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