Eri*_* H. 6 python polygon shapely
在python中,我有一个普通的“外部”多边形和一个“内部”多边形列表。我想使用此列表在多边形中打孔。
from shapely.geometry import Polygon
# polygon with 1 hole in the middle
p = Polygon(((0,0),(10,0),(10,10),(0,10)), (((4,4),(4,6),(6,6),(6,4)), ))
print p.wkt
# POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (4 4, 4 6, 6 6, 6 4, 4 4))
# other constructor, does not work (no hole) :
outer = Polygon(((0,0),(10,0),(10,10),(0,10),(0,0)))
inners = (Polygon(((4,4),(4,6),(6,6),(6,4),(4,4))), )
p = Polygon(outer, inners)
print p.wkt
# POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))
Run Code Online (Sandbox Code Playgroud)
如何根据给定的外部和内部构造p?
抱歉,我刚刚找到了一个解决方案,outer以纯多边形和纯多边形inners列表(每个都包含在中outer)给出:
p = Polygon(outer.exterior.coords, [inner.exterior.coords for inner in inners])
Run Code Online (Sandbox Code Playgroud)
Polygon构造函数只能将坐标作为输入,而不能与其他Polygons一起使用,例如:
p = Polygon(outer, inners)
Run Code Online (Sandbox Code Playgroud)