【问题标题】:How to Union Intersecting Geometries in Same Geopandas Dataframe如何联合相同 Geopandas 数据框中的相交几何
【发布时间】:2017-09-21 21:58:38
【问题描述】:

我有一个带有圆圈的数据框,其中一些与其他圆圈相交。我想将这些相交区域合并为数据框中的新行,添加相交区域的属性。我只看到如何在两个数据帧之间使用 sjoin。

【问题讨论】:

    标签: pandas union intersect geopandas


    【解决方案1】:

    设置

    import geopandas as gpd, pandas as pd
    from urbansim.maps import dframe_explorer
    from shapely.geometry import Point
    %matplotlib inline
    
    c1 = Point(1, 0).buffer(1)
    c2 = Point(.5, 0).buffer(1)
    
    gdf = gpd.GeoDataFrame(dict(A=[1, 2], B=[3, 4]), geometry=[c1, c2])
    
    gdf.plot()
    

    解决方案
    使用来自functoolsreduce

    from functools import reduce
    
    intersection = reduce(Point.intersection, gdf.geometry) 
    
    summed = gpd.GeoDataFrame(
        gdf.sum().to_frame().T,
        geometry=[intersection]
    )
    
    gdf.set_geometry(
        gdf.difference(intersection)
    ).append(summed, ignore_index=True).plot()
    

    【讨论】:

    • 谢谢。这是答案的一个有用部分,但是 gdf ​​将具有原始多边形及其交叉点。我想把它们分开。所以我想要交叉点,然后是不相交的部分。将其与上面的图相关联,我想要右侧的新月形、交叉点和左侧的新月形。请原谅我原来的问题中的任何歧义
    • 不客气......只是让你知道,你接受这个答案就是让我超过 90,000 代表。谢谢!
    • 我很荣幸,我相信你应该得到它!
    • 嘿,所以我刚刚回去处理这个问题,现在我看到无论有多少不相交的相交多边形集,它都会找到一个交点。想不出一个合理的方法来做到这一点(我可以从对开始遍历表,然后是三元组等以找到所有可能的交叉点,但这非常昂贵)。基本上我希望它像here 所示的 arcmap 的联合,但在一个表内
    猜你喜欢
    • 2023-01-18
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 2020-12-16
    • 2017-01-05
    • 1970-01-01
    • 2019-12-11
    • 2021-07-22
    相关资源
    最近更新 更多