I'm trying to understand how to calculate the correct area for a shape. I'm well aware from many of the searches that I need to select the right CRS to be able to calculate the right area, but my problem is that I'm not sure what the correct CRS should be for the area. For this is generally trust QGIS but I cannot reproduce the correct area in GeoPandas.

Let's say we have the following shape: 'POLYGON ((-2.164637332474595 5.256875328024387, -2.153937604215215 5.260153696182363, -2.124307587496931 5.135563662748329, -2.145707044015691 5.11342997445197, -2.155583716255119 5.083917200394721, -2.184390676953451 5.099493555735554, -2.164637332474595 5.256875328024387))' (in EPSG:4326)

If I calculate the area in QGIS (using the $area function) for the CRS EPSG:3857 I get the following: enter image description here

I understand from the answers here that I can actually get the same area using a different function.

And then calculating the same area using geopandas using the following code:

import pandas as pd
import geopandas as gpd
from shapely import wkt
from fiona.crs import from_epsg

df = pd.DataFrame({'Point': ['Test'],
                   'Coordinates': ['POLYGON ((-2.164637332474595 5.256875328024387, -2.153937604215215 5.260153696182363, -2.124307587496931 5.135563662748329, -2.145707044015691 5.11342997445197, -2.155583716255119 5.083917200394721, -2.184390676953451 5.099493555735554, -2.164637332474595 5.256875328024387))']})

df['Coordinates'] = df['Coordinates'].apply(wkt.loads)

gdf = gpd.GeoDataFrame(df, geometry='Coordinates')
gdf.crs = from_epsg(4326)
gdf = gdf.to_crs(from_epsg(3857))
gdf['area'] = gdf['Coordinates'].area

The area that I now get is somehow 7.301224e+07, different from what we have in QGIS.

My understanding is that (due to the answer given here) the area in QGIS is actually correct due to the ellipsoidal settings in the project (I might not correctly understand the term though). My question is, how do I get the same result in GeoPandas?

In general, my more broad question would be, how can I make sure I always calculate the right area of a shape in hectares. Is there a straightforward way to do this in GeoPandas?

  • 2
    FYI 3857 is not a projection to calculate areas in in any case, it is highly distorted (look at a typical webmap and zoom out to see Greenland as big as Africa, that's the area measurements you get from it!). – bugmenot123 Sep 25 '20 at 10:10
  • 2
    What kind of accuracy are you aiming for and how big are your areas? – bugmenot123 Sep 25 '20 at 10:10
  • I'm looking to get an accuracy of within 10m2. My biggest areas will be around 100 ha, but most of them will be below 10ha. All of my shapes will be located in tropical zones around the equator. @bugmenot123 – Tim.Lucas Sep 25 '20 at 10:14

Your Answer

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

Browse other questions tagged or ask your own question.