Skip to content

Commit

Permalink
Refs #35058 -- Added support for measured geometries to GDAL Polygon.
Browse files Browse the repository at this point in the history
  • Loading branch information
smithdc1 authored Jan 31, 2024
1 parent b9e2a3f commit d3922e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
4 changes: 3 additions & 1 deletion django/contrib/gis/gdal/geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions docs/releases/5.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
32 changes: 30 additions & 2 deletions tests/gis_tests/gdal_tests/test_geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d3922e9

Please sign in to comment.