Question

I'm using geodjango and I want to filter rows from a table based on distance:

geom = models.MultiLineStringField()

When I use geodjango like so:

geo_objects.objects.filter(geom__dwithin=(pnt, D(km=10)))

where pnt is 'POINT (-73.5666999999996136 45.5000000000000213)'

Geodjango gives me:

*** django.core.exceptions.FieldError: Join on field 'geom' not permitted. Did you misspell 'dwithin' for the lookup type?

On the other hand, doing the same thing (as far as I understand) directly from the postgres command line returns sensible results:

select * from geo_objects
WHERE ST_DWithin(geo_objects.geom, 'POINT(-73.5665 45.5000)', 122222, false)

works perfectly well.

What am i doing wrong?

Thanks in advance.

Was it helpful?

Solution

thats the answer: in order to perform geometric queries, you need a geomanager. https://docs.djangoproject.com/en/dev/ref/contrib/gis/model-api/#geomanager

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top