Late to the party, but with a hopefully useful contribution. Building on scw's answer using geopy, I wrote a small function that does the calculation for a shapely LineString object with arbitrarily many coordinates. It uses a
pairs iterator from Stackoverflow.
Main feature: the docstrings are much longer than the snippets.
"""Calculate length of a line in meters, given in geographic coordinates.
line: a shapely LineString object with WGS 84 coordinates
Length of line in meters
# Swap shapely (lonlat) to geopy (latlon) points
latlon = lambda lonlat: (lonlat, lonlat)
total_length = sum(distance(latlon(a), latlon(b)).meters
for (a, b) in pairs(line.coords))
return round(total_length, 0)
"""Iterate over a list in overlapping pairs without wrap-around.
lst: an iterable/list
Yields a pair of consecutive elements (lst[k], lst[k+1]) of lst. Last
call yields the last two elements.
lst = [4, 7, 11, 2]
pairs(lst) yields (4, 7), (7, 11), (11, 2)
i = iter(lst)
prev = i.next()
for item in i:
yield prev, item
prev = item