Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
OpenGeo have a useful writeup on the difference between geography and geometry calculations in PostGIS 1.5: workshops.opengeo.org/postgis-intro/geography.html –  djq Oct 6 '11 at 14:48
add comment

1 Answer

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?

share|improve this answer
    
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. –  Griffith Rees Sep 7 '11 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. –  Griffith Rees Sep 7 '11 at 0:51
add comment

Your Answer

 
discard

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.