繁体   English   中英

如何在具有多边形的形状蟒蛇的多边形中打洞

[英]How to make holes in a Polygon in shapely python, having Polygons

在python中,我有一个普通的Polygon“outer”和一个多边形“inners”列表。 我想用这个列表在我的多边形上打洞。

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))

如何建立外部和内部?

对不起,我刚刚找到了一个解决方案, outer为普通Polygon, inners为普通多边形列表(每个包含在outer ):

p = Polygon(outer.exterior.coords, [inner.exterior.coords for inner in inners])

Polygon构造函数仅适用于坐标作为输入,而不适用于其他多边形,例如:

p = Polygon(outer, inners)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM