Getting distance between 2 points using GeoDjango?
The answer seems to be in this Google Groups thread:
from django.contrib.gis.geos import GEOSGeometry
pnt = GEOSGeometry('SRID=4326;POINT(40.396764 -3.68042)')
pnt2 = GEOSGeometry('SRID=4326;POINT( 48.835797 2.329102 )')
pnt.distance(pnt2) * 100
I think it's better use pyproj
:
geod = pyproj.Geod(ellps='WGS84')
angle1,angle2,distance = geod.inv(long1, lat1, long2, lat2)
See more: http://blog.tremily.us/posts/pyproj/
You can use Point too.
from django.contrib.gis.geos import Point
p1 = Point(37.2676483,-6.9273579)
p2 = Point(37.2653293,-6.9249401)
distance = p1.distance(p2)
distance_in_km = distance * 100