# Calculate distance in kilometers with shapely

I am for the first time needing to use geolocation and geodata resources in a WEB application. As the application is being developed in python / flask I decided to make use of the shapely library. The shapely library makes it possible to perform some calculations, such as calculating the size of a LineString.

``````>>> from shapely.geometry import LineString
>>> line = LineString([(0, 0), (1, 1)])
>>> line.area
0.0
>>> line.length
1.4142135623730951
``````

If I get a LineString through the GoogleMap API (in the Google API it's called Polyline):

``````var flightPlanCoordinates = [
{lat: 37.772, lng: -122.214},
{lat: 21.291, lng: -157.821},
{lat: -18.142, lng: 178.431},
{lat: -27.467, lng: 153.027}
];
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
``````

and with the data from that LineString create a hapely.geometry.LineString object and calculate its size with:

``````>>> from shapely.geometry import LineString
>>> line = LineString([(37.772, -122.214), (21.291, -157.821), (-18.142, 178.431), (-27.467, 153.027)])
>>> line.length
?
``````

Will I get the distance in kilometers from LineString? Will the result be the same if calculated using the Google Maps API itself?

I did a test and got a strange result:

``````>>> from shapely.geometry import LineString
>>> line = LineString([(-29.9673156, -51.1497259), (-29.969095, -51.114017)])
>>> line.length
0.03575320689910512
``````
• Welcome to gis.SE. Did you check this out: gis.stackexchange.com/questions/80881/… ? It may help to answer your question because actually, distances can be computer on the sphere or on a cartographic plane. So if you want a euclidean distance, you'll have to reproject your data from WGS84 to your local frame. – s.k Apr 17 '20 at 5:10