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.
"""Length of a line in meters, given in geographic coordinates
line: a shapely LineString object with WGS-84 coordinates
Length of line in meters
from geopy.distance import distance
return sum(distance(a, b).meters for (a, b) in pairs(line.coords))
"""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