#22830: GeoDjango dwithin errors when using django.contrib.gis.measure.D
----------------------------+--------------------
Reporter: django@… | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
First off, I started a StackOverflow thread
[http://stackoverflow.com/questions/24194710/geodjango-dwithin-error-
argument-of-type-geoqueryset-is-not-iterable here] but haven't come up
with an answer yet. I think there may be a bug in Django somewhere.
Versions: Python 2.7.6, Django 1.6.5, Postgres 9.3.4, PostGIS 2.1.3,
psycopg2 2.5.3 on RHEL 6.5
Here's the model I'm using:
{{{
#!python
class Location(models.Model):
name = models.CharField(max_length=255)
geometry = models.MultiPolygonField(blank=True, default=None,
null=True)
objects = models.GeoManager() # override the default manager with a
GeoManager instance
parent = models.ForeignKey('self', blank=True, default=None,
null=True)
def __unicode__(self):
return self.name
}}}
This query should work
[https://docs.djangoproject.com/en/1.6/ref/contrib/gis/geoquerysets/#std
:fieldlookup-dwithin according to the docs]:
{{{
#!python
touching_locations =
Location.objects.filter(geometry__dwithin=(location.geometry, D(km=5)))
logging.debug(type(touching_locations))
logging.debug(len(touching_locations))
}}}
But it doesn't. The first debug call works, but the second throws a
`ValueError`:
{{{
<class 'django.contrib.gis.db.models.query.GeoQuerySet'>
ValueError: Only numeric values of degree units are allowed on geographic
DWithin queries.
}}}
If I make a small change by changing `D(km=5)` to `5`:
{{{
#!python
touching_locations =
Location.objects.filter(geometry__dwithin=(location.geometry, 5))
logging.debug(type(touching_locations))
logging.debug(len(touching_locations))
}}}
All of a sudden it works. The output I get is this:
{{{
<class 'django.contrib.gis.db.models.query.GeoQuerySet'>
54
}}}
Is there a bug somewhere in Django? Am I misunderstanding how to use `D`?
Are the Django docs incorrect? Is something else going on here? I
appreciate any help I can get. Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/22830>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.4fa2f190eff13fe5715fd102517e0e40%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.