summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Wiesmann <daniel.wiesmann@gmail.com>2016-04-06 12:50:25 +0100
committerTim Graham <timograham@gmail.com>2016-04-09 09:22:30 -0400
commitc12a00e554c8b4b93931b520bb94a479c5ba8706 (patch)
tree235f37a8c8ce8e0e4cc2a8736bcc9b7b14244fdd /tests
parentf6ca63a9f8b3d030097135e096c1041e09c29fd9 (diff)
Fixed #26455 -- Allowed filtering and repairing invalid geometries.
Added the IsValid and MakeValid database functions, and the isvalid lookup, all for PostGIS. Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/gis_tests/geoapp/test_functions.py19
-rw-r--r--tests/gis_tests/geoapp/tests.py7
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py
index 344fa03e61..c42ed95a86 100644
--- a/tests/gis_tests/geoapp/test_functions.py
+++ b/tests/gis_tests/geoapp/test_functions.py
@@ -233,6 +233,17 @@ class GISFunctionsTests(TestCase):
expected = c.mpoly.intersection(geom)
self.assertEqual(c.inter, expected)
+ @skipUnlessDBFeature("has_IsValid_function")
+ def test_isvalid(self):
+ valid_geom = fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))')
+ invalid_geom = fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 1 1, 1 0, 0 0))')
+ State.objects.create(name='valid', poly=valid_geom)
+ State.objects.create(name='invalid', poly=invalid_geom)
+ valid = State.objects.filter(name='valid').annotate(isvalid=functions.IsValid('poly')).first()
+ invalid = State.objects.filter(name='invalid').annotate(isvalid=functions.IsValid('poly')).first()
+ self.assertEqual(valid.isvalid, True)
+ self.assertEqual(invalid.isvalid, False)
+
@skipUnlessDBFeature("has_Area_function")
def test_area_with_regular_aggregate(self):
# Create projected country objects, for this test to work on all backends.
@@ -249,6 +260,14 @@ class GISFunctionsTests(TestCase):
result = result.sq_m
self.assertAlmostEqual((result - c.mpoly.area) / c.mpoly.area, 0)
+ @skipUnlessDBFeature("has_MakeValid_function")
+ def test_make_valid(self):
+ invalid_geom = fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 1 1, 1 0, 0 0))')
+ State.objects.create(name='invalid', poly=invalid_geom)
+ invalid = State.objects.filter(name='invalid').annotate(repaired=functions.MakeValid('poly')).first()
+ self.assertEqual(invalid.repaired.valid, True)
+ self.assertEqual(invalid.repaired, fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'))
+
@skipUnlessDBFeature("has_MemSize_function")
def test_memsize(self):
ptown = City.objects.annotate(size=functions.MemSize('point')).get(name='Pueblo')
diff --git a/tests/gis_tests/geoapp/tests.py b/tests/gis_tests/geoapp/tests.py
index f0b6f7ba65..2b215f80a9 100644
--- a/tests/gis_tests/geoapp/tests.py
+++ b/tests/gis_tests/geoapp/tests.py
@@ -300,6 +300,13 @@ class GeoLookupTest(TestCase):
0
)
+ @skipUnlessDBFeature("supports_isvalid_lookup")
+ def test_isvalid_lookup(self):
+ invalid_geom = fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 1 1, 1 0, 0 0))')
+ State.objects.create(name='invalid', poly=invalid_geom)
+ self.assertEqual(State.objects.filter(poly__isvalid=False).count(), 1)
+ self.assertEqual(State.objects.filter(poly__isvalid=True).count(), State.objects.count() - 1)
+
@skipUnlessDBFeature("supports_left_right_lookups")
def test_left_right_lookups(self):
"Testing the 'left' and 'right' lookup types."