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
Update
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.