Gabriele Fugazzi
Gabriele Fugazzi

Reputation: 181

Getting a UserWarning when calculating centroid of a GeoSeries

Running the command dataframe['geometry'].centroid a warning is shown:

The column 'geometry' is made up of Multipolygon objects. How can I solve this issue to accurately calculate the centroid of my multipolygon's shapes?

Upvotes: 6

Views: 6370

Answers (1)

Gabriele Fugazzi
Gabriele Fugazzi

Reputation: 181

This error could be solved by a projection to flat the surfaces down. The dataset I was using was a GeoDataFrame with a crs value of epsg=4326, as shown in the following screenshot

https://i.sstatic.net/oFtUd.png

To accurately calculate the centroid we first need a plane area rather than a geodic one. In my case I'd use the ETRS Lambert Azimuthal Equal Area projection (epsg=3035) to flat up the surface of North Europe (where the city of Milan is located).

https://i.sstatic.net/pKzTG.png

As a proof, the plot differs a bit from the original one

https://i.sstatic.net/ixLq2.png

Performing again a crs() transformation back to epsg=4326 the projected polygon and centroid can be trasformed again in lat/lon coordinates.

https://i.sstatic.net/pvsWr.png

Upvotes: 12

Related Questions