From 03c6ad7ad44032206a8780f74c693d16ca1f1a37 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Mon, 2 Nov 2015 20:20:53 +0500 Subject: [PATCH] Fixed #25664 -- Fixed `dims` for `Point` --- django/contrib/gis/geos/prototypes/geom.py | 2 +- tests/gis_tests/geos_tests/test_geos.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/django/contrib/gis/geos/prototypes/geom.py b/django/contrib/gis/geos/prototypes/geom.py index 1d4247f414..dec3a0d203 100644 --- a/django/contrib/gis/geos/prototypes/geom.py +++ b/django/contrib/gis/geos/prototypes/geom.py @@ -82,7 +82,7 @@ to_wkt = StringFromGeom('GEOSGeomToWKT') geos_normalize = IntFromGeom('GEOSNormalize') geos_type = StringFromGeom('GEOSGeomType') geos_typeid = IntFromGeom('GEOSGeomTypeId') -get_dims = IntFromGeom('GEOSGeom_getDimensions', zero=True) +get_dims = GEOSFuncFactory('GEOSGeom_getDimensions', argtypes=[GEOM_PTR], restype=c_int) get_num_coords = IntFromGeom('GEOSGetNumCoordinates') get_num_geoms = IntFromGeom('GEOSGetNumGeometries') diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index e2f6576759..26c88e85fb 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -228,6 +228,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): pnt = fromstr(p.wkt) self.assertEqual(pnt.geom_type, 'Point') self.assertEqual(pnt.geom_typeid, 0) + self.assertEqual(pnt.dims, 0) self.assertEqual(p.x, pnt.x) self.assertEqual(p.y, pnt.y) self.assertEqual(pnt, fromstr(p.wkt)) @@ -281,6 +282,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): mpnt = fromstr(mp.wkt) self.assertEqual(mpnt.geom_type, 'MultiPoint') self.assertEqual(mpnt.geom_typeid, 4) + self.assertEqual(mpnt.dims, 0) self.assertAlmostEqual(mp.centroid[0], mpnt.centroid.tuple[0], 9) self.assertAlmostEqual(mp.centroid[1], mpnt.centroid.tuple[1], 9) @@ -301,6 +303,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): ls = fromstr(l.wkt) self.assertEqual(ls.geom_type, 'LineString') self.assertEqual(ls.geom_typeid, 1) + self.assertEqual(ls.dims, 1) self.assertEqual(ls.empty, False) self.assertEqual(ls.ring, False) if hasattr(l, 'centroid'): @@ -329,6 +332,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): ml = fromstr(l.wkt) self.assertEqual(ml.geom_type, 'MultiLineString') self.assertEqual(ml.geom_typeid, 5) + self.assertEqual(ml.dims, 1) self.assertAlmostEqual(l.centroid[0], ml.centroid.x, 9) self.assertAlmostEqual(l.centroid[1], ml.centroid.y, 9) @@ -352,6 +356,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): lr = fromstr(rr.wkt) self.assertEqual(lr.geom_type, 'LinearRing') self.assertEqual(lr.geom_typeid, 2) + self.assertEqual(lr.dims, 1) self.assertEqual(rr.n_p, len(lr)) self.assertEqual(True, lr.valid) self.assertEqual(False, lr.empty) @@ -385,6 +390,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): poly = fromstr(p.wkt) self.assertEqual(poly.geom_type, 'Polygon') self.assertEqual(poly.geom_typeid, 3) + self.assertEqual(poly.dims, 2) self.assertEqual(poly.empty, False) self.assertEqual(poly.ring, False) self.assertEqual(p.n_i, poly.num_interior_rings) @@ -462,6 +468,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): mpoly = fromstr(mp.wkt) self.assertEqual(mpoly.geom_type, 'MultiPolygon') self.assertEqual(mpoly.geom_typeid, 6) + self.assertEqual(mpoly.dims, 2) self.assertEqual(mp.valid, mpoly.valid) if mp.valid: @@ -831,6 +838,19 @@ class GEOSTest(unittest.TestCase, TestDataMixin): else: self.assertRaises(IndexError, g.__getitem__, 0) + def test_collection_dims(self): + gc = GeometryCollection([]) + self.assertEqual(gc.dims, -1) + + gc = GeometryCollection(Point(0, 0)) + self.assertEqual(gc.dims, 0) + + gc = GeometryCollection(LineString((0, 0), (1, 1)), Point(0, 0)) + self.assertEqual(gc.dims, 1) + + gc = GeometryCollection(LineString((0, 0), (1, 1)), Polygon(((0, 0), (0, 1), (1, 1), (0, 0))), Point(0, 0)) + self.assertEqual(gc.dims, 2) + def test_collections_of_collections(self): "Testing GeometryCollection handling of other collections." # Creating a GeometryCollection WKT string composed of other