I have two square polygons df1
and df2
. Both polygons are assigned a value of 10 (df1) and 20 (df2) in the "content" column. Let's assume, I have a circle with the midpoint 1.5,1.5
and a radius of 1.
How can I assign to this circle a new value "content", based on the overlap with the other polygons?
For example, one third of the circle overlaps with df1 and one third of the circle overlaps with df2. In this case, the circle would then obtain 10 * 1/3 + 20 * 1/3
as a value for "content".
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);