From 222bf2932b55ebc964ffc5f9a6f47bad083e5ac2 Mon Sep 17 00:00:00 2001 From: David Smith Date: Mon, 12 Feb 2024 07:50:08 +0000 Subject: [PATCH] Refs #35058 -- Added support for measured geometries to GDAL GeometryCollection and subclasses. --- django/contrib/gis/gdal/geometries.py | 16 +++++++--- docs/releases/5.1.txt | 9 +++--- tests/gis_tests/gdal_tests/test_geom.py | 40 ++++++++++++++++++++----- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index 6ee98c412d..44e1026e3f 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -801,14 +801,22 @@ GEO_CLASSES = { 2001: Point, # POINT M 2002: LineString, # LINESTRING M 2003: Polygon, # POLYGON M + 2004: MultiPoint, # MULTIPOINT M + 2005: MultiLineString, # MULTILINESTRING M + 2006: MultiPolygon, # MULTIPOLYGON M + 2007: GeometryCollection, # GEOMETRYCOLLECTION M 3001: Point, # POINT ZM 3002: LineString, # LINESTRING ZM 3003: Polygon, # POLYGON ZM + 3004: MultiPoint, # MULTIPOINT ZM + 3005: MultiLineString, # MULTILINESTRING ZM + 3006: MultiPolygon, # MULTIPOLYGON ZM + 3007: GeometryCollection, # GEOMETRYCOLLECTION ZM 1 + OGRGeomType.wkb25bit: Point, # POINT Z 2 + OGRGeomType.wkb25bit: LineString, # LINESTRING Z 3 + OGRGeomType.wkb25bit: Polygon, # POLYGON Z - 4 + OGRGeomType.wkb25bit: MultiPoint, - 5 + OGRGeomType.wkb25bit: MultiLineString, - 6 + OGRGeomType.wkb25bit: MultiPolygon, - 7 + OGRGeomType.wkb25bit: GeometryCollection, + 4 + OGRGeomType.wkb25bit: MultiPoint, # MULTIPOINT Z + 5 + OGRGeomType.wkb25bit: MultiLineString, # MULTILINESTRING Z + 6 + OGRGeomType.wkb25bit: MultiPolygon, # MULTIPOLYGON Z + 7 + OGRGeomType.wkb25bit: GeometryCollection, # GEOMETRYCOLLECTION Z } diff --git a/docs/releases/5.1.txt b/docs/releases/5.1.txt index aca1281a98..94c342e8a0 100644 --- a/docs/releases/5.1.txt +++ b/docs/releases/5.1.txt @@ -81,10 +81,11 @@ Minor features * :class:`~django.contrib.gis.gdal.OGRGeometry`, :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. + :class:`~django.contrib.gis.gdal.LineString`, + :class:`~django.contrib.gis.gdal.Polygon`, and + :class:`~django.contrib.gis.gdal.GeometryCollection` and its subclasses now + support measured geometries via the new :attr:`.OGRGeometry.is_measured` and + ``m`` properties, and the :meth:`.OGRGeometry.set_measured` method. * :attr:`.OGRGeometry.centroid` is now available on all supported geometry types. diff --git a/tests/gis_tests/gdal_tests/test_geom.py b/tests/gis_tests/gdal_tests/test_geom.py index 35b11b753a..3967b945a4 100644 --- a/tests/gis_tests/gdal_tests/test_geom.py +++ b/tests/gis_tests/gdal_tests/test_geom.py @@ -675,10 +675,10 @@ class OGRGeomTest(SimpleTestCase, TestDataMixin): ("Point M", 2001, True), ("LineString M", 2002, True), ("Polygon M", 2003, True), - ("MultiPoint M", 2004, False), - ("MultiLineString M", 2005, False), - ("MultiPolygon M", 2006, False), - ("GeometryCollection M", 2007, False), + ("MultiPoint M", 2004, True), + ("MultiLineString M", 2005, True), + ("MultiPolygon M", 2006, True), + ("GeometryCollection M", 2007, True), ("CircularString M", 2008, False), ("CompoundCurve M", 2009, False), ("CurvePolygon M", 2010, False), @@ -690,10 +690,10 @@ class OGRGeomTest(SimpleTestCase, TestDataMixin): ("Point ZM", 3001, True), ("LineString ZM", 3002, True), ("Polygon ZM", 3003, True), - ("MultiPoint ZM", 3004, False), - ("MultiLineString ZM", 3005, False), - ("MultiPolygon ZM", 3006, False), - ("GeometryCollection ZM", 3007, False), + ("MultiPoint ZM", 3004, True), + ("MultiLineString ZM", 3005, True), + ("MultiPolygon ZM", 3006, True), + ("GeometryCollection ZM", 3007, True), ("CircularString ZM", 3008, False), ("CompoundCurve ZM", 3009, False), ("CurvePolygon ZM", 3010, False), @@ -943,6 +943,30 @@ class OGRGeomTest(SimpleTestCase, TestDataMixin): geom.shell.wkt, "LINEARRING (0 0 0,10 0 0,10 10 0,0 10 0,0 0 0)" ) + def test_multi_geometries_m_dimension(self): + tests = [ + "MULTIPOINT M ((10 40 10), (40 30 10), (20 20 10))", + "MULTIPOINT ZM ((10 40 0 10), (40 30 1 10), (20 20 1 10))", + "MULTILINESTRING M ((10 10 1, 20 20 2),(40 40 1, 30 30 2))", + "MULTILINESTRING ZM ((10 10 0 1, 20 20 0 2),(40 40 1, 30 30 0 2))", + ( + "MULTIPOLYGON ZM (((30 20 1 0, 45 40 1 0, 30 20 1 0))," + "((15 5 0 0, 40 10 0 0, 15 5 0 0)))" + ), + ( + "GEOMETRYCOLLECTION M (POINT M (40 10 0)," + "LINESTRING M (10 10 0, 20 20 0, 10 40 0))" + ), + ( + "GEOMETRYCOLLECTION ZM (POINT ZM (40 10 0 1)," + "LINESTRING ZM (10 10 1 0, 20 20 1 0, 10 40 1 0))" + ), + ] + for geom_input in tests: + with self.subTest(geom_input=geom_input): + geom = OGRGeometry(geom_input) + self.assertIs(geom.is_measured, True) + class DeprecationTests(SimpleTestCase): def test_coord_setter_deprecation(self):