GeoPandas Centroid Warning – Resolving UserWarning in Polygon Centroid Calculation

geopandaspyprojpython

I have this geopandas dataframe:

df1 = gpd.GeoDataFrame(df,crs=rasterio.crs.CRS.from_string("epsg:4326"), geometry=df['geojson'].apply(json_load))
df1 = df1.set_crs(epsg=4326)
print (df1.shape)
df1.head()

 account_id area    geojson                                             geometry
0   1365    1.7     {"type": "MultiPolygon","coordinates":[[[[35.4...   MULTIPOLYGON (((35.48632 32.78037, 35.48600 32...
1   3019    0.6     {"type": "MultiPolygon","coordinates":[[[[4.92...   MULTIPOLYGON (((4.92786 43.68305, 4.92951 43.6...



df1.crs
>> <Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

I would like to get the coordinates of the centroid of each polygon.
I used to be able to get it by df1['geometry'].centroid without any warning, but now when I try that line I get:

UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

  """Entry point for launching an IPython kernel.

I don't understand why because my CRS looks fine, also the coordinates of the centroid look fine, should I just ignore this warning?

My packages versions:

print(pyproj.__version__)
print(rasterio.__version__)
print(gpd.__version__)

>> 2.6.1.post1
>> 1.1.5
>> 0.8.1

Best Answer

I am no export on geopandas, but to me the warning only tells you that you should use a crs with coordinates in meters,

Probably because the function calculating the centroid doesn't support ellipsoidal calculations or something.

So if your polygons are relatively small, wich they seem to be, the 'curvature' of the ellipsoid doesn't have much of an impact and treats your coordinates as if they are in meters and does cartesian calculations, hence why your centroid is 'correct'.

EDIT:

This answer to a similar question seems to point to my answer being right