TSW
------------------
Trevor Wiens
Sent from my mobile
> --
> You received this message because you are subscribed to the Google Groups "geodjango" group.
> To post to this group, send email to geod...@googlegroups.com.
> To unsubscribe from this group, send email to geodjango+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/geodjango?hl=en.
>
At first I thought this might be case, but geography fields are opt-in
(GeoDjango won't use them unless explicitly told so via `geography=True`
keyword). Also, ST_Distance exists for geography columns.
>> places = Model.objects.filter(place__point__distance_lte=(pnt,
>> D(mi=2))).distance(pnt).order_by('distance')
>>
>> But I get:
>>
>> TypeError: ST_Distance output only available on GeometryFields.
>>
>> I'm sure there's a way to do this and I'm just not seeing it. Can
>> anyone point me in a direction?
It's failing because there's no geographic field on `Model`.
GeoQuerySet methods operate on the first geographic field in the model
by default. It looks like you want to perform the query on the point
column of a _related_ model -- thus, you'll have to specify this with
the `field_name` keyword your `distance()` call [1]:
places =
Model.objects.filter(place__point__distance_lte=(pnt,D(mi=2))).distance(pnt,
field_name='place__point').order_by('distance')
Note that for this to work, you'll need to have `objects = GeoManager()`
on Model, which I'm assuming you don't. [2]
[1]
http://docs.djangoproject.com/en/dev/ref/contrib/gis/geoquerysets/#geoqueryset-methods
[2]
http://docs.djangoproject.com/en/dev/ref/contrib/gis/model-api/#geomanager
-Justin
you may do that easily
best regards
P
--
Paolo Corti
GIS Architect and Developer
web: http://www.paolocorti.net
twitter: @paolo_corti