11

For example, to calculate the area is like this:

df['area'] = df['geometry'].area

How do we find the length of the perimeter?

0

2 Answers 2

15

Same way as area but:

df.geometry.length

or

df['geometry'].length

See GeoSeries.length:

Returns a Series containing the length of each geometry.

6

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.crs
gdf["perimeter"] = gdf["geometry"].length
gdf.head()
# 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
gdf_eckert4.head()

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

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.