我想知道我是否以错误的方式思考或者这是否是一个错误:
我有一个线串和一个多边形,
我创建直线和多边形边界的交点
这些交点应该与多边形的边界相交(至少接触),对吧?
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
这不是一个错误,但这是一个常见问题。
Without a precision model, all floating point calculations are limited by the 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, the DE-9IM predicates don't use the precision model, therefore it is unlikely that the GEOS clone will work any different).
更稳健的策略是测试两者之间的距离,如果它们相交,该距离应该小于机器 epsilon。例如。:
EPS = 1e-15
for i in ips:
print(i.distance(poly) < EPS)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)