5

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()

enter image description here

world.head(5)

enter image description here

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']]

enter image description here

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.

0

1 Answer 1

11

You get that warning because EPSG:4326 (WGS84) is geographic CRS and its unit is degree. The key message here is "Geometry is in a geographic CRS". You don't get a warning when using EPSG:4328 because it is not geographic, but it is geocentric and its unit is meter.

When you use area, length or distance, GeoPandas checks CRS before calculation and warns if the planar operation is done in a geographic CRS.

Why checking?
One of the packages that Geopandas depends on is Shapely, where geometric calculations are made. Shapely uses 2D Cartesian coordinates (x, y) and calculations are performed in 2D plane. So Shapely doesn't care if the coordinates are in degree or meter. They are just numbers to Shapely. Therefore, in the table, the unit of calculated_area1 is square degree (no meaning), and the other is square meter.

3
  • Thank you for this answer! Excellent. Are you sure about the square meter though? I quickly Googled Tanzania's & Canada's area (second and fourth line in the table, just two random entries), and the answer I get via Google is significantly different than what the table tells me.
    – zabop
    Commented Sep 4, 2021 at 21:00
  • 4
    Are you sure about the square meter though? Yes. But square meter here doesn't mean it's accurate or close to the actual area. The area of a country will be different in many CRS. Even each area may even be significantly different values. It is quite normal. Commented Sep 4, 2021 at 21:38
  • Thank you! This is quite surprising for me (I'm new to this).
    – zabop
    Commented Sep 5, 2021 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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