I'm doing a very simple calculation of the length of a Polyline using shapely:
from shapely.geometry import LineString
...
xy_list = [map(float, e) for e in xy_intm]
line = LineString(xy_list)
s = '%s,%s,%s' % (fr, to, line.length)
My coordinates are in WGS84. I can't seem to find any information about Shapely's length attribute. What is the unit of the length attribute? Is there an easy way to convert to to km or meters?
Best Answer
Source: http://toblerity.org/shapely/manual.html#coordinate-systems
shapely
is completely agnostic in reference to SRS. Therefore, the length attribute is expressed in the same unit of coordinates of your linestring, i.e. degrees. In fact:Instead, if you want to express length in meters, you have to transform your geometries from WGS84 to a projected SRS using pyproj (or, better, execute geodesic distance calculation, see Gene's answer). In detail, since version 1.2.18 (
shapely.__version__
),shapely
supports the geometry transform functions ( http://toblerity.org/shapely/shapely.html#module-shapely.ops) that we can use it in conjunction withpyproj
. Here's a quick example: