#25605: GeoDjango DB functions doesn't really work with expressions
----------------------------+--------------------
Reporter: sir-sigurd | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
geotest/models.py:
{{{
class Test(models.Model):
point1 = models.PointField()
point2 = models.PointField()
}}}
python manage.py shell
{{{
In [1]: %paste
from django.contrib.gis.db.models.functions import Distance
from django.contrib.gis.geos import Point
from geotest.models import Test
point1 = Point(0, 0, srid=4326)
point2 = Point(0, 1, srid=4326)
Test.objects.create(point1=point1, point2=point2)
## -- End pasted text --
Out[1]: <Test: Test object>
In [2]: print Test.objects.annotate(dist=Distance('point1',
point2)).last().dist
111195.079735 m
In [3]: print Test.objects.annotate(dist=Distance(point1,
'point2')).last().dist
GEOS_ERROR: ParseException: Unknown type: 'POINT2'
---------------------------------------------------------------------------
ValueError Traceback (most recent call
last)
<ipython-input-3-aa91ca51a4df> in <module>()
----> 1 print Test.objects.annotate(dist=Distance(point1,
'point2')).last().dist
/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expr1, expr2, spheroid, **extra)
239 self.spheroid = spheroid
240 expressions += (self._handle_param(spheroid,
'spheroid', bool),)
--> 241 super(Distance, self).__init__(*expressions, **extra)
242
243 def as_postgresql(self, compiler, connection):
/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expression, geom, *expressions, **extra)
97 geom = GEOSGeometry(geom)
98 except Exception:
---> 99 raise ValueError("This function requires a
geometric parameter.")
100 if not geom.srid:
101 raise ValueError("Please provide a geometry attribute
with a defined SRID.")
ValueError: This function requires a geometric parameter.
In [4]: print Test.objects.annotate(dist=Distance('point1',
'point2')).last().dist
GEOS_ERROR: ParseException: Unknown type: 'POINT2'
---------------------------------------------------------------------------
ValueError Traceback (most recent call
last)
<ipython-input-4-177990c7d19a> in <module>()
----> 1 print Test.objects.annotate(dist=Distance('point1',
'point2')).last().dist
/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expr1, expr2, spheroid, **extra)
239 self.spheroid = spheroid
240 expressions += (self._handle_param(spheroid,
'spheroid', bool),)
--> 241 super(Distance, self).__init__(*expressions, **extra)
242
243 def as_postgresql(self, compiler, connection):
/home/sergey/dev/django/django/contrib/gis/db/models/functions.pyc in
__init__(self, expression, geom, *expressions, **extra)
97 geom = GEOSGeometry(geom)
98 except Exception:
---> 99 raise ValueError("This function requires a
geometric parameter.")
100 if not geom.srid:
101 raise ValueError("Please provide a geometry attribute
with a defined SRID.")
ValueError: This function requires a geometric parameter.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25605>
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/053.37e8bb9d5ac68281b953a8752ce57671%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.