[geos-commits] [SCM] GEOS branch main updated. 7d20b1772d57c8eba1c12902c812dae9bf58307b

git at osgeo.org git at osgeo.org
Wed Apr 19 19:54:27 PDT 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, main has been updated
       via  7d20b1772d57c8eba1c12902c812dae9bf58307b (commit)
      from  f526c4f972f9a0caeecbf282698184933b2c42e4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7d20b1772d57c8eba1c12902c812dae9bf58307b
Author: Mike Taves <mwtoews at gmail.com>
Date:   Thu Apr 20 14:54:00 2023 +1200

    Change WKTWriter Old3D option to only add "M" for XYM (#871)

diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index ea370ad84..2179a4f2a 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -5410,8 +5410,9 @@ extern int  GEOS_DLL GEOSWKTWriter_getOutputDimension(GEOSWKTWriter *writer);
 
 /**
 * Sets the format for 3D outputs. The "old 3D" format does not
-* include a dimensionality tag, eg. "POINT(1 2 3)" while the new (ISO)
-* format does includes a tag, eg "POINT Z (1 2 3)".
+* include a Z dimension tag, e.g. "POINT (1 2 3)", except for XYM,
+* e.g. "POINT M (1 2 3)". Geometries with XYZM coordinates do not add
+* any dimensionality tags, e.g. "POINT (1 2 3 4)".
 * \param writer A \ref GEOSWKTWriter.
 * \param useOld3D True to use the old format, false is the default.
 *
diff --git a/src/io/WKTWriter.cpp b/src/io/WKTWriter.cpp
index 680efd37b..39740894f 100644
--- a/src/io/WKTWriter.cpp
+++ b/src/io/WKTWriter.cpp
@@ -252,7 +252,10 @@ WKTWriter::appendGeometryTaggedText(const Geometry& geometry,
 void
 WKTWriter::appendOrdinateText(OrdinateSet outputOrdinates, Writer& writer) const
 {
-    if (old3D && !outputOrdinates.hasM()) {
+    if (old3D) {
+        if (!outputOrdinates.hasZ() && outputOrdinates.hasM()) {
+            writer.write("M ");
+        }
         return;
     }
 
diff --git a/tests/unit/io/WKTWriterTest.cpp b/tests/unit/io/WKTWriterTest.cpp
index 45859f14c..d12227232 100644
--- a/tests/unit/io/WKTWriterTest.cpp
+++ b/tests/unit/io/WKTWriterTest.cpp
@@ -260,11 +260,21 @@ void object::test<9>
     ensure_equals(wktwriter.write(*ls),
                   std::string("LINESTRING ZM (1 2 3 4, 5 6 7 8)"));
 
+    wktwriter.setOld3D(true);
+    ensure_equals(wktwriter.write(*ls),
+                  std::string("LINESTRING (1 2 3 4, 5 6 7 8)"));
+
+
     // If only 3 dimensions are allowed we pick Z instead of M
+    wktwriter.setOld3D(false);
     wktwriter.setOutputDimension(3);
 
     ensure_equals(wktwriter.write(*ls),
                   std::string("LINESTRING Z (1 2 3, 5 6 7)"));
+
+    wktwriter.setOld3D(true);
+    ensure_equals(wktwriter.write(*ls),
+                  std::string("LINESTRING (1 2 3, 5 6 7)"));
 }
 
 // Test writing XYM
@@ -284,6 +294,11 @@ void object::test<10>
 
     ensure_equals(wktwriter.write(*ls),
                   std::string("LINESTRING M (1 2 3, 4 5 6)"));
+
+    // Same output
+    wktwriter.setOld3D(true);
+    ensure_equals(wktwriter.write(*ls),
+                  std::string("LINESTRING M (1 2 3, 4 5 6)"));
 }
 
 // Test writing XY
@@ -302,6 +317,11 @@ void object::test<11>
 
     ensure_equals(wktwriter.write(*ls),
                   std::string("LINESTRING (1 2, 3 4)"));
+
+    // Same output
+    wktwriter.setOld3D(true);
+    ensure_equals(wktwriter.write(*ls),
+                  std::string("LINESTRING (1 2, 3 4)"));
 }
 
 // Test writing 3D/4D EMPTY geometries

-----------------------------------------------------------------------

Summary of changes:
 capi/geos_c.h.in                |  5 +++--
 src/io/WKTWriter.cpp            |  5 ++++-
 tests/unit/io/WKTWriterTest.cpp | 20 ++++++++++++++++++++
 3 files changed, 27 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list