Recently I've found out that GeoPandas has a world map available:
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
Looks beautiful:
world.plot()
world.head(5)
If I try calculating the area of each country by naively doing:
world.area
I get this warning:
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
Ok, let's use the to_crs()
function. To find out what EPSG code I need to use, I do:
world.crs.to_epsg()
4326
is returned.
If I do, then:
world=world.assign(calculated_area1 = world.to_crs(4326).area)
I still get the warning:
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:1: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
However, if I deliberately use the wrong EPSG code 4328
, I don't get a warning.
world=world.assign(calculated_area2 = world.to_crs(4328).area)
The result is:
world[['name','calculated_area1','calculated_area2']]
Ie none of the columns contain the area of countries in square meters or kilometers.
Why do I get a warning when using the right EPSG code while not getting warnings when using a wrong one?
If I understand this, I hope to be able to calculate the area of countries.