I have a line shapefile named "river" which has 385 features. I would like to calculate the length of each feature using Python. I am currently using GDAL, Shapely, and Fiona libraries.

  • Welcome to gis stackexchange. It would be nice that you post what you have already try, and also explain what are the excepted result. Add the length to an existent field or to a new field, print in the console, ... – Francisco Puga Jan 27 at 19:01

Appreciate it's not one of the modules you've listed but using geopandas may be of some use here.

#using geopandas
import geopandas as gp

#read shapefile in
gf = gp.read_file('path/to/shapefile')

#set crs to a projected coordinate system
#choose appropriately for your location
gf = gf.to_crs(epsg=00000)

#create column in dataframe with length of each feature
gf['length'] = gf.geometry.length

Not the answer you're looking for? Browse other questions tagged or ask your own question.