如何在具有多边形的匀称蟒蛇的多边形中打孔 [英] How to make holes in a Polygon in shapely python, having Polygons

查看:76
本文介绍了如何在具有多边形的匀称蟒蛇的多边形中打孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,我有一个普通的多边形外部"和一个多边形内部"列表.我想使用此列表在多边形中打孔.

In python, I have a plain Polygon "outer" and a list of Polygons "inners". I want to make holes in my polygon using this list.

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

如何构建 p 给定的外部和内部?

How to build p given outer and inners ?

推荐答案

抱歉,我刚刚找到了一个解决方案,给定 outer 作为普通多边形和 inners 作为一个普通多边形列表(每个多边形都包含在 outer 中):

Sorry, I've just found a solution, given outer as a plain Polygon and inners as a list of plain Polygons (each of them contained in outer) :

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

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

The Polygon constructor only works with coordinates as input, not with other Polygons such as :

p = Polygon(outer, inners)

这篇关于如何在具有多边形的匀称蟒蛇的多边形中打孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆