diff options
| author | Claude Paroz <claude@2xlibre.net> | 2015-01-17 15:43:02 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-01-17 15:46:50 +0100 |
| commit | 6b1b7263f4b0065a8a514abfd7e74e17e742dbf6 (patch) | |
| tree | 772aacf5863711738a452152cec153e74e6aae50 | |
| parent | b714316c0606110cd508863b6d12650004366aaf (diff) | |
[1.8.x] Fixed PostGIS crosses lookup and added crosses test
Backport of aff0e54d5 from master.
| -rw-r--r-- | django/contrib/gis/db/backends/base/features.py | 4 | ||||
| -rw-r--r-- | django/contrib/gis/db/backends/postgis/operations.py | 2 | ||||
| -rw-r--r-- | django/contrib/gis/tests/geoapp/tests.py | 15 |
3 files changed, 20 insertions, 1 deletions
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 @@ -42,6 +42,10 @@ class BaseSpatialFeatures(object): 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." |
