形状相交与形体关系

编程入门 行业动态 更新时间:2024-10-22 19:32:02
本文介绍了形状相交与形体关系 - 不精确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

这些交点应该相交(至少触摸)多边形的边界,右边?

从shapely import geometry,wkt )=几何矩阵([(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 ip s:打印i.touches(聚边界)#应该触摸,但它不! >>> False

解决方案>

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

没有精度模型,所有浮点计算都受到机器epsilon 。相交点从每个几何插值,很少精确(除非你有直角)。所有 DE-9IM 谓词如touches目前需要精确的编码(除非我们有一个精确模型,这可能会发生一天。更新:使用 JTS拓扑套件,DE-9IM谓词不使用精度模型,因此GEOS克隆不太可能会有任何差异)。

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

EPS = 1e-15 在ips中: print i.distance(poly ) EPS

Hi I wonder if I am thinking the wrong way or if this is a bug:

I have a linestring and a polygon, I create the intersection points of the line and the polygon's boundary

These intersection points should intersect (at least touch) the polygon's boundary, right?

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

解决方案

It's not a bug, but this is a frequent question.

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).

A more robust strategy is to test the distance between the two, which should be less than the machine epsilon if they intersect. E.g.:

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

更多推荐

形状相交与形体关系

本文发布于:2023-11-27 04:26:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636585.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:形体   形状   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!