Opened 10 years ago
Closed 9 years ago
#25605 closed Bug (fixed)
GIS functions don't work with left-hand-side expressions
| Reported by: | Sergey Fedoseev | Owned by: | Sergey Fedoseev |
|---|---|---|---|
| Component: | GIS | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (8)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 10 years ago
| Patch needs improvement: | set |
|---|
comment:4 by , 10 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 10 years ago
| Summary: | GeoDjango DB functions doesn't really work with expressions → GIS functions don't work with left-hand-side expressions |
|---|
Note:
See TracTickets
for help on using tickets.
PR -- https://github.com/django/django/pull/5477