diff --git a/NEWS.md b/NEWS.md index b605e1a622..1f555c9cb7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ - Fixes/Improvements: - Fix ConcaveHullOfPolygons nested shell handling (GH-1169, Martin Davis) - Fix RelateNG for computing IM for empty-nonempty cases (Martin Davis) + - Fix LineString->getPoint(n) for M geometries (GH-1191, @hsieyuan) ## Changes in 3.13.0 2024-09-06 diff --git a/src/geom/SimpleCurve.cpp b/src/geom/SimpleCurve.cpp index be9b50b443..dcbaf7114b 100644 --- a/src/geom/SimpleCurve.cpp +++ b/src/geom/SimpleCurve.cpp @@ -251,7 +251,16 @@ SimpleCurve::getPointN(std::size_t n) const { assert(getFactory()); assert(points.get()); - return std::unique_ptr(getFactory()->createPoint(points->getAt(n))); + if (hasM() || hasZ()) { + CoordinateXYZM c; + points->getAt(n, c); + return getFactory()->createPoint(c); + } + else { + CoordinateXY c; + points->getAt(n, c); + return getFactory()->createPoint(c); + } } std::unique_ptr diff --git a/tests/unit/geom/LineStringTest.cpp b/tests/unit/geom/LineStringTest.cpp index 26a8756bfb..1e1136fce5 100644 --- a/tests/unit/geom/LineStringTest.cpp +++ b/tests/unit/geom/LineStringTest.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ struct test_linestring_data { geos::geom::PrecisionModel pm_; geos::geom::GeometryFactory::Ptr factory_; geos::io::WKTReader reader_; + geos::io::WKTWriter writer_; std::unique_ptr empty_line_; std::unique_ptr line_; @@ -588,5 +590,23 @@ void object::test<32> ensure(!line_->hasDimension(geos::geom::Dimension::A)); } + +// https://github.com/libgeos/geos/issues/1191 +// line->getPoint(n) loses M dimension +template<> +template<> +void object::test<33> +() +{ + auto geom = reader_.read("LINESTRING M (0 1 2, 10 11 12, 20 21 22)"); + ensure(geom != nullptr); + geos::geom::LineString *line = static_cast(geom.get()); + ensure_equals(line->getCoordinateDimension(), 3); + auto pt = line->getPointN(2); + auto out = writer_.write(*pt); + ensure_equals(out, "POINT M (20 21 22)"); +} + + } // namespace tut