diff --git a/src/coverage/CoverageSimplifier.cpp b/src/coverage/CoverageSimplifier.cpp index 73b5a5e442..335b107597 100644 --- a/src/coverage/CoverageSimplifier.cpp +++ b/src/coverage/CoverageSimplifier.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using geos::geom::Geometry; @@ -83,7 +84,12 @@ CoverageSimplifier::simplifyInner( CoverageSimplifier::CoverageSimplifier(std::vector& coverage) : m_input(coverage) , m_geomFactory(coverage.empty() ? nullptr : coverage[0]->getFactory()) - {} + { + for (const Geometry* g: m_input) { + if (!g->isPolygonal()) + throw util::IllegalArgumentException("Argument is not a non-polygonal"); + } + } /* public */ std::vector> diff --git a/tests/unit/coverage/CoverageSimplifierTest.cpp b/tests/unit/coverage/CoverageSimplifierTest.cpp index 61e79f54ec..94534544af 100644 --- a/tests/unit/coverage/CoverageSimplifierTest.cpp +++ b/tests/unit/coverage/CoverageSimplifierTest.cpp @@ -431,7 +431,7 @@ void object::test<24> () "POLYGON EMPTY", "POLYGON EMPTY" }) ); - } +} // testOneEmpty template<> @@ -446,7 +446,7 @@ void object::test<25> () "POLYGON ((1 9, 9 9, 9 1, 1 1, 1 9))", "POLYGON EMPTY" }) ); - } +} // testEmptyHole() template<> @@ -461,6 +461,26 @@ void object::test<26> () "POLYGON ((1 9, 9 9, 9 1, 1 1, 1 9), EMPTY)", "POLYGON EMPTY" }) ); - } +} + +// Test non-polygon inputs (GH-1031) +template<> +template<> +void object::test<30> () +{ + auto input = readArray({ + "MULTILINESTRING ((200 100, 100 100, 200 200), (200 200, 200 100), (200 200, 300 100, 200 100))" + }); + try { + std::vector> result = + CoverageSimplifier::simplify(input, 10); + } + catch (geos::util::IllegalArgumentException& iae) { + ensure("caught IllegalArgumentException", true); + return; + } + ensure("did not throw IllegalArgumentException", false); +} + } // namespace tut