Opened 8 years ago
Closed 8 years ago
#27529 closed Bug (duplicate)
Geographic database functions with two parameters should accept expressions in one or the other arguments
Reported by: | Antoine Auberger | Owned by: | nobody |
---|---|---|---|
Component: | GIS | Version: | dev |
Severity: | Normal | Keywords: | gis geographic queryset |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Context
With the release of Django 1.9 database functions were introduced to simplify measurements, operations, lookups, etc. within the queryset.
Some of the functions introduced take two arguments : Difference
, Distance
, Intersection
, SymDifference
and Union
.
The doc (1) states these functions "Accepts two geographic fields or expressions and returns the distance between them".
Problem
As they all inherit from GeoFuncWithGeoParam
(2), they actually expect expr1
to be an expression (column or value), and expr2
to be a GEOSGeometry
object, despite stated otherwise.
If an expression is passed as expr2
, this error is raised :
In [0]: MyClass.objects.annotate(distance=Distance('field1', 'field2')) [...] ValueError: Please provide a geometry attribute with a defined SRID.
Solutions
- Edit the doc to mention these limitations
- (much better) Fix the code to accept expressions in
expr2
as documented (andGEOSGeometry
objects as expr1). Most of the backends support geographic measurements and operations between two fields, so there is not much to change.
Happy to work on a patch if the bug is validated.
(1) https://docs.djangoproject.com/en/dev/ref/contrib/gis/functions/#distance
(2) https://github.com/django/django/blob/1.9/django/contrib/gis/db/models/functions.py#L91
Change History (3)
comment:1 by , 8 years ago
Version: | 1.10 → 1.9 |
---|
comment:2 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.9 → master |
I'm not that familar with the GIS stuff but I could see queries using expression such as
Distance('field1', 'field2')
being useful and I can't see why we'd like to prevent that.