在Python中合并多边形形状文件
我的python3脚本创建了变量在Python中合并多边形形状文件,python,polygon,shapely,Python,Polygon,Shapely,我的python3脚本创建了变量geometrics\u list,其值是一个shapefile列表,每个shapefile都是一个表示地理区域的多边形 [<shapefile.Shape at 0x7f060abfae48>, <shapefile.Shape at 0x7f05dcaf1cc0>, <shapefile.Shape at 0x7f060a86b278>, <shapefile.Shape at 0x7f05da470668>
geometrics\u list
,其值是一个shapefile列表,每个shapefile都是一个表示地理区域的多边形
[<shapefile.Shape at 0x7f060abfae48>,
<shapefile.Shape at 0x7f05dcaf1cc0>,
<shapefile.Shape at 0x7f060a86b278>,
<shapefile.Shape at 0x7f05da470668>]
但结果是:
AttributeError:'Shape'对象没有属性“union”
我看到了另一种方法,包括创建shapefilewriter对象并依次覆盖列表中的每个多边形。这种方法可能有效,但每次覆盖都会保存到磁盘上。也许值得一提的是,这是一种更有效的合并形状的方法 您可以将
shapefile.Shape
对象通过其GeoJSON表示转换为shapely.Polygon
对象,并按如下方式合并它们
from shapely.geometry import shape
from shapely.geometry.ops import unary_union
union = unary_union([shape(s.__geo_interface__) for s in geometries_list])
以下解决了几何图形列表=[几何图形列表中x的几何图形.Polygon(x.points)]
from shapely.geometry import shape
from shapely.geometry.ops import unary_union
union = unary_union([shape(s.__geo_interface__) for s in geometries_list])