From 1b6de8fd2377cc1c02d2c4e4dc4aae402b1b0afb Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 18 Jun 2016 17:10:16 +0200 Subject: [PATCH] [1.10.x] Fixed #26775 -- Supported dim=3 geography fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks François-Xavier Thomas for the report. Backport of 8ba44ecda0 from master. --- .../gis/db/backends/postgis/operations.py | 17 +++++++++-------- tests/gis_tests/geo3d/models.py | 1 + tests/gis_tests/geo3d/tests.py | 10 +++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py index 8216668ca5..d50f177918 100644 --- a/django/contrib/gis/db/backends/postgis/operations.py +++ b/django/contrib/gis/db/backends/postgis/operations.py @@ -268,18 +268,19 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations): """ if f.geom_type == 'RASTER': return 'raster' - elif f.geography: + + # Type-based geometries. + # TODO: Support 'M' extension. + if f.dim == 3: + geom_type = f.geom_type + 'Z' + else: + geom_type = f.geom_type + if f.geography: if f.srid != 4326: raise NotImplementedError('PostGIS only supports geography columns with an SRID of 4326.') - return 'geography(%s,%d)' % (f.geom_type, f.srid) + return 'geography(%s,%d)' % (geom_type, f.srid) else: - # Type-based geometries. - # TODO: Support 'M' extension. - if f.dim == 3: - geom_type = f.geom_type + 'Z' - else: - geom_type = f.geom_type return 'geometry(%s,%d)' % (geom_type, f.srid) def get_distance(self, f, dist_val, lookup_type, handle_spheroid=True): diff --git a/tests/gis_tests/geo3d/models.py b/tests/gis_tests/geo3d/models.py index e816cb3dad..bcb9e2dc57 100644 --- a/tests/gis_tests/geo3d/models.py +++ b/tests/gis_tests/geo3d/models.py @@ -19,6 +19,7 @@ class NamedModel(models.Model): class City3D(NamedModel): point = models.PointField(dim=3) + pointg = models.PointField(dim=3, geography=True) class Interstate2D(NamedModel): diff --git a/tests/gis_tests/geo3d/tests.py b/tests/gis_tests/geo3d/tests.py index 1181e4b6c2..50e8702f6f 100644 --- a/tests/gis_tests/geo3d/tests.py +++ b/tests/gis_tests/geo3d/tests.py @@ -91,7 +91,9 @@ class Geo3DLoadingHelper(object): def _load_city_data(self): for name, pnt_data in city_data: - City3D.objects.create(name=name, point=Point(*pnt_data, srid=4326)) + City3D.objects.create( + name=name, point=Point(*pnt_data, srid=4326), pointg=Point(*pnt_data, srid=4326), + ) def _load_polygon_data(self): bbox_wkt, bbox_z = bbox_data @@ -129,9 +131,11 @@ class Geo3DTest(Geo3DLoadingHelper, TestCase): self._load_city_data() for name, pnt_data in city_data: city = City3D.objects.get(name=name) - z = pnt_data[2] + # Testing both geometry and geography fields self.assertTrue(city.point.hasz) - self.assertEqual(z, city.point.z) + self.assertTrue(city.pointg.hasz) + self.assertEqual(city.point.z, pnt_data[2]) + self.assertEqual(city.pointg.z, pnt_data[2]) def test_3d_polygons(self): """