From a6c803a2e3d270818d20f3f0c76e2241de9f0ab1 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Mon, 14 Dec 2015 09:33:15 +0500 Subject: [PATCH] Fixed #25932 -- Made predicates of OGRGeometry return bool instead of int. --- django/contrib/gis/gdal/prototypes/geom.py | 2 +- tests/gis_tests/gdal_tests/test_geom.py | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/django/contrib/gis/gdal/prototypes/geom.py b/django/contrib/gis/gdal/prototypes/geom.py index 2bcc5a021c..993c15c166 100644 --- a/django/contrib/gis/gdal/prototypes/geom.py +++ b/django/contrib/gis/gdal/prototypes/geom.py @@ -26,7 +26,7 @@ def pnt_func(f): def topology_func(f): f.argtypes = [c_void_p, c_void_p] f.restype = c_int - f.errchck = bool + f.errcheck = lambda result, func, cargs: bool(result) return f # ### OGR_G ctypes function prototypes ### diff --git a/tests/gis_tests/gdal_tests/test_geom.py b/tests/gis_tests/gdal_tests/test_geom.py index 27ca4654b7..60aecd1d35 100644 --- a/tests/gis_tests/gdal_tests/test_geom.py +++ b/tests/gis_tests/gdal_tests/test_geom.py @@ -489,7 +489,49 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): self.assertEqual(3, geom[0].coord_dim) self.assertEqual(wkt_3d, geom.wkt) + # Testing binary predicates, `assertIs` is used to check that bool is returned. + def test_equivalence_regression(self): "Testing equivalence methods with non-OGRGeometry instances." self.assertIsNotNone(OGRGeometry('POINT(0 0)')) self.assertNotEqual(OGRGeometry('LINESTRING(0 0, 1 1)'), 3) + + def test_contains(self): + self.assertIs(OGRGeometry('POINT(0 0)').contains(OGRGeometry('POINT(0 0)')), True) + self.assertIs(OGRGeometry('POINT(0 0)').contains(OGRGeometry('POINT(0 1)')), False) + + def test_crosses(self): + self.assertIs(OGRGeometry('LINESTRING(0 0, 1 1)').crosses(OGRGeometry('LINESTRING(0 1, 1 0)')), True) + self.assertIs(OGRGeometry('LINESTRING(0 0, 0 1)').crosses(OGRGeometry('LINESTRING(1 0, 1 1)')), False) + + def test_disjoint(self): + self.assertIs(OGRGeometry('LINESTRING(0 0, 1 1)').disjoint(OGRGeometry('LINESTRING(0 1, 1 0)')), False) + self.assertIs(OGRGeometry('LINESTRING(0 0, 0 1)').disjoint(OGRGeometry('LINESTRING(1 0, 1 1)')), True) + + def test_equals(self): + self.assertIs(OGRGeometry('POINT(0 0)').contains(OGRGeometry('POINT(0 0)')), True) + self.assertIs(OGRGeometry('POINT(0 0)').contains(OGRGeometry('POINT(0 1)')), False) + + def test_intersects(self): + self.assertIs(OGRGeometry('LINESTRING(0 0, 1 1)').intersects(OGRGeometry('LINESTRING(0 1, 1 0)')), True) + self.assertIs(OGRGeometry('LINESTRING(0 0, 0 1)').intersects(OGRGeometry('LINESTRING(1 0, 1 1)')), False) + + def test_overlaps(self): + self.assertIs( + OGRGeometry('POLYGON ((0 0, 0 2, 2 2, 2 0, 0 0))').overlaps( + OGRGeometry('POLYGON ((1 1, 1 5, 5 5, 5 1, 1 1))') + ), True + ) + self.assertIs(OGRGeometry('POINT(0 0)').overlaps(OGRGeometry('POINT(0 1)')), False) + + def test_touches(self): + self.assertIs( + OGRGeometry('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))').touches(OGRGeometry('LINESTRING(0 2, 2 0)')), True + ) + self.assertIs(OGRGeometry('POINT(0 0)').touches(OGRGeometry('POINT(0 1)')), False) + + def test_within(self): + self.assertIs( + OGRGeometry('POINT(0.5 0.5)').within(OGRGeometry('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')), True + ) + self.assertIs(OGRGeometry('POINT(0 0)').within(OGRGeometry('POINT(0 1)')), False)