我试图找出两个多边形是否相互交叉。通过'交叉'我的意思是他们的外表可以互相接触,但他们的内部却不能:
只允许使用以下两个最右侧解决方案:
我尝试过使用匀称的十字架或十字架(以及其他一些),但找不到有效的内置功能(它们通常与内部和外部有关)。
答案 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
方法。