Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CPMAddPackage(
"EXPECTED_BUILD_TESTS OFF"
"EXPECTED_BUILD_PACKAGE_DEB OFF")
CPMAddPackage(
URI "gh:Klebert-Engineering/simfil#byte-array"
URI "gh:Klebert-Engineering/simfil#v0.6.3"
OPTIONS
"SIMFIL_WITH_MODEL_JSON ON"
"SIMFIL_SHARED OFF")
Expand Down
61 changes: 50 additions & 11 deletions libs/geojsonsource/src/geojsonsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,57 @@ void GeoJsonSource::fill(const mapget::TileFeatureLayer::Ptr& tile)
auto feature = tile->newFeature(featureTypeName, {{"featureIndex", featureId}});
featureId++;

// Get geometry data
auto geometry = feature_data["geometry"];
if (geometry["type"] == "Point") {
auto coordinates = geometry["coordinates"];
feature->addPoint({coordinates[0], coordinates[1]});
}
else if (geometry["type"] == "LineString") {
auto line = feature->geom()->newGeometry(GeomType::Line, 2);
for (auto& coordinates : geometry["coordinates"]) {
line->append({coordinates[0], coordinates[1]});
// Parse geometry data (recursive lambda to support GeometryCollection)
std::function<void(nlohmann::json const&)> addGeometry;
addGeometry = [&](nlohmann::json const& geom) {
if (!geom.is_object() || !geom.contains("type"))
return;
auto const type = geom["type"].get<std::string>();
if (type == "Point") {
auto const& c = geom["coordinates"];
feature->addPoint({c[0], c[1]});
}
}
else if (type == "MultiPoint") {
auto points = feature->geom()->newGeometry(GeomType::Points, geom["coordinates"].size());
for (auto const& c : geom["coordinates"])
points->append({c[0], c[1]});
}
else if (type == "LineString") {
auto line = feature->geom()->newGeometry(GeomType::Line, geom["coordinates"].size());
for (auto const& c : geom["coordinates"])
line->append({c[0], c[1]});
}
else if (type == "MultiLineString") {
for (auto const& coords : geom["coordinates"]) {
auto line = feature->geom()->newGeometry(GeomType::Line, coords.size());
for (auto const& c : coords)
line->append({c[0], c[1]});
}
}
else if (type == "Polygon") {
if (!geom["coordinates"].empty()) {
auto const& ring = geom["coordinates"][0];
auto poly = feature->geom()->newGeometry(GeomType::Polygon, ring.size());
for (auto const& c : ring)
poly->append({c[0], c[1]});
}
}
else if (type == "MultiPolygon") {
for (auto const& polygon : geom["coordinates"]) {
if (!polygon.empty()) {
auto const& ring = polygon[0];
auto poly = feature->geom()->newGeometry(GeomType::Polygon, ring.size());
for (auto const& c : ring)
poly->append({c[0], c[1]});
}
}
}
else if (type == "GeometryCollection") {
for (auto const& child : geom["geometries"])
addGeometry(child);
}
};
addGeometry(feature_data["geometry"]);

// Add top-level properties as attributes
for (auto& property : feature_data["properties"].items()) {
Expand Down
1 change: 1 addition & 0 deletions libs/http-service/src/http-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ LayerTilesRequest::Ptr HttpClient::request(const LayerTilesRequest::Ptr& request
httpReq->setMethod(drogon::Post);
httpReq->setPath("/tiles");
httpReq->setContentTypeCode(drogon::CT_APPLICATION_JSON);
httpReq->addHeader("Accept", "application/binary");
httpReq->setBody(std::move(body));
applyHeaders(httpReq, impl_->headers_);

Expand Down
9 changes: 8 additions & 1 deletion libs/pymapget/binding/py-layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,12 @@ void bindTileLayer(py::module_& m)
{ return self.toJson().dump(); },
R"pbdoc(
Convert this tile to a GeoJSON feature collection.
)pbdoc");
)pbdoc")
.def("__len__", [](TileFeatureLayer const& self) { return self.size(); })
.def("__getitem__", [](TileFeatureLayer const& self, int64_t i) {
auto sz = (int64_t)self.size();
if (i < 0) i += sz;
if (i < 0 || i >= sz) throw py::index_error();
return BoundFeature(self.at((size_t)i));
});
}
Loading
Loading