【发布时间】:2017-01-20 10:23:57
【问题描述】:
我有两个在不同部分相交的形状优美的 MultiPolygon 实例(由 lon、lat 点组成)。我正在尝试遍历,确定两个多边形之间是否存在交叉点,然后创建一个排除该交叉点的新多边形。从附图来看,我基本上不希望红色圆圈与黄色轮廓重叠,我希望边缘正好是黄色轮廓开始的地方。
我已经尝试按照here 的说明进行操作,但它根本不会改变我的输出,而且我不想将它们合并到一个级联联合中。我没有收到任何错误消息,但是当我将这些 MultiPolygons 添加到 KML 文件(只是 python 中的原始文本操作,没有花哨的程序)时,它们仍然显示为没有任何修改的圆圈。
# multipol1 and multipol2 are my shapely MultiPolygons
from shapely.ops import cascaded_union
from itertools import combinations
from shapely.geometry import Polygon,MultiPolygon
outmulti = []
for pol in multipoly1:
for pol2 in multipoly2:
if pol.intersects(pol2)==True:
# If they intersect, create a new polygon that is
# essentially pol minus the intersection
intersection = pol.intersection(pol2)
nonoverlap = pol.difference(intersection)
outmulti.append(nonoverlap)
else:
# Otherwise, just keep the initial polygon as it is.
outmulti.append(pol)
finalpol = MultiPolygon(outmulti)
【问题讨论】:
-
我投票结束这个问题为“不可重现”,因为问题中的代码是正确和 OP commented 错误在别处。