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

  1. Edit the doc to mention these limitations
  2. (much better) Fix the code to accept expressions in expr2 as documented (and GEOSGeometry 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 Antoine Auberger, 8 years ago

Version: 1.101.9

comment:2 by Simon Charette, 8 years ago

Triage Stage: UnreviewedAccepted
Version: 1.9master

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.

comment:3 by Sergey Fedoseev, 8 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #25605.

Note: See TracTickets for help on using tickets.
Back to Top