Calculating length of polygon in geopandas?

Same way as area but:




See GeoSeries.length:

Returns a Series containing the length of each geometry.

You can use GeoSeries.length for this. Note that geopandas uses Shapely that is crs agnostic. You will need to reproject your geodataframe to a crs in a unit that makes sense.

import geopandas as gpd

gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
gdf["perimeter"] = gdf["geometry"].length
# As you can see, the perimeter is calculated in the unit of the crs e.g. degrees length. not very meaningful.

# lets reproject and try again

ECKERT_IV_PROJ4_STRING = "+proj=eck4 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"

gdf_eckert4 = gdf.to_crs(ECKERT_IV_PROJ4_STRING)
gdf_eckert4["perimeter"] = gdf_eckert4["geometry"].length

Note that the length of a polygon (perimeter) is arbitrary depending on the resolution of your polygon. It is also known as the coastline paradox

Notebook with example