Skip to content

Commit

Permalink
Add simplifyDP and simplifyTP to XML tester. Closes GH-1010
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Dec 8, 2023
1 parent 725f297 commit c49ac84
Show file tree
Hide file tree
Showing 2 changed files with 268 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/xmltester/XMLTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 << ":";
Expand Down
231 changes: 231 additions & 0 deletions tests/xmltester/tests/general/TestSimplify.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit c49ac84

Please sign in to comment.