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.

Model A has a ForeignKey relation to Model B. Model B has a PointField. Is there a way to order Model A objects by distance from a POINT?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Assuming that both Model A and B are using objects = models.GeoManager(), the FK field on Model A is named b, Model B has PointField named point, and pnt is a GEOSGeometry then the following should work:

A.objects.distance(pnt, field_name='b__point').order_by('distance')
share|improve this answer
    
thanks. i have yet to try this, but it looks promising. is this documented somewhere? i couldn't find it... –  kliao Dec 31 '10 at 22:29
    
tried it and worked...thanks –  kliao Jan 7 '11 at 5:12
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.