summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Smith <smithdc@gmail.com>2025-09-04 18:57:32 +0100
committerJacob Walls <jacobtylerwalls@gmail.com>2026-02-09 08:44:08 -0500
commit218077d944e5e57a560f256034f5c4f13e77ab14 (patch)
tree0ac61a5ab28b76419a1d0050954fea799c2873fe /tests
parent7c54fee7760b1c61fd7f9cb7cc6a2965f4236137 (diff)
Refs #36036 -- Added m dimension to GEOSCoordSeq.
Diffstat (limited to 'tests')
-rw-r--r--tests/gis_tests/geos_tests/test_coordseq.py136
1 files changed, 135 insertions, 1 deletions
diff --git a/tests/gis_tests/geos_tests/test_coordseq.py b/tests/gis_tests/geos_tests/test_coordseq.py
index b6f5136dd1..37c421f5c3 100644
--- a/tests/gis_tests/geos_tests/test_coordseq.py
+++ b/tests/gis_tests/geos_tests/test_coordseq.py
@@ -1,4 +1,11 @@
-from django.contrib.gis.geos import LineString
+import math
+from unittest import skipIf
+from unittest.mock import patch
+
+from django.contrib.gis.geos import GEOSGeometry, LineString
+from django.contrib.gis.geos import prototypes as capi
+from django.contrib.gis.geos.coordseq import GEOSCoordSeq
+from django.contrib.gis.geos.libgeos import geos_version_tuple
from django.test import SimpleTestCase
@@ -13,3 +20,130 @@ class GEOSCoordSeqTest(SimpleTestCase):
with self.subTest(i):
with self.assertRaisesMessage(IndexError, msg):
coord_seq[i]
+
+ @skipIf(geos_version_tuple() < (3, 14), "GEOS M support requires 3.14+")
+ def test_has_m(self):
+ geom = GEOSGeometry("POINT ZM (1 2 3 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ self.assertIs(coord_seq.hasm, True)
+
+ geom = GEOSGeometry("POINT Z (1 2 3)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ self.assertIs(coord_seq.hasm, False)
+
+ geom = GEOSGeometry("POINT M (1 2 3)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ self.assertIs(coord_seq.hasm, True)
+
+ @skipIf(geos_version_tuple() < (3, 14), "GEOS M support requires 3.14+")
+ def test_get_set_m(self):
+ geom = GEOSGeometry("POINT ZM (1 2 3 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ self.assertEqual(coord_seq.tuple, (1, 2, 3, 4))
+ self.assertEqual(coord_seq.getM(0), 4)
+ coord_seq.setM(0, 10)
+ self.assertEqual(coord_seq.tuple, (1, 2, 3, 10))
+ self.assertEqual(coord_seq.getM(0), 10)
+
+ geom = GEOSGeometry("POINT M (1 2 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ self.assertEqual(coord_seq.tuple, (1, 2, 4))
+ self.assertEqual(coord_seq.getM(0), 4)
+ coord_seq.setM(0, 10)
+ self.assertEqual(coord_seq.tuple, (1, 2, 10))
+ self.assertEqual(coord_seq.getM(0), 10)
+ self.assertIs(math.isnan(coord_seq.getZ(0)), True)
+
+ @skipIf(geos_version_tuple() < (3, 14), "GEOS M support requires 3.14+")
+ def test_setitem(self):
+ geom = GEOSGeometry("POINT ZM (1 2 3 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ coord_seq[0] = (10, 20, 30, 40)
+ self.assertEqual(coord_seq.tuple, (10, 20, 30, 40))
+
+ geom = GEOSGeometry("POINT M (1 2 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ coord_seq[0] = (10, 20, 40)
+ self.assertEqual(coord_seq.tuple, (10, 20, 40))
+ self.assertEqual(coord_seq.getM(0), 40)
+ self.assertIs(math.isnan(coord_seq.getZ(0)), True)
+
+ @skipIf(geos_version_tuple() < (3, 14), "GEOS M support requires 3.14+")
+ def test_kml_m_dimension(self):
+ geom = GEOSGeometry("POINT ZM (1 2 3 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ self.assertEqual(coord_seq.kml, "<coordinates>1.0,2.0,3.0</coordinates>")
+ geom = GEOSGeometry("POINT M (1 2 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ self.assertEqual(coord_seq.kml, "<coordinates>1.0,2.0,0</coordinates>")
+
+ @skipIf(geos_version_tuple() < (3, 14), "GEOS M support requires 3.14+")
+ def test_clone_m_dimension(self):
+ geom = GEOSGeometry("POINT ZM (1 2 3 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ clone = coord_seq.clone()
+ self.assertEqual(clone.tuple, (1, 2, 3, 4))
+ self.assertIs(clone.hasz, True)
+ self.assertIs(clone.hasm, True)
+
+ geom = GEOSGeometry("POINT M (1 2 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ clone = coord_seq.clone()
+ self.assertEqual(clone.tuple, (1, 2, 4))
+ self.assertIs(clone.hasz, False)
+ self.assertIs(clone.hasm, True)
+
+ @skipIf(geos_version_tuple() < (3, 14), "GEOS M support requires 3.14+")
+ def test_dims(self):
+ geom = GEOSGeometry("POINT ZM (1 2 3 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ self.assertEqual(coord_seq.dims, 4)
+
+ geom = GEOSGeometry("POINT M (1 2 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ self.assertEqual(coord_seq.dims, 3)
+
+ geom = GEOSGeometry("POINT Z (1 2 3)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ self.assertEqual(coord_seq.dims, 3)
+
+ geom = GEOSGeometry("POINT (1 2)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ self.assertEqual(coord_seq.dims, 2)
+
+ def test_size(self):
+ geom = GEOSGeometry("POINT (1 2)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ self.assertEqual(coord_seq.size, 1)
+
+ geom = GEOSGeometry("POINT M (1 2 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=False)
+ self.assertEqual(coord_seq.size, 1)
+
+ @skipIf(geos_version_tuple() < (3, 14), "GEOS M support requires 3.14+")
+ def test_iscounterclockwise(self):
+ geom = GEOSGeometry("LINEARRING ZM (0 0 3 0, 1 0 0 2, 0 1 1 3, 0 0 3 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ self.assertEqual(
+ coord_seq.tuple,
+ (
+ (0.0, 0.0, 3.0, 0.0),
+ (1.0, 0.0, 0.0, 2.0),
+ (0.0, 1.0, 1.0, 3.0),
+ (0.0, 0.0, 3.0, 4.0),
+ ),
+ )
+ self.assertIs(coord_seq.is_counterclockwise, True)
+
+ def test_m_support_error(self):
+ geom = GEOSGeometry("POINT M (1 2 4)")
+ coord_seq = GEOSCoordSeq(capi.get_cs(geom.ptr), z=True)
+ msg = "GEOSCoordSeq with an M dimension requires GEOS 3.14+."
+
+ # mock geos_version_tuple to be 3.13.13
+ with patch(
+ "django.contrib.gis.geos.coordseq.geos_version_tuple",
+ return_value=(3, 13, 13),
+ ):
+ with self.assertRaisesMessage(NotImplementedError, msg):
+ coord_seq.hasm