根据与其他多边形的重叠区域为多边形分配新值

时间:2020-01-17 08:11:14

标签: python geopandas

我有两个正方形df1df2。在“内容”列中,两个多边形的值分别为10(df1)和20(df2)。假设我有一个中点1.5,1.5且半径为1的圆。如何基于与其他多边形的重叠向该圆分配新的值“ content”? 例如。圆的三分之一与df1重叠,圆的三分之一与df2重叠。在这种情况下,圈子将获得10 * 1/3 + 20 * 1/3作为“内容”的值。

from shapely.geometry import Polygon
import geopandas

polys1 = geopandas.GeoSeries([Polygon([(0,0), (2,0), (2,2), (0,2)])])

polys2 = geopandas.GeoSeries([Polygon([(1,1), (3,1), (3,3), (1,3)])])

df1 = geopandas.GeoDataFrame({'geometry': polys1, 'df1':[1], 'content':[10]})

df2 = geopandas.GeoDataFrame({'geometry': polys2, 'df2':[1], 'content':[20]})

ax = df1.plot(color='red');
df2.plot(ax=ax, color='green', alpha=0.5);

enter image description here

0 个答案:

没有答案