多边形通过Shapely触及多个点 [英] Polygon touches in more than one point with Shapely

查看:289
本文介绍了多边形通过Shapely触及多个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python中有一个Shapely多边形的列表.要使用.touches()方法找出哪种多边形触摸起来很容易.但是,我需要一些仅在多边形共享的多于而不是一个点(换句话说,共享边界)时才返回True的东西.让我举例说明:

I have a list of Shapely polygons in Python. To find out which polygon touch is easy, using the .touches() method. However, I need something that returns True only when the polygons share more than one point (in other words shares a border). Let me illustrate:

In [1]: from shapely.geometry import Polygon
In [2]: polygons = [Polygon([(0,0),(0,1),(1,1),(1,0)]), Polygon([(1,0),(1,1),(2,1),(2,0)]), Polygon([(2,1),(2,2),(3,2),(3,1)])]

In [3]: polygons[0].touches(polygons[1])
Out[3]: True

In [4]: polygons[0].touches(polygons[2])
Out[4]: False

In [5]: polygons[1].touches(polygons[2])
Out[5]: True

在这种情况下,面0和1共享两个点(整个边界).多边形1和2仅共享一个点.我要寻找的是一个可以在上述示例中为我提供TrueFalseFalse的函数,或者仅仅是可以返回接触点数量的函数,然后我可以自己完成其余的逻辑.

In this case, polygon 0 and 1 shares two points (an entire border). Polygon 1 and 2 only shares one point. What I'm looking for is a function that would give me True, False, False in the above example or just something that returns the number of touching point, then I can do the rest of the logic myself.

当然,任何不涉及手动遍历所有点的解决方案都是最佳的-如果我需要这样做,那将违反使用Shapely的目的:-)

And of course, any solution that does not involve manually iterating through all points is optimal - if I need to do that, it kind of defeats the purpose of using Shapely :-)

推荐答案

我没有匀称使用,但是您是否尝试过查看两个多边形的交点是否为直线?

i haven't used shapely, but have you tried seeing if the intersection of the two polygons is a line?

这篇关于多边形通过Shapely触及多个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆