I recently tried to calculate country sizes with geopandas and the included world file; and I am not capable to calculate the correct size for the chosen countries. Maybe someone can give me a hint where I made a mistake?
Tried various shapefiles (and the included world file shipped with geopandas); all of the afaik in epsg:4326
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
cnames = ['Austria','Sweden','Kenya']
epsgs = ['3857','3395']
for c in cnames:
carea = world[world['name'] == c]
for e in epsgs:
carea = carea.to_crs(epsg=e)
area = int(pd.to_numeric(carea['geometry'].area)/10**6)
print(area)
Expected results are:
Actual results I get:
So Kenya is quite close (also to the equator)? Is the reprojection not right?
Basically, you just multiply the latitude by the length of one degree of latitude, and the longitude by the length of a degree of latitude and the cosine of the latitude.
GeoPandas is an open source project to make working with geospatial data in python easier. GeoPandas extends the datatypes used by pandas to allow spatial operations on geometric types. Geometric operations are performed by shapely. Geopandas further depends on fiona for file access and matplotlib for plotting.
To get correct area, you must use 'equal-area' projection. The one that works well with your code is epsg 6933
. It is cylindrical equal-area projection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With