1

I have a shapefile containing the map of Milano that contain square polygons with different size, I mean small, medium and big squares and each square has an identifier and I want to fill these polygons with the data which is reported in another file. The Shapefile polygons are as follows:

                  id                                           geometry
0           3939_1_1  POLYGON ((504174.2673271392 5003118.268122713,...
1         3939_1_2_1  POLYGON ((508268.9938896392 5003118.268122713,...
2     3939_1_2_2_3_3  POLYGON ((511851.8796318267 5005064.825739901,...
3     3939_1_2_2_3_0  POLYGON ((511340.0388115142 5005064.825739901,...
4       3939_1_2_2_0  POLYGON ((510316.3571708892 5004415.973200838,...
5         3939_1_2_3  POLYGON ((510316.3571708892 5005713.678278963,...

This is also the data file that I have

3939_0_0    5.906552126050579   848.3214545643237
3939_0_1    5.82302081392767    1465.1476909159426
3939_0_2    11.465018361277856  742.8107082619533
3939_0_3_1  3.820090639450465   325.98139282061385
3939_0_3_3  5.1252845330079415  558.5800634528392

and I have plotted these data on Milano shapefile and I have created heatmaps but since the squares do not have the same size the data must be normalized over each polygon area. Is there any suggestion how can I normalize my data over each polygon area?

here is some part of the code that I have created these heatmaps.

import pandas as pd
import geopandas as gpd
from geopandas import GeoSeries, GeoDataFrame
mapDir = "/home/foroogh/PhD/milano-grid"
mapName = "intersection_Milano_W_GRIDIT_NEW.shp"
map_path = os.path.join(mapDir, mapName)
milano = gpd.read_file(map_path)
.
.
.
df1 = pd.read_csv(file_,sep='\t',index_col=None, header=None, names=    ['squareid','nofcalls','callduration'])
df1 = milano.set_index("id").join(df1.set_index('squareid'))
fig = plt.figure()
df1.plot(column = "callduration", cmap = "jet", figsize = (20,20))
filename3 = str(file_.split("/")[-1])+'.png'
plt.savefig(os.path.join(root_path2, os.path.basename(file_)))
plt.savefig(os.path.join(root_path2,filename3))
plt.close(' ')
0

Use the area method to retrieve polygons areas and normalize your data:

gdf['data_norm'] = gdf['data']/gdf.area

Unit is the same as the one defining your polygons geometry (and your projection). Using equal area projection make sense. You can also add unit conversion to the formula.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.