【问题标题】:Identify the buffered bounds of a GeoDataFrame识别 GeoDataFrame 的缓冲边界
【发布时间】:2017-05-10 16:27:23
【问题描述】:

给定一个GeopandasGeoDataFrame,我想提取由n 单位缓冲的GeoDataFrame 的总边界。

使用gdf.geometry.total_bounds,我可以访问整个 DataFrame 中组合几何的非缓冲边界。我想到的一种方法是采用这些边界,将它们转换为 Shapely 多边形,然后对其进行缓冲。

【问题讨论】:

    标签: python shapely geopandas


    【解决方案1】:

    我认为您提到的方法(从总边界创建一个多边形,然后对其进行缓冲)确实是最好的方法。要进行转换,您可以使用shapely.geometry.box 便利功能:

    In [21]: s = geopandas.GeoSeries([Point(0,0), Point(0,5), Point(3,3)])
    
    In [22]: s
    Out[22]: 
    0    POINT (0 0)
    1    POINT (0 5)
    2    POINT (3 3)
    dtype: object
    
    In [23]: s.total_bounds
    Out[23]: (0.0, 0.0, 3.0, 5.0)
    
    In [24]: import shapely.geometry
    
    In [25]: shapely.geometry.box(*s.total_bounds)
    Out[25]: <shapely.geometry.polygon.Polygon at 0x7fac100d25f8>
    
    In [26]: print(shapely.geometry.box(*s.total_bounds))
    POLYGON ((3 0, 3 5, 0 5, 0 0, 3 0))
    
    In [27]: shapely.geometry.box(*s.total_bounds).buffer(3)
    Out[27]: <shapely.geometry.polygon.Polygon at 0x7fac10041a90>
    
    In [28]: shapely.geometry.box(*s.total_bounds).buffer(3).bounds
    Out[28]: (-3.0, -3.0, 6.0, 8.0)
    

    或者(但不确定这是否总是会给出完全相同的结果),您也可以先使用 cascaded_union 将对象组合成一个对象,然后对其进行缓冲,然后获取边界:

    In [33]: s.cascaded_union
    Out[33]: <shapely.geometry.multipoint.MultiPoint at 0x7fac100cd278>
    
    In [34]: s.cascaded_union.buffer(3)
    Out[34]: <shapely.geometry.polygon.Polygon at 0x7fac100cd048>
    
    In [35]: s.cascaded_union.buffer(3).bounds
    Out[35]: (-3.0, -3.0, 6.0, 8.0)
    

    【讨论】:

    • 太棒了 - 谢谢!我没想过要使用shapely.geometry.box 方法。
    猜你喜欢
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多