如何在同一Geopandas数据帧中合并相交几何图形

如何在同一Geopandas数据帧中合并相交几何图形,pandas,union,intersect,geopandas,Pandas,Union,Intersect,Geopandas,我有一个带有圆圈的数据框,其中一些圆圈与其他圆圈相交。我希望将这些相交区域合并为dataframe中的新行,添加来自相交区域的属性。我只看到如何在两个数据帧之间使用sjoin。设置 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(

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

设置

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()

解决方案
使用
functools

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将有原始多边形及其交点。我想把他们分开。所以我想要相交,然后是不相交的部分。把它和上面的图联系起来,我想要右向的新月,交叉点,和左向的新月。请原谅我原始问题中的任何含糊不清不客气。。。只是想让你知道,你接受这个答案是什么让我超过90000代表。谢谢!我很荣幸,我相信这是你应得的!嘿,我刚刚开始研究这个,现在我看到它找到了一个交集,不管有多少不相交的多边形。我想不出一个合理的方法来实现这一点(我可以遍历表,从对开始,然后是三元组,等等,以找到所有可能的交集,但这非常昂贵)。基本上,我希望它像所示的arcmap的并集一样,但是在一个表中