【发布时间】:2018-05-05 21:13:08
【问题描述】:
我正在尝试在 Shapely 中将一个点插入到 LineString 上,然后相应地拆分线串。但是由于精度误差,Shapely 认为插值点不在linestring 上,因此split 操作不起作用。
这是一个例子:
from shapely.ops import split
from shapely.geometry import LineString, Point
### Initialize point and line
line = LineString([(0.123,0.456),(5.678,7.890),(12.135,6.789)])
point = Point(4.785,8.382)
### Interpolate point onto line
new_point = line.interpolate(line.project(point))
print new_point
>> POINT (5.593949278213755 7.777518800043393)
### BUT: line does not intersect the interpolated point
line.intersects(new_point)
>> False
### EVEN THOUGH: distance between them is essentially (not exactly) zero
line.distance(new_point)
>> 0.0
### THEREFORE: line cannot be split using the new point
len(split(line, new_point))
>> 1
我认为问题如下:
1.我将原始点/线坐标四舍五入,以免它们超出机器的精度限制。
2. 但是,INTERPOLATED 点的精度非常高。我不知道如何控制它。
3.理论上,我可以将这个新点的坐标四舍五入,但这似乎也不能确保新点在线上。
【问题讨论】: