diff --git a/src/io/GeoJSONReader.cpp b/src/io/GeoJSONReader.cpp index fe53b63c7..0f0817e32 100644 --- a/src/io/GeoJSONReader.cpp +++ b/src/io/GeoJSONReader.cpp @@ -317,7 +317,7 @@ std::unique_ptr GeoJSONReader::readMultiLineString( coordinates->reserve(coords.size()); for (const auto& coord : coords) { const geom::Coordinate& c = readCoordinate(coord); - coordinates->add(geom::Coordinate{c.x, c.y}); + coordinates->add(c); } lines.push_back(geometryFactory.createLineString(std::move(coordinates))); } diff --git a/tests/unit/io/GeoJSONReaderTest.cpp b/tests/unit/io/GeoJSONReaderTest.cpp index 2a8e7c030..c5ff39db8 100644 --- a/tests/unit/io/GeoJSONReaderTest.cpp +++ b/tests/unit/io/GeoJSONReaderTest.cpp @@ -596,4 +596,28 @@ void object::test<38> ensure_equals(static_cast(geom->getCoordinateDimension()), 3u); } +// Read a GeoJSON MultiLineString with three dimensions +template<> +template<> +void object::test<39> +() +{ + std::string geojson { "{\"type\":\"MultiLineString\",\"coordinates\":[[[30,10,1],[40,40,2],[20,40,4],[10,20,8],[30,10,16]]]}" }; + GeomPtr geom(geojsonreader.read(geojson)); + ensure_equals(geom->toText(), "MULTILINESTRING Z ((30 10 1, 40 40 2, 20 40 4, 10 20 8, 30 10 16))"); + ensure_equals(static_cast(geom->getCoordinateDimension()), 3u); +} + +// Read a GeoJSON MultiLineString with mixed dimensions +template<> +template<> +void object::test<40> +() +{ + std::string geojson { "{\"type\":\"MultiLineString\",\"coordinates\":[[[30,10],[40,40,2],[20,40],[10,20,8],[30,10]]]}" }; + GeomPtr geom(geojsonreader.read(geojson)); + ensure_equals(geom->toText(), "MULTILINESTRING Z ((30 10 NaN, 40 40 2, 20 40 NaN, 10 20 8, 30 10 NaN))"); + ensure_equals(static_cast(geom->getCoordinateDimension()), 3u); +} + }