Skip to content

Commit

Permalink
FIX: 3D coordinates handling of GeoJSON MultiLineString (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreilles committed Aug 22, 2024
1 parent 937cf5f commit 654ad34
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/io/GeoJSONReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ std::unique_ptr<geom::MultiLineString> 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)));
}
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/io/GeoJSONReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,28 @@ void object::test<38>
ensure_equals(static_cast<size_t>(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<size_t>(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<size_t>(geom->getCoordinateDimension()), 3u);
}

}

0 comments on commit 654ad34

Please sign in to comment.