1

I am using the following code:

x = POINT(-1.154321, 55.124412)
y = POINT(-1.2354352, 56.2345235)

distance = x.distance(y)

print(distance)

I am unsure what distance measurement is being used, but my distance is returning very small numbers e.g. 0.0.....

Is it possible to return KMs or Miles distance using shapely?

  • 1
    Shapely do a cartesian distance in the unit of the data. If degree, distance is in degree. See https://gis.stackexchange.com/questions/80881/what-is-unit-of-shapely-length-attribute to solve your issue: knowing why degree, and calculate in meters/kilometers You may also look at https://gis.stackexchange.com/questions/184340/shapely-distance-different-from-geopy-haversine – ThomasG77 Jul 10 '21 at 10:57

1 Answers1

3

To get the distance between two points you could use the geometry_length function from pyproj. It returns the geodesic length in meters of a given shapely geometry.

from pyproj import Geod
from shapely.geometry import Point, LineString

line_string = LineString([Point(-1.154321, 55.124412), Point(-1.2354352, 56.2345235)]) geod = Geod(ellps="WGS84")

print(geod.geometry_length(line_string)) '123700.61484174021'

That would mean the distance between your two points is about 123.7 km.

CodeBard
  • 3,511
  • 1
  • 7
  • 20