python,shapely:如何确定两个多边形是否相互交叉,同时允许它们的边重叠

时间:2016-07-20 12:32:55

标签: python shapely

我试图找出两个多边形是否相互交叉。通过'交叉'我的意思是他们的外表可以互相接触,但他们的内部却不能:

只允许使用以下两个最右侧解决方案:

enter image description here

我尝试过使用匀称的十字架或十字架(以及其他一些),但找不到有效的内置功能(它们通常与内部和外部有关)。

2 个答案:

答案 0 :(得分:2)

这是适用于OP的解决方案(取自问题):

if ((pol1.intersects(pol2) == False) and (pol1.disjoint(pol2) == True)) or ((pol1.intersects(pol2) == True) and (pol1.touches(pol2) == True)):
    allowed = True
elif (pol1.intersects(polMe) == True) and (pol1.disjoint(polMe) == False) and (pol1.touches(polMe) == False):
    allowed = False

答案 1 :(得分:1)

您是否看过touches方法?它似乎做你想要的。

如果没有,你可以自己推动自己的"。例如,一些变体:

def myTouches(poly1, poly2):
    return poly1.intersects(poly2) and not poly1.crosses(poly2) and not poly1.contains(poly2)

或者,假设您的形状只是多边形,您可以查看intersection返回的集合。如果它只包含LineStrings或单Point,那么他们只需触摸"。如果它包含任何其他内容(多个Points和/或其他多边形),则它们会重叠。

修改 现在我看到了您的图片,除了disjoint之外,您可能还需要使用touches方法。