Skip to content

Commit

Permalink
Fix LineString->getPoint(n) for M geometries (closes GH-1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Nov 15, 2024
1 parent e696cc4 commit fa08715
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/geom/SimpleCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,16 @@ SimpleCurve::getPointN(std::size_t n) const
{
assert(getFactory());
assert(points.get());
return std::unique_ptr<Point>(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<Point>
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/geom/LineStringTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/io/WKTReader.h>
#include <geos/io/WKTWriter.h>
#include <geos/util/GEOSException.h>
#include <geos/util/IllegalArgumentException.h>
#include <geos/constants.h>
Expand All @@ -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<geos::geom::LineString> empty_line_;
std::unique_ptr<geos::geom::LineString> line_;
Expand Down Expand Up @@ -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<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)");
}


} // namespace tut

0 comments on commit fa08715

Please # to comment.