2017-02-17 259 views
0

给定一个多边形列表,我试图找出所有不同的非重叠区域的边界。相交多边形的非重叠区域的边界

polygon_lst = [] 
for xyloc in xylocs: 
    polygon_lst.append(Polygon(xyloc)) 

这与this类似的问题。不过,我得到一个错误,当我运行unary_union操作:

from shapely.geometry import LineString 
layer = polygon_lst 
rings = [LineString(list(pol.exterior.coords)) for pol in layer] 
from shapely.ops import unary_union, polygonize 

ERROR:shapely.geos:TopologyException: found non-noded intersection between LINESTRING (103.333 327.917, 103 328) and LINESTRING (104.2 327.2, 103 328) at 103.00000000000006 328

我都试过,我创建相互重叠的顶部的所有多边形的面具一种替代方法。然后,我尝试通过Canny检测器提取不同的区域,并在opencv中找到Contour函数。然而,由这种方法产生的边界是连接的(不是每个不同区域的边界)而且是非闭合的。

enter image description here enter image description here

会是什么,我可以去寻找这些非重叠区域及其边界的好办法?

回答

0

对任意多边形的布尔运算比第一次出现要困难得多,主要是因为退化问题。

如果您将多边形渲染到缓冲区,则填充边距,然后绘制轮廓,即可实现目标。

在二进制图像库 (您需要drawbinary.c绘制多边形并执行泛洪填充,binaryutils.c或chaincodes.c来获取轮廓,这取决于你想要它们(作为xys的列表或作为上下,左右命令的链)

https://github.com/MalcolmMcLean/binaryimagelibrary