Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to show you something. I am using django+postgis and I am experiencing wrong distance values between two points.

This is my model:

class Location(models.Model):
    name = models.CharField(max_length=255)
    latitude = models.FloatField(blank=True, null=True, verbose_name='Latitude')
    longitude = models.FloatField(blank=True, null=True, verbose_name='Longitude')
    location = models.PointField(blank = True, null=True)

    objects = models.GeoManager()

    def save(self, *args, **kwargs):
        self.location = Point(self.latitude, self.longitude)
        super(Location, self).save(*args, **kwargs)

This is the data:

bogota = Location(name='bogota', latitude='4.61779093242', longitude='-74.0893133545')
barranquilla = Location(name='barranquilla', latitude='10.9731710819', longitude='-74.8020513916')

This is the query:

ls = Location.objects.distance(bog.location).order_by('distance')
for l in ls:;

This is the output:

Out[29]: u'BOGOTA'
Out[29]: 0.0
Out[29]: 205.27667079004999

But Barranquilla city is to ~700km from Bogota city, see here.

So, what is wrong? the SRID are the default values.

share|improve this question
I removed the direct link to the site because it invisibly redirects to some kind of marketing page that isn't working :-(. –  whuber Sep 14 '11 at 2:29

1 Answer 1

up vote 6 down vote accepted

The order of latitude and longitude has been reversed in the call

self.location = Point(self.latitude, self.longitude)

That is because Points expect the x-coordinate (longitude) to be the first argument.

Indeed, the distance between points at latitude -74 degrees and longitudes at 4.6 and 11.0 degrees is approximately 206 kilometers.

share|improve this answer
whuber you are the geoman :) thanks. –  panchicore Sep 19 '11 at 22:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.