[geos-commits] [SCM] GEOS branch main updated. c49ac84dd18de4c7313056771c4a1d40b1f483c5

git at osgeo.org git at osgeo.org
Fri Dec 8 11:16:33 PST 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  c49ac84dd18de4c7313056771c4a1d40b1f483c5 (commit)
      from  725f2979173cc5a089bb21b0d8a8cf8e6bbb83c9 (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 c49ac84dd18de4c7313056771c4a1d40b1f483c5
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Fri Dec 8 10:05:22 2023 -0800

    Add simplifyDP and simplifyTP to XML tester. Closes GH-1010

diff --git a/tests/xmltester/XMLTester.cpp b/tests/xmltester/XMLTester.cpp
index 4bd67edef..5013e8bf9 100644
--- a/tests/xmltester/XMLTester.cpp
+++ b/tests/xmltester/XMLTester.cpp
@@ -45,6 +45,8 @@
 #include <geos/operation/polygonize/BuildArea.h>
 #include <geos/operation/valid/MakeValid.h>
 #include <geos/precision/MinimumClearance.h>
+#include <geos/simplify/TopologyPreservingSimplifier.h>
+#include <geos/simplify/DouglasPeuckerSimplifier.h>
 #include <geos/util.h>
 #include <geos/util/Interrupt.h>
 #include <geos/io/WKBReader.h>
@@ -2193,6 +2195,41 @@ XMLTester::parseTest(const tinyxml2::XMLNode* node)
             }
         }
 
+        else if(opName == "simplifydp" || opName == "simplifytp")
+        {
+            geom::Geometry* p_gT = gA;
+            if((opArg1 == "B" || opArg1 == "b") && gB) {
+                p_gT = gB;
+            }
+
+            GeomPtr gRes(parseGeometry(opRes, "expected"));
+            gRes->normalize();
+
+            profile.start();
+
+            GeomPtr gRealRes;
+            double tolerance = std::atof(opArg2.c_str());
+
+            if (opName == "simplifydp") {
+                gRealRes = geos::simplify::DouglasPeuckerSimplifier::simplify(p_gT, tolerance);
+            }
+            else {
+                gRealRes = geos::simplify::TopologyPreservingSimplifier::simplify(p_gT, tolerance);
+            }
+
+            profile.stop();
+            gRealRes->normalize();
+
+            actual_result = printGeom(gRealRes.get());
+            expected_result = printGeom(gRes.get());
+
+            success = gRealRes.get()->equalsExact(gRes.get(), 0.000001) ? 1 : 0;
+
+            if(testValidOutput) {
+                success &= int(testValid(gRealRes.get(), "result"));
+            }
+        }
+
         else {
             std::cerr << *curr_file << ":";
             std::cerr << " case" << caseCount << ":";
diff --git a/tests/xmltester/tests/general/TestSimplify.xml b/tests/xmltester/tests/general/TestSimplify.xml
new file mode 100644
index 000000000..5b4dd0a6a
--- /dev/null
+++ b/tests/xmltester/tests/general/TestSimplify.xml
@@ -0,0 +1,231 @@
+<run>
+  <desc>Test cases for DouglasPeuckerSimplifier and TopologyPreservingSimplifier</desc>
+  <precisionModel type="FLOATING"/>
+
+<case>
+  <desc>P - point</desc>
+  <a> POINT(10 10) 
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="1"> 
+      POINT(10 10)
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="1"> 
+      POINT(10 10)
+    </op> </test>
+</case>
+
+<case>
+  <desc>mP - point with EMPTY</desc>
+  <a> MULTIPOINT(EMPTY, (10 10), (20 20))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="1"> 
+      MULTIPOINT((10 10), (20 20))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="1"> 
+      MULTIPOINT((10 10), (20 20))
+    </op> </test>
+</case>
+
+<case>
+  <desc>L - empty line</desc>
+  <a> LINESTRING EMPTY 
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      LINESTRING EMPTY 
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      LINESTRING EMPTY 
+    </op> </test>
+</case>
+
+<case>
+  <desc>L - line</desc>
+  <a> LINESTRING (10 10, 20 21, 30 30) 
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      LINESTRING (10 10, 30 30)
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      LINESTRING (10 10, 30 30)
+    </op> </test>
+</case>
+
+<case>
+  <desc>L - short line</desc>
+  <a> LINESTRING (0 5, 1 5, 2 5, 5 5)
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      LINESTRING (0 5, 5 5)
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      LINESTRING (0 5, 5 5)
+    </op> </test>
+</case>
+
+<case>
+  <desc>mL - lines with constrained topology</desc>
+  <a> MULTILINESTRING ((10 60, 39 50, 70 60, 90 50), (35 55, 46 55), (65 55, 75 55), (10 40, 40 30, 70 40, 90 30)) 
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      MULTILINESTRING ((10 60, 90 50), (35 55, 46 55), (65 55, 75 55), (10 40, 90 30))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      MULTILINESTRING ((10 60, 39 50, 70 60, 90 50), (35 55, 46 55), (65 55, 75 55), (10 40, 90 30))
+    </op> </test>
+</case>
+
+<case>
+  <desc>mL - lines with EMPTY</desc>
+  <a> MULTILINESTRING(EMPTY, (10 10, 20 21, 30 30), (10 10, 10 30, 30 30)) 
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      MULTILINESTRING ((10 10, 30 30), (10 10, 10 30, 30 30))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      MULTILINESTRING ((10 10, 30 30), (10 10, 10 30, 30 30))
+    </op> </test>
+</case>
+
+<case>
+  <desc>A - polygon with flat endpoint</desc>
+  <a> POLYGON ((5 1, 1 1, 1 9, 9 9, 9 1, 5 1))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="1"> 
+      POLYGON ((1 1, 1 9, 9 9, 9 1, 1 1))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="1"> 
+      POLYGON ((1 1, 1 9, 9 9, 9 1, 1 1))
+    </op> </test>
+</case>
+
+<case>
+  <desc>A - polygon with multiple flat segments around endpoint</desc>
+  <a> POLYGON ((5 5, 7 5, 9 5, 9 1, 1 1, 1 5, 3 5, 5 5))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="1"> 
+      POLYGON ((9 5, 9 1, 1 1, 1 5, 9 5))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="1"> 
+      POLYGON ((9 5, 9 1, 1 1, 1 5, 9 5))
+    </op> </test>
+</case>
+
+<case>
+  <desc>A - polygon simplification</desc>
+  <a> POLYGON ((10 10, 10 90, 60.5 87, 90 90, 90 10, 12 12, 10 10))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      POLYGON ((10 10, 10 90, 90 90, 90 10, 10 10))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      POLYGON ((10 10, 10 90, 90 90, 90 10, 10 10))
+    </op> </test>
+</case>
+
+<case>
+  <desc>A - polygon with edge collapse.
+    DP: polygon is split
+    TP: unchanged
+    </desc>
+  <a> POLYGON ((40 240, 160 241, 280 240, 280 160, 160 240, 40 140, 40 240))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="1"> 
+      MULTIPOLYGON (((40 240, 160 240, 40 140, 40 240)), ((160 240, 280 240, 280 160, 160 240)))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="1"> 
+      POLYGON ((40 240, 160 241, 280 240, 280 160, 160 240, 40 140, 40 240))
+    </op> </test>
+</case>
+
+<case>
+  <desc>A - polygon collapse for DP</desc>
+  <a> POLYGON ((5 2, 9 1, 1 1, 5 2))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="1"> 
+      POLYGON EMPTY
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="1"> 
+      POLYGON ((5 2, 9 1, 1 1, 5 2))
+    </op> </test>
+</case>
+
+<case>
+  <desc>A - polygon with touching hole</desc>
+  <a> POLYGON ((10 10, 10 90, 90 90, 90 10, 10 10), (80 20, 20 20, 20 80, 50 90, 80 80, 80 20))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      POLYGON ((10 10, 10 90, 90 90, 90 10, 10 10), (80 20, 20 20, 20 80, 80 80, 80 20))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      POLYGON ((10 10, 10 90, 90 90, 90 10, 10 10), (80 20, 20 20, 20 80, 80 80, 80 20))
+    </op> </test>
+</case>
+
+<case>
+  <desc>A - polygon with large hole near edge.
+    DP: simplified and fixed
+    TP: unchanged
+  </desc>
+  <a> POLYGON ((10 10, 10 80, 50 90, 90 80, 90 10, 10 10), (80 20, 20 20, 50 90, 80 20))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      POLYGON ((10 10, 10 80, 45.714285714285715 80, 20 20, 80 20, 54.285714285714285 80, 90 80, 90 10, 10 10))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      POLYGON ((10 10, 10 80, 50 90, 90 80, 90 10, 10 10), (80 20, 20 20, 50 90, 80 20))
+    </op> </test>
+</case>
+
+<case>
+  <desc>A - polygon with small hole near simplified edge
+    DP: hole is remmoved
+    TP: hole is preserved
+  </desc>
+  <a> POLYGON ((10 10, 10 80, 50 90, 90 80, 90 10, 10 10), (70 81, 30 81, 50 90, 70 81))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      POLYGON ((10 10, 10 80, 90 80, 90 10, 10 10))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      POLYGON ((10 10, 10 80, 50 90, 90 80, 90 10, 10 10), (70 81, 30 81, 50 90, 70 81))
+    </op> </test>
+</case>
+
+<case>
+  <desc>mA - multipolygon with EMPTY</desc>
+  <a> MULTIPOLYGON (EMPTY, ((10 90, 10 10, 90 10, 50 60, 10 90)), ((70 90, 90 90, 90 70, 70 70, 70 90)))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      MULTIPOLYGON (((10 90, 10 10, 90 10, 10 90)), ((70 90, 90 90, 90 70, 70 70, 70 90)))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      MULTIPOLYGON (((10 90, 10 10, 90 10, 50 60, 10 90)), ((70 90, 90 90, 90 70, 70 70, 70 90)))
+    </op> </test>
+</case>
+
+<case>
+  <desc>mA - multipolygon with small element removed</desc>
+  <a> MULTIPOLYGON (((10 90, 10 10, 40 40, 90 10, 47 57, 10 90)), ((90 90, 90 85, 85 85, 85 90, 90 90)))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      POLYGON ((10 90, 10 10, 40 40, 90 10, 10 90))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      MULTIPOLYGON (((10 90, 10 10, 40 40, 90 10, 10 90)), ((85 90, 90 85, 85 85, 85 90)))
+    </op> </test>
+</case>
+
+<case>
+  <desc>GC - geometry collection</desc>
+  <a> GEOMETRYCOLLECTION (POLYGON ((10 90, 10 10, 40 40, 90 10, 47 57, 10 90)), LINESTRING (30 90, 65 65, 90 30), MULTIPOINT ((80 90), (90 90)))
+    </a>
+  <test> <op name="simplifyDP" arg1="A" arg2="10"> 
+      GEOMETRYCOLLECTION (POLYGON ((10 90, 10 10, 40 40, 90 10, 10 90)), LINESTRING (30 90, 90 30), MULTIPOINT ((80 90), (90 90)))
+    </op> </test>
+  <test> <op name="simplifyTP" arg1="A" arg2="10"> 
+      GEOMETRYCOLLECTION (POLYGON ((10 90, 10 10, 40 40, 90 10, 10 90)), LINESTRING (30 90, 90 30), MULTIPOINT ((80 90), (90 90)))
+    </op> </test>
+</case>
+
+
+</run>

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

Summary of changes:
 tests/xmltester/XMLTester.cpp                  |  37 ++++
 tests/xmltester/tests/general/TestSimplify.xml | 231 +++++++++++++++++++++++++
 2 files changed, 268 insertions(+)
 create mode 100644 tests/xmltester/tests/general/TestSimplify.xml


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list