[geos-commits] [SCM] GEOS branch main updated. 3f3a3e911f259b6fe76e18e05abe03c062d89aeb
git at osgeo.org
git at osgeo.org
Mon Jan 12 07:31:34 PST 2026
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 3f3a3e911f259b6fe76e18e05abe03c062d89aeb (commit)
from eb6121ae303477279d4a571c54ae9f0435e120bb (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 3f3a3e911f259b6fe76e18e05abe03c062d89aeb
Author: Daniel Baston <dbaston at gmail.com>
Date: Mon Jan 12 10:31:09 2026 -0500
Simplify: Preserve dimensions of empty geometries (#1357)
* DouglasPeuckerSimplifier: Preserve dimension of empty geometries
* TopologyPreservingSimplifier: Add test for preservation of empty geometry dims
diff --git a/include/geos/simplify/DouglasPeuckerSimplifier.h b/include/geos/simplify/DouglasPeuckerSimplifier.h
index 97fa32ca4..57fe5404e 100644
--- a/include/geos/simplify/DouglasPeuckerSimplifier.h
+++ b/include/geos/simplify/DouglasPeuckerSimplifier.h
@@ -68,7 +68,7 @@ public:
*/
void setDistanceTolerance(double tolerance);
- std::unique_ptr<geom::Geometry> getResultGeometry();
+ std::unique_ptr<geom::Geometry> getResultGeometry() const;
private:
diff --git a/src/simplify/DouglasPeuckerSimplifier.cpp b/src/simplify/DouglasPeuckerSimplifier.cpp
index 893d785a2..05b32b588 100644
--- a/src/simplify/DouglasPeuckerSimplifier.cpp
+++ b/src/simplify/DouglasPeuckerSimplifier.cpp
@@ -201,8 +201,12 @@ DouglasPeuckerSimplifier::setDistanceTolerance(double tol)
}
Geometry::Ptr
-DouglasPeuckerSimplifier::getResultGeometry()
+DouglasPeuckerSimplifier::getResultGeometry() const
{
+ if (inputGeom->isEmpty()) {
+ return inputGeom->clone();
+ }
+
DPTransformer t(distanceTolerance);
return t.transform(inputGeom);
diff --git a/tests/unit/simplify/DouglasPeuckerSimplifierTest.cpp b/tests/unit/simplify/DouglasPeuckerSimplifierTest.cpp
index ee3257a90..50c0bf308 100644
--- a/tests/unit/simplify/DouglasPeuckerSimplifierTest.cpp
+++ b/tests/unit/simplify/DouglasPeuckerSimplifierTest.cpp
@@ -37,7 +37,7 @@ struct test_dpsimp_data {
{}
void
- checkDP(const std::string& wkt, double tolerance, const std::string& wkt_expected)
+ checkDP(const std::string& wkt, double tolerance, const std::string& wkt_expected) const
{
GeomPtr g(wktreader.read(wkt));
GeomPtr simplified = DouglasPeuckerSimplifier::simplify(g.get(), tolerance);
@@ -49,7 +49,7 @@ struct test_dpsimp_data {
}
void
- checkDPNoChange(const std::string& wkt, double tolerance)
+ checkDPNoChange(const std::string& wkt, double tolerance) const
{
checkDP(wkt, tolerance, wkt);
}
@@ -382,4 +382,24 @@ void object::test<23>()
"POLYGON ZM ((2 0 10 9, 2 2 15 11, 0 2 20 13, 0 0 25 15, 2 0 10 9))");
}
+template<>
+template<>
+void object::test<24>()
+{
+ set_test_name("simplification preserves dimensions of empty geometries");
+
+ const std::vector<std::string> geomTypes{"POINT", "LINESTRING", "POLYGON"};
+ const std::vector<std::string> dimensions{"", "Z", "M", "ZM"};
+ const std::vector<std::string> mods{"", "MULTI"};
+
+ for (const auto& geomType : geomTypes) {
+ for (const auto& dimension: dimensions) {
+ for (const auto& mod: mods) {
+ std::string wkt = mod + geomType + " " + dimension + " EMPTY";
+ checkDP(wkt, 0, wkt);
+ }
+ }
+ }
+}
+
} // namespace tut
diff --git a/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp b/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
index d8ab8d615..651627b05 100644
--- a/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
+++ b/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
@@ -34,17 +34,17 @@ struct test_tpsimp_data {
}
void
- checkTPS(const std::string& wkt, double tolerance, const std::string& wkt_expected)
+ checkTPS(const std::string& wkt, double tolerance, const std::string& wkt_expected) const
{
GeomPtr g(wktreader.read(wkt));
GeomPtr simplified = TopologyPreservingSimplifier::simplify(g.get(), tolerance);
GeomPtr exp(wktreader.read(wkt_expected));
- ensure_equals_geometry(exp.get(), simplified.get(),0.00001);
+ ensure_equals_geometry_xyzm(exp.get(), simplified.get(),0.00001);
ensure("Simplified geometry is invalid!", simplified->isValid());
}
void
- checkTPSNoChange(const std::string& wkt, double tolerance)
+ checkTPSNoChange(const std::string& wkt, double tolerance) const
{
checkTPS(wkt, tolerance, wkt);
}
@@ -453,4 +453,24 @@ void object::test<35>()
"MULTIPOLYGON (((689.300102 5733.615673, 689.46186 5733.617409, 689.458981 5733.646089, 689.300102 5733.615673)), ((689.488158 5733.746304, 689.23796 5733.680098, 689.253227 5733.613915, 689.467162 5733.67151, 689.679568 5733.588383, 689.488158 5733.746304)))");
}
+template<>
+template<>
+void object::test<36>()
+{
+ set_test_name("simplification preserves dimensions of empty geometries");
+
+ const std::vector<std::string> geomTypes{"POINT", "LINESTRING", "POLYGON"};
+ const std::vector<std::string> dimensions{"", "Z", "M", "ZM"};
+ const std::vector<std::string> mods{"", "MULTI"};
+
+ for (const auto& geomType : geomTypes) {
+ for (const auto& dimension: dimensions) {
+ for (const auto& mod: mods) {
+ std::string wkt = mod + geomType + " " + dimension + " EMPTY";
+ checkTPSNoChange(wkt, 0);
+ }
+ }
+ }
+}
+
} // namespace tut
-----------------------------------------------------------------------
Summary of changes:
include/geos/simplify/DouglasPeuckerSimplifier.h | 2 +-
src/simplify/DouglasPeuckerSimplifier.cpp | 6 ++++-
.../unit/simplify/DouglasPeuckerSimplifierTest.cpp | 24 ++++++++++++++++++--
.../simplify/TopologyPreservingSimplifierTest.cpp | 26 +++++++++++++++++++---
4 files changed, 51 insertions(+), 7 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list