From 69b5637447fe09b6e9b4fc40dcd303aadf1678a8 Mon Sep 17 00:00:00 2001 From: Hugo Ledoux <h.ledoux@tudelft.nl> Date: Mon, 2 Oct 2017 17:33:47 +0200 Subject: [PATCH] all attributes from input used in CityJSON output --- Building.cpp | 1 + Forest.cpp | 2 ++ Road.cpp | 2 ++ Separation.cpp | 2 ++ Terrain.cpp | 2 ++ TopoFeature.cpp | 9 +++++++++ TopoFeature.h | 1 + Water.cpp | 2 ++ 8 files changed, 21 insertions(+) diff --git a/Building.cpp b/Building.cpp index 44fc1cb0..7d1ab72c 100644 --- a/Building.cpp +++ b/Building.cpp @@ -174,6 +174,7 @@ void Building::get_cityjson(nlohmann::json& j, std::unordered_map<std::string, u nlohmann::json b; b["type"] = "Building"; b["attributes"]; + get_cityjson_attributes(b, _attributes); float hbase = z_to_float(this->get_height_base()); float h = z_to_float(this->get_height()); b["attributes"]["min-height-surface"] = hbase; diff --git a/Forest.cpp b/Forest.cpp index b373d134..a90ca0a9 100644 --- a/Forest.cpp +++ b/Forest.cpp @@ -66,6 +66,8 @@ bool Forest::lift() { void Forest::get_cityjson(nlohmann::json& j, std::unordered_map<std::string,unsigned long> &dPts) { nlohmann::json f; f["type"] = "PlantCover"; + f["attributes"]; + get_cityjson_attributes(f, _attributes); nlohmann::json g; this->get_cityjson_geom(g, dPts); f["geometry"].push_back(g); diff --git a/Road.cpp b/Road.cpp index f417942b..29654ba8 100644 --- a/Road.cpp +++ b/Road.cpp @@ -65,6 +65,8 @@ void Road::get_cityjson(nlohmann::json& j, std::unordered_map<std::string,unsign nlohmann::json f; // f["type"] = "Road"; // TODO : change back to Road when implemented f["type"] = "GenericCityObject"; + f["attributes"]; + get_cityjson_attributes(f, _attributes); nlohmann::json g; this->get_cityjson_geom(g, dPts); f["geometry"].push_back(g); diff --git a/Separation.cpp b/Separation.cpp index 12bcdd1e..4ea168ee 100644 --- a/Separation.cpp +++ b/Separation.cpp @@ -67,6 +67,8 @@ bool Separation::lift() { void Separation::get_cityjson(nlohmann::json& j, std::unordered_map<std::string,unsigned long> &dPts) { nlohmann::json f; f["type"] = "GenericCityObject"; + f["attributes"]; + get_cityjson_attributes(f, _attributes); nlohmann::json g; this->get_cityjson_geom(g, dPts); f["geometry"].push_back(g); diff --git a/Terrain.cpp b/Terrain.cpp index 9a5af43f..f586234a 100644 --- a/Terrain.cpp +++ b/Terrain.cpp @@ -62,6 +62,8 @@ bool Terrain::lift() { void Terrain::get_cityjson(nlohmann::json& j, std::unordered_map<std::string,unsigned long> &dPts) { nlohmann::json f; f["type"] = "LandUse"; + f["attributes"]; + get_cityjson_attributes(f, _attributes); nlohmann::json g; this->get_cityjson_geom(g, dPts); f["geometry"].push_back(g); diff --git a/TopoFeature.cpp b/TopoFeature.cpp index 6a77e866..5a03cd73 100644 --- a/TopoFeature.cpp +++ b/TopoFeature.cpp @@ -275,6 +275,15 @@ void TopoFeature::get_imgeo_object_info(std::ofstream& of, std::string id) { } } +void TopoFeature::get_cityjson_attributes(nlohmann::json& f, AttributeMap attributes) { + for (auto& attribute : attributes) { + // add attributes except gml_id + if (attribute.first.compare("gml_id") != 0) + f["attributes"][std::get<0>(attribute)] = attribute.second.second; + } +} + + void TopoFeature::get_citygml_attributes(std::ofstream& of, AttributeMap attributes) { for (auto& attribute : attributes) { // add attributes except gml_id diff --git a/TopoFeature.h b/TopoFeature.h index a4588061..15c1c156 100644 --- a/TopoFeature.h +++ b/TopoFeature.h @@ -76,6 +76,7 @@ class TopoFeature { AttributeMap get_attributes(); void get_imgeo_object_info(std::ofstream& of, std::string id); void get_citygml_attributes(std::ofstream& of, AttributeMap attributes); + void get_cityjson_attributes(nlohmann::json& f, AttributeMap attributes); protected: Polygon2* _p2; std::vector< std::vector<int> > _p2z; diff --git a/Water.cpp b/Water.cpp index 9fc3f305..c9f930dc 100644 --- a/Water.cpp +++ b/Water.cpp @@ -67,6 +67,8 @@ bool Water::lift() { void Water::get_cityjson(nlohmann::json& j, std::unordered_map<std::string,unsigned long> &dPts) { nlohmann::json f; f["type"] = "WaterBody"; + f["attributes"]; + get_cityjson_attributes(f, _attributes); nlohmann::json g; this->get_cityjson_geom(g, dPts); f["geometry"].push_back(g);