[geos-commits] [SCM] GEOS branch main updated. 1ee3b0be4e860b0b76e857075b4f51de01be581b

git at osgeo.org git at osgeo.org
Fri Nov 15 14:36:21 PST 2024


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  1ee3b0be4e860b0b76e857075b4f51de01be581b (commit)
      from  286f189e2b3d07d8dc76cca8dd39465550b69bad (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 1ee3b0be4e860b0b76e857075b4f51de01be581b
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Fri Nov 15 14:35:25 2024 -0800

    Fix line->getPoint(n) error with m coordinates GH-1191

diff --git a/src/geom/SimpleCurve.cpp b/src/geom/SimpleCurve.cpp
index be9b50b44..6bb589257 100644
--- a/src/geom/SimpleCurve.cpp
+++ b/src/geom/SimpleCurve.cpp
@@ -251,7 +251,18 @@ SimpleCurve::getPointN(std::size_t n) const
 {
     assert(getFactory());
     assert(points.get());
-    return std::unique_ptr<Point>(getFactory()->createPoint(points->getAt(n)));
+
+    std::unique_ptr<Point> point;
+    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<Point>
diff --git a/tests/unit/geom/LineStringTest.cpp b/tests/unit/geom/LineStringTest.cpp
index 26a8756bf..06e1dfa0c 100644
--- a/tests/unit/geom/LineStringTest.cpp
+++ b/tests/unit/geom/LineStringTest.cpp
@@ -35,6 +35,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<geos::geom::LineString> empty_line_;
     std::unique_ptr<geos::geom::LineString> line_;
@@ -588,5 +589,50 @@ 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<LineString*>(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)");
+}
+
+template<>
+template<>
+void object::test<34>
+()
+{
+    auto geom = reader_.read("LINESTRING Z (0 1 2, 10 11 12, 20 21 22)");
+    ensure(geom != nullptr);
+    geos::geom::LineString *line = static_cast<LineString*>(geom.get());
+    ensure_equals(line->getCoordinateDimension(), 3);
+    auto pt = line->getPointN(2);
+    auto out = writer_.write(*pt);
+    ensure_equals(out, "POINT Z (20 21 22)");
+}
+
+template<>
+template<>
+void object::test<35>
+()
+{
+    auto geom = reader_.read("LINESTRING ZM (0 1 2 3, 10 11 12 13, 20 21 22 23)");
+    ensure(geom != nullptr);
+    geos::geom::LineString *line = static_cast<LineString*>(geom.get());
+    ensure_equals(line->getCoordinateDimension(), 4);
+    auto pt = line->getPointN(2);
+    auto out = writer_.write(*pt);
+    ensure_equals(out, "POINT ZM (20 21 22 23)");
+}
+
+
 } // namespace tut
 

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

Summary of changes:
 src/geom/SimpleCurve.cpp           | 13 ++++++++++-
 tests/unit/geom/LineStringTest.cpp | 46 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list