Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中合并多边形形状文件_Python_Polygon_Shapely - Fatal编程技术网

在Python中合并多边形形状文件

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

我的python3脚本创建了变量
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])