Here's my model:

class ExchangeArea(models.Model):
    An Exchange Service Area, calculated from a phone exchange and surrounding census tracts. 
    coordinates = models.PointField(null=True, geography=True)
    geom = models.MultiPolygonField(null=True, geography=True) 
    objects = models.GeoManager()
    adopts = AdoptionManager()

    def __unicode__(self):        
        return '(%f, %f)' % (self.coordinates.coords[1], self.coordinates.coords[0])

And here's my ipython terminal output:

for e in ExchangeArea.objects.distance(ea.coordinates)[:10]: print e.distance, e.coordinates.wkt

0.0 m POINT (-121.4749999999999801 36.5399999999999991)                  
34.3149213171 m POINT (-87.4350000000000023 32.2049999999999983)  
34.1483824654 m POINT (-87.6800000000000068 31.6400000000000006)          
1.30461680198 m POINT (-122.4000000000000057 37.4600000000000009)         
27.2054594705 m POINT (-94.2750000000000057 35.9950000000000045)          
34.2874590776 m POINT (-87.7500000000000000 30.3550000000000004)         
29.441773469 m POINT (-92.1550000000000011 33.8650000000000020)          
5.51086451056 m POINT (-116.1352147188304826 35.1775313564249501)        
2.11899150541 m POINT (-119.6700000000000017 37.6499999999999986)        
27.6825400749 m POINT (-93.7950000000000017 36.1649999999999991)

Using this code as a reference, the first non-zero distance should be:

3151063.676 m


So using south I've worked around this issue, ideally retaining the same level of accuracy (with reduced speed) by switching back to a normal geometry field (removing geography=true from my model) and using spheroid=True on my distance queries. They are now in a more sensible order of magnitude and still treat the earth as an spheroid (which is why I was using geography=True in the first place). Still would like to know what the deal with geography fields is. Leaving this open until someone can explain.


1 Answer 1


Haven't used geodjango but I'm wondering if the geography=true is just a notice to it to tell it the data is stored in geography format. Are your geometries in postgis stored as geography or geometry?

  • It does save it in geography format. That was the idea. My understanding was that would automatically ensure all distance calculations would treat the earth as a spheroid. However I never got that to work (as I detailed in the Update). It appears it gives me the angular distances rather than a distance in meters. Sep 7, 2011 at 0:50
  • So: at the moment the solution is to store it as geometry rather than geography, and geodjango can do the spheroid calculation for me, which I assume just calls the corresponding postgis function. Sep 7, 2011 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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