【发布时间】:2020-07-16 23:56:15
【问题描述】:
我的 python3 脚本创建了变量 geometries_list,其值为 shapefile 列表,每个多边形代表一个地理区域
[<shapefile.Shape at 0x7f060abfae48>,
<shapefile.Shape at 0x7f05dcaf1cc0>,
<shapefile.Shape at 0x7f060a86b278>,
<shapefile.Shape at 0x7f05da470668>]
我想“合并”多边形。我尝试了以下代码
from functools import reduce
from shapely.geometry import Polygon
union = reduce(lambda x,y: x.union(y), geometries_list)
但它给出了结果: AttributeError: 'Shape' 对象没有属性 'union'
我看到另一种方法涉及创建 shapefilewriter 对象并连续覆盖列表中的每个多边形https://gis.stackexchange.com/questions/103033/using-pyshp-to-merge-two-shapefiles 这种方法可能有效,但每次覆盖都会保存到磁盘
【问题讨论】:
-
以下解决了问题 geometries_list = [geometry.Polygon(x.points) for x in geometries_list]