【问题标题】:Convex Hull for all linestrings (ca. 1Million) in a Geodataframe地理数据框中所有线串(约 100 万)的凸壳
【发布时间】:2021-03-11 02:07:59
【问题描述】:

我有一个带有 ca 的 Geopandas 数据框。 100 万个线串,我想用 Geopandas 的相应工具 (GeoSeries.convex_hull) 计算它们的凸包。这会导致计算时间很长(大约 4 小时)。有人知道如何更快地做到这一点吗?

地理数据框如下所示:

   s_p_ed_hik  length lanes  i                                         geometry
0    2.658196   4.263  None  0  LINESTRING (8.52441 47.39506, 8.52443 47.39502)
1    2.658196   4.263  None  0  LINESTRING (8.52441 47.39506, 8.52443 47.39502)
2    2.874100   4.343  None  0  LINESTRING (8.52443 47.39502, 8.52449 47.39502)
...

以下是关于我的 Geopandas 数据框的 Linestrings 长度的统计数据:

count    1063284.000000
mean         12.693328
std          13.335160
min           0.385000
25%           4.956000
50%           9.507000
75%          13.638000
max         287.713000

【问题讨论】:

    标签: python geopandas


    【解决方案1】:

    确保您已安装 pygeos - https://geopandas.readthedocs.io/en/latest/getting_started/install.html#using-the-optional-pygeos-dependency。这将为您提供矢量化操作和大幅加速。

    conda install -c conda-forge pygeos
    

    你也可以试试dask-geopandas做多核。

    pip install git+https://github.com/geopandas/dask-geopandas.git
    
    

    https://github.com/geopandas/dask-geopandas

    【讨论】:

    • 谢谢。 Pygeos 对执行时间没有任何影响。我比较了:gpd.options.use_pygeos = True/False,两者都需要 56.000 个线串 62 秒。使用 dask_geopands 执行此代码时出现以下错误:import dask_geopandas ddf = dask_geopandas.from_geopandas(paths_7000, npartitions=8) paths_7000_HULL=ddf.unary_union paths_7000_HULL=paths_7000_HULL.convex_hull print(paths_7000_HULL) AttributeError: 'Scalar' object has no attribute 'convex_hull'
    • 啊,你在convex_hull之前没有说你在做unary_union。然后将其自身合并为瓶颈,除了确保您拥有最新的 GEOS 3.9 之外,没有什么可做的。
    • 谢谢!我想出了一个解决方法:我将 Geodataframe 转换回 OSMnx-MultiDiGraph,然后使用此代码计算凸包:1) node_points = [Point((data['x'], data['y'])) for node, data in testgraph_proj.nodes(data=True)],2) bounding_poly = gpd.GeoSeries(node_points).unary_union.convex_hull
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 2012-06-28
    • 2020-01-24
    • 1970-01-01
    • 2015-02-07
    • 2018-05-17
    • 2012-06-13
    相关资源
    最近更新 更多