Created
November 25, 2025 14:59
-
-
Save Lkruitwagen/88831500b6a3f96242c25230a1c2871a to your computer and use it in GitHub Desktop.
area calculation comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from area import area | |
| import geopandas as gpd | |
| from urllib.request import urlopen | |
| bytes = urlopen("https://pastebin.com/raw/XBpJ6Hnp").read() | |
| gdf = gpd.read_file(bytes) | |
| gdf['country_name'] = ['south-africa','india','japan','france','argentina','united-states'] | |
| for reprojection in [ | |
| "epsg:3395", | |
| "epsg:3857", | |
| "epsg:3035", | |
| {'proj':'cea'}, | |
| "esri:54009", | |
| ]: | |
| gdf[f'area_{reprojection}'] = gdf.to_crs(reprojection).geometry.area / 10e6 | |
| gdf['area_area_lib'] = gdf.geometry.apply(lambda geom: area(geom.__geo_interface__)) / 10e6 | |
| for ii in range(len(gdf)): | |
| gdf.at[ii, 'area_utm'] = ( | |
| gdf.iloc[ii:ii+1] | |
| .to_crs(gdf.iloc[ii:ii+1].estimate_utm_crs()) | |
| .geometry.area.values[0] / 10e6 | |
| ) | |
| print (gdf.drop(columns='geometry')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment