From d3922e9e5ad045f5408b02216a824f26a50950f0 Mon Sep 17 00:00:00 2001 From: David Smith <39445562+smithdc1@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:11:16 +0000 Subject: [PATCH] Refs #35058 -- Added support for measured geometries to GDAL Polygon. --- django/contrib/gis/gdal/geometries.py | 4 +++- docs/releases/5.1.txt | 5 ++-- tests/gis_tests/gdal_tests/test_geom.py | 32 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index 83b7b39fd0df..6ee98c412d80 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -800,11 +800,13 @@ class MultiPolygon(GeometryCollection): 101: LinearRing, 2001: Point, # POINT M 2002: LineString, # LINESTRING M + 2003: Polygon, # POLYGON M 3001: Point, # POINT ZM 3002: LineString, # LINESTRING ZM + 3003: Polygon, # POLYGON ZM 1 + OGRGeomType.wkb25bit: Point, # POINT Z 2 + OGRGeomType.wkb25bit: LineString, # LINESTRING Z - 3 + OGRGeomType.wkb25bit: Polygon, + 3 + OGRGeomType.wkb25bit: Polygon, # POLYGON Z 4 + OGRGeomType.wkb25bit: MultiPoint, 5 + OGRGeomType.wkb25bit: MultiLineString, 6 + OGRGeomType.wkb25bit: MultiPolygon, diff --git a/docs/releases/5.1.txt b/docs/releases/5.1.txt index f1664746079c..3fefaa9f0e94 100644 --- a/docs/releases/5.1.txt +++ b/docs/releases/5.1.txt @@ -79,8 +79,9 @@ Minor features ``Z`` coordinate dimension. * :class:`~django.contrib.gis.gdal.OGRGeometry`, - :class:`~django.contrib.gis.gdal.Point`, and - :class:`~django.contrib.gis.gdal.LineString` now support measured geometries + :class:`~django.contrib.gis.gdal.Point`, + :class:`~django.contrib.gis.gdal.LineString`, and + :class:`~django.contrib.gis.gdal.Polygon` now support measured geometries via the new :attr:`.OGRGeometry.is_measured` and ``m`` properties, and the :meth:`.OGRGeometry.set_measured` method. diff --git a/tests/gis_tests/gdal_tests/test_geom.py b/tests/gis_tests/gdal_tests/test_geom.py index abcfbc9eab91..35b11b753a82 100644 --- a/tests/gis_tests/gdal_tests/test_geom.py +++ b/tests/gis_tests/gdal_tests/test_geom.py @@ -674,7 +674,7 @@ def test_geometry_types(self): ("Triangle Z", 1017, False), ("Point M", 2001, True), ("LineString M", 2002, True), - ("Polygon M", 2003, False), + ("Polygon M", 2003, True), ("MultiPoint M", 2004, False), ("MultiLineString M", 2005, False), ("MultiPolygon M", 2006, False), @@ -689,7 +689,7 @@ def test_geometry_types(self): ("Triangle M", 2017, False), ("Point ZM", 3001, True), ("LineString ZM", 3002, True), - ("Polygon ZM", 3003, False), + ("Polygon ZM", 3003, True), ("MultiPoint ZM", 3004, False), ("MultiLineString ZM", 3005, False), ("MultiPolygon ZM", 3006, False), @@ -915,6 +915,34 @@ def test_linestring_m_dimension(self): self.assertIs(geom.is_measured, False) self.assertIs(geom.m, None) + def test_polygon_m_dimension(self): + geom = OGRGeometry("POLYGON Z ((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0))") + self.assertIs(geom.is_measured, False) + self.assertEqual( + geom.shell.wkt, "LINEARRING (0 0 0,10 0 0,10 10 0,0 10 0,0 0 0)" + ) + + geom = OGRGeometry("POLYGON M ((0 0 0, 10 0 0, 10 10 0, 0 10 0, 0 0 0))") + self.assertIs(geom.is_measured, True) + self.assertEqual( + geom.shell.wkt, "LINEARRING M (0 0 0,10 0 0,10 10 0,0 10 0,0 0 0)" + ) + + geom = OGRGeometry( + "POLYGON ZM ((0 0 0 1, 10 0 0 1, 10 10 0 1, 0 10 0 1, 0 0 0 1))" + ) + self.assertIs(geom.is_measured, True) + self.assertEqual( + geom.shell.wkt, + "LINEARRING ZM (0 0 0 1,10 0 0 1,10 10 0 1,0 10 0 1,0 0 0 1)", + ) + + geom.set_measured(False) + self.assertEqual(geom.wkt, "POLYGON ((0 0 0,10 0 0,10 10 0,0 10 0,0 0 0))") + self.assertEqual( + geom.shell.wkt, "LINEARRING (0 0 0,10 0 0,10 10 0,0 10 0,0 0 0)" + ) + class DeprecationTests(SimpleTestCase): def test_coord_setter_deprecation(self):