# Assigning new values to polygon based on overlapping area with other polygons

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':, 'content':})

df2 = geopandas.GeoDataFrame({'geometry': polys2, 'df2':, 'content':})

ax = df1.plot(color='red');
df2.plot(ax=ax, color='green', alpha=0.5);
``````  ``````from shapely.geometry import Polygon, Point
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':, 'content':})
df2 = geopandas.GeoDataFrame({'geometry': polys2, 'df2':, 'content':})

#Geometries
geom1 = df1.iloc.geometry
geom2 = df2.iloc.geometry
circle = Point(1.5, 1.5).buffer(1)

#Areas
area_common = geom1.intersection(geom2).area
area1 = circle.intersection(geom1).area
area2 = circle.intersection(geom2).area

#Ratio excluding brown area
ratio1 = (area1 - area_common) / circle.area #ratio of blue area
ratio2 = (area2 - area_common) / circle.area #ratio of yellow area

#Ratio including brown area
#ratio1 = area1 / circle.area
#ratio2 = area2 / circle.area

content = df1.iloc.content * ratio1 + df2.iloc.content * ratio2
df3 = geopandas.GeoDataFrame({'geometry': circle, 'df3':, 'content':content})

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