Skip to content

Commit

Permalink
faster parsing of points
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmermannubique committed Jan 31, 2024
1 parent 9cd9f8c commit e744ce5
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions shared/src/map/layers/tiled/vector/geojson/GeoJsonParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,30 @@ class GeoJsonParser {
return points;
}

UUIDGenerator generator;

std::shared_ptr<GeoJson> geoJson = std::make_shared<GeoJson>();
for (const auto &feature: geojson["features"]) {
if (!feature["geometry"].is_object() ||
!feature["geometry"]["type"].is_string() ||
!feature["geometry"]["coordinates"].is_array()) {
const auto &geometry = feature["geometry"];

if (!geometry.is_object()) {
LogError <<= "Geojson feature is not valid";
continue;
}

const auto &geometryType = feature["geometry"]["type"];
const auto &coordinates = feature["geometry"]["coordinates"];
std::shared_ptr<GeoJsonGeometry> geometry;
vtzero::GeomType geomType;
if (geometryType == "Point") {
geometry = parsePoint(coordinates);
geomType = vtzero::GeomType::POINT;
const auto &geometryType = geometry["type"];
if (!geometryType.is_string() || geometryType != "Point") {
continue;
}

if(!geometry || geometry->coordinates.size() != 1 || geometry->coordinates.front().size() != 1) {
if(!feature["id"].is_string()) {
continue;
}

if(!feature["id"].is_string()) {
const auto &coordinates = geometry["coordinates"];

if(!coordinates.is_array()) {
continue;
}

points.emplace_back(geometry->coordinates.front().front(), GeoJsonParser::getFeatureInfo(feature["properties"], feature["id"].get<std::string>()));
points.emplace_back(getPoint(coordinates), GeoJsonParser::getFeatureInfo(feature["properties"], feature["id"].get<std::string>()));
}

return points;
Expand Down Expand Up @@ -222,6 +217,10 @@ class GeoJsonParser {
return geometry;
}

static Coord getPoint(const nlohmann::json &coordinates) {
return parseCoordinate(coordinates);
}

static std::shared_ptr<GeoJsonGeometry> parseMultiPoint(const nlohmann::json &coordinates) {
auto geometry = std::make_shared<GeoJsonGeometry>();
for (const auto &coord : coordinates) {
Expand Down

0 comments on commit e744ce5

Please sign in to comment.