匀称的交叉点与匀称的关系 - 不准确?

Shapely intersections vs shapely relationships - inexact?

我想知道我是不是想错了,或者这是一个错误:

我有一个线串和一个多边形, 我创建线和多边形边界的交点

这些交点应该与多边形的边界相交(至少接触),对吗?

from shapely import geometry,wkt
line = geometry.LineString([(13.51039642756912, 52.598912814414675), (13.525173800277184, 52.60620240344557)])
poly = geometry.Polygon ([(13.52072838433517, 52.61735554606274), (13.52233276805985, 52.59511541819082), (13.51312087418833, 52.59394589806786),( 13.51526963068252, 52.60338701649216),( 13.51836560008325 ,52.6009395669487), (13.52072838433517, 52.61735554606274)])

ips = line.intersection(poly.boundary)
for i in ips:
    print i.touches(poly.boundary)  # should touch but it doesnt!!!!

>>>False

这不是错误,但这是一个常见问题。

没有精度模型,所有浮点计算都受到 machine epsilon. The intersected points are interpolated from each geometry, and are seldom exact (unless you have right angles). All of the DE-9IM predicates like 'touches' currently require exact noding (unless we have a precision model, which might happen one day UPDATE: testing with JTS Topology Suite 的限制,DE-9IM 谓词不使用精度模型,因此 GEOS 克隆不太可能有任何不同) .

一个更稳健的策略是测试两者之间的距离,如果它们相交,应该小于机器epsilon。例如:

EPS = 1e-15
for i in ips:
    print(i.distance(poly) < EPS)