shapely 的 unary_union 函数需要优化

问题描述 投票:0回答:1

我很想知道 shapely 的 unary_union() 是否可以在速度方面进一步优化。使用 Shapely 的 Cascaded_union 是更好的解决方案还是有任何替代解决方案可用?

我基本上想联合列表或几何系列中的所有几何图形。特别是我们正在处理多边形几何形状。

from shapely.ops import unary_union

polygon_list =[ polygon1, polygon2, polygon3......]
union_polygon =unary_union(polygon_list)

考虑到我有一个多边形列表列表,在每个单个列表或矢量化应用上应用 unary_union() 是否有优势:

def vectorized_unary_union(polygon_list):
   unary_union(polygon_list)

python numpy union shapely unary-function
1个回答
0
投票

如果您愿意使用额外的库,您可以尝试 geofileops.dissolve.

它在底层使用 geopandas 和 shapely(即 shapely.unary_union)进行溶解,但使用一些技巧(平铺输入+多重处理)来加速处理大型数据集。为了支持处理大于内存的数据集,它需要从文件(.gpkg)输入并将结果写入文件。

免责声明:我是

geofileops
的开发者。

示例脚本:

import logging
import geofileops as gfo

if __name__ == "__main__":
    # Init logging so progress info is shown
    logging.basicConfig(level=logging.INFO)

    input_path = "C:/temp/input.gpkg"
    output_path = "C:/temp/output.gpkg"
    gfo.dissolve(
        input_path=input_path,
        output_path=output_path,
        explodecollections=True,
    )

以下基准给出了可能的性能改进的指示:

© www.soinside.com 2019 - 2024. All rights reserved.