GeoDjango annotate distance

316 views
Skip to first unread message

mikegolf

unread,
Dec 12, 2012, 4:15:44 PM12/12/12
to django...@googlegroups.com
Hi,
I've recently started learning GeoDjango and I'm a bit confused. 
There's a GeoQuerySet method "distance" which annotates each object with the distance to the given point, like that:

pnt = 'POINT(coords... coords ...)'
MyModel.objects.all().distance(pnt)

but what field of the object does it take to calculate the distance?
I'd like to do "classic" annotation, like that:

MyModel.objects.all().annotate(distance_to_pnt = Distance('location_attribute_of_MyModel', pnt))

any tips?
thanks
mg

Chris Cogdon

unread,
Dec 14, 2012, 2:36:56 PM12/14/12
to django...@googlegroups.com
Just did a cursory read of the geodjango documentation for the first time...the querysets being returned from "all()" (or really, just objects) need to be GeoQuerySets which have a default "position" as part of their specification (I think), also such modules need to inherit from the geo version of model.Model AND use a special GeoManager. So, once you use that special manager, there is a point, boundary or area tat all the geo functions refer to.
Reply all
Reply to author
Forward
0 new messages