How to calculate distance between two PointField?

Viewed 4465

I use Postgis with Django to store geographic points. I have a model like the following:

from django.contrib.gis.db import models
class Event(models.Model)
    position = models.PointField()

I have two events(ev1, ev2). Here is the position value of each:

SRID=4326;POINT (-73.6335140000000052 45.5472019999999986)
SRID=4326;POINT (-73.6267909999999972 45.5459189999999978)

My goal is to get distance in meters between those two points. If i do:

ev1.position.distance(ev2.position)

I get 0.006844327432269004 How can I convert this value in meters?

Thanks!

4 Answers

Instead of the class Distance, the database function Distance is used to perform the annotation:

    from django.contrib.gis.db.models.functions import Distance
Related