From aff0e54d511f55dbcdbae6a79c237fbb3edc9973 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 17 Jan 2015 15:43:02 +0100 Subject: [PATCH] Fixed PostGIS crosses lookup and added crosses test --- django/contrib/gis/db/backends/base/features.py | 4 ++++ .../contrib/gis/db/backends/postgis/operations.py | 2 +- django/contrib/gis/tests/geoapp/tests.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/django/contrib/gis/db/backends/base/features.py b/django/contrib/gis/db/backends/base/features.py index f43724dcf7..ecefde493b 100644 --- a/django/contrib/gis/db/backends/base/features.py +++ b/django/contrib/gis/db/backends/base/features.py @@ -41,6 +41,10 @@ class BaseSpatialFeatures(object): def supports_contained_lookup(self): return 'contained' in self.connection.ops.gis_operators + @property + def supports_crosses_lookup(self): + return 'crosses' in self.connection.ops.gis_operators + @property def supports_dwithin_lookup(self): return 'dwithin' in self.connection.ops.gis_operators diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py index 44cab5d12a..2255897f2f 100644 --- a/django/contrib/gis/db/backends/postgis/operations.py +++ b/django/contrib/gis/db/backends/postgis/operations.py @@ -71,7 +71,7 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations): 'contains_properly': PostGISOperator(func='ST_ContainsProperly'), 'coveredby': PostGISOperator(func='ST_CoveredBy', geography=True), 'covers': PostGISOperator(func='ST_Covers', geography=True), - 'crosses': PostGISOperator(func='ST_Crosses)'), + 'crosses': PostGISOperator(func='ST_Crosses'), 'disjoint': PostGISOperator(func='ST_Disjoint'), 'equals': PostGISOperator(func='ST_Equals'), 'intersects': PostGISOperator(func='ST_Intersects', geography=True), diff --git a/django/contrib/gis/tests/geoapp/tests.py b/django/contrib/gis/tests/geoapp/tests.py index 8d20ef843a..0dc4ce269d 100644 --- a/django/contrib/gis/tests/geoapp/tests.py +++ b/django/contrib/gis/tests/geoapp/tests.py @@ -286,6 +286,21 @@ class GeoLookupTest(TestCase): self.assertEqual(1, len(qs)) self.assertEqual('Texas', qs[0].name) + @skipUnlessDBFeature("supports_crosses_lookup") + def test_crosses_lookup(self): + Track.objects.create( + name='Line1', + line=LineString([(-95, 29), (-60, 0)]) + ) + self.assertEqual( + Track.objects.filter(line__crosses=LineString([(-95, 0), (-60, 29)])).count(), + 1 + ) + self.assertEqual( + Track.objects.filter(line__crosses=LineString([(-95, 30), (0, 30)])).count(), + 0 + ) + @skipUnlessDBFeature("supports_left_right_lookups") def test_left_right_lookups(self): "Testing the 'left' and 'right' lookup types."