8

From GeoDjango Point Field, I get the following points:

object1.point = "POINT(-113.4741271000000040 53.4235217000000020)"
object2.point = "POINT(-113.5013688000000229 53.5343457999999970)"

Then I calculate the distance using geopy:

from geopy import distance
from geopy import Point

p1 = Point("-113.4741271000000040 53.4235217000000020")
p2 = Point("-113.5013688000000229 53.5343457999999970")
result = distance.distance(p1,p2).kilometers
print result
# 5.791490830933827

But using this tool: http://www.movable-type.co.uk/scripts/latlong.html I get a distance of 12.45km

Why is there such a big discrepancy?

MERose
  • 4,048
  • 7
  • 53
  • 79
pmah
  • 157
  • 1
  • 2
  • 8

1 Answers1

14

You've got lat/long the wrong way round. Try:

p1 = Point("53.4235217000000020 -113.4741271000000040")
p2 = Point("53.5343457999999970 -113.5013688000000229")

Gives me result = 12.466096663282977

Maria Zverina
  • 10,863
  • 3
  • 44
  • 61
  • I made an assumption that you're measuring in Edmonton rather than somewhere in Antarctica :) – Maria Zverina Jun 13 '12 at 05:05
  • 2
    You are right, Edmonton is right. Lat = 53, lon = -113. But, when representing a point in Geodjango PointField, it's done as "POINT({lon} {lat})". With geopy, is it Point("{lat} {lon}")? (See correction). If this is the case, how would I find the distance between two GeoDjango point fields? – pmah Jun 13 '12 at 05:25
  • Not sure - not familiar with GeoDjango classes. You might want to post a django question. :) Have you tried the obvious conversion via strings? Also I'm suspicious of any framework that use lon/lat instead of the very conventional lat/log. :) – Maria Zverina Jun 13 '12 at 18:50
  • FWIW, using the `Geodesic.WGS84.Inverse()` method of ([the Python module](http://geographiclib.sourceforge.net/html/other.html#python) from C. F. F. Karney's [GeographicLib](http://geographiclib.sourceforge.net/) I get 12466.096663762537 metres. – PM 2Ring Aug 19 '15 at 10:38
  • 1
    For documentation sake: geopy has a [`lonlat()`](https://geopy.readthedocs.io/en/stable/#geopy.distance.lonlat) method to convert a `(lon, lat)` tuple to a `(lat, lon)` tuple. If you have a Django `Point` instance, you can use the `.tuple` attribute so you can do: `lonlat(*my_pnt.tuple)`. Btw: the order of lat/lon is unfortunately not standardized and differs widely in systems, so it's not a case of geopy/Django being wrong or right. – gitaarik Dec 17 '19 at 13:37