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}
];
var flightPath = new google.maps.Polyline({
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
