From 35504f74a8c3b45d308969a77488d11443ce4348 Mon Sep 17 00:00:00 2001 From: Kevan Swanberg Date: Thu, 21 Jul 2016 16:54:07 -0400 Subject: [PATCH] Fixed #26685 -- Added dwithin lookup support on SpatiaLite. --- django/contrib/gis/db/backends/spatialite/operations.py | 1 + docs/ref/contrib/gis/db-api.txt | 2 +- docs/ref/contrib/gis/geoquerysets.txt | 5 +++-- docs/releases/1.11.txt | 2 ++ tests/gis_tests/distapp/tests.py | 6 ++++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py index 7a5343e2e6..41e829a815 100644 --- a/django/contrib/gis/db/backends/spatialite/operations.py +++ b/django/contrib/gis/db/backends/spatialite/operations.py @@ -58,6 +58,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations): gis_operators = { 'equals': SpatialOperator(func='Equals'), 'disjoint': SpatialOperator(func='Disjoint'), + 'dwithin': SpatialOperator(func='PtDistWithin'), 'touches': SpatialOperator(func='Touches'), 'crosses': SpatialOperator(func='Crosses'), 'within': SpatialOperator(func='Within'), diff --git a/docs/ref/contrib/gis/db-api.txt b/docs/ref/contrib/gis/db-api.txt index 6ac4b81c58..55387cd721 100644 --- a/docs/ref/contrib/gis/db-api.txt +++ b/docs/ref/contrib/gis/db-api.txt @@ -343,7 +343,7 @@ Lookup Type PostGIS Oracle MySQL [#]_ SpatiaLite :lookup:`distance_gte` X X X N :lookup:`distance_lt` X X X N :lookup:`distance_lte` X X X N -:lookup:`dwithin` X X B +:lookup:`dwithin` X X X B :lookup:`equals` X X X X C :lookup:`exact` X X X X B :lookup:`intersects` X X X X B diff --git a/docs/ref/contrib/gis/geoquerysets.txt b/docs/ref/contrib/gis/geoquerysets.txt index 7d2bcbdd6e..6f2ee01e36 100644 --- a/docs/ref/contrib/gis/geoquerysets.txt +++ b/docs/ref/contrib/gis/geoquerysets.txt @@ -708,11 +708,12 @@ Backend SQL Equivalent ========== ====================================== PostGIS ``ST_DWithin(poly, geom, 5)`` Oracle ``SDO_WITHIN_DISTANCE(poly, geom, 5)`` +SpatiaLite ``PtDistWithin(poly, geom, 5)`` ========== ====================================== -.. note:: +.. versionchanged:: 1.11 - This lookup is not available on SpatiaLite. + SpatiaLite support was added. .. _geoqueryset-methods: diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt index 67c247c86e..3953ba917c 100644 --- a/docs/releases/1.11.txt +++ b/docs/releases/1.11.txt @@ -114,6 +114,8 @@ Minor features * The new :meth:`.GEOSGeometry.from_gml` and :meth:`.OGRGeometry.from_gml` methods allow creating geometries from GML. +* Added support for the :lookup:`dwithin` lookup on SpatiaLite. + :mod:`django.contrib.messages` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/gis_tests/distapp/tests.py b/tests/gis_tests/distapp/tests.py index fd4e6dfaca..cb0c422a54 100644 --- a/tests/gis_tests/distapp/tests.py +++ b/tests/gis_tests/distapp/tests.py @@ -10,7 +10,7 @@ from django.db.models import F, Q from django.test import TestCase, ignore_warnings, skipUnlessDBFeature from django.utils.deprecation import RemovedInDjango20Warning -from ..utils import no_oracle, oracle, postgis +from ..utils import no_oracle, oracle, postgis, spatialite from .models import ( AustraliaCity, CensusZipcode, Interstate, SouthTexasCity, SouthTexasCityFt, SouthTexasInterstate, SouthTexasZipcode, @@ -82,9 +82,11 @@ class DistanceTest(TestCase): type_error = False if isinstance(dist, tuple): - if oracle: + if oracle or spatialite: + # Result in meters dist = dist[1] else: + # Result in units of the field dist = dist[0] # Creating the query set.