From 9692c3d85a7d10a3a11e84631060406db5b13225 Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Fri, 11 Dec 2015 19:27:28 +0300 Subject: [PATCH 1/3] Add tags 'height' and 'building:levels' to metadata as FMD_HEIGHT --- generator/osm2meta.hpp | 36 ++++++++++++++++++++++++++++++++++++ indexer/feature_meta.hpp | 1 + 2 files changed, 37 insertions(+) diff --git a/generator/osm2meta.hpp b/generator/osm2meta.hpp index 8874dfb7a7..818331ede4 100644 --- a/generator/osm2meta.hpp +++ b/generator/osm2meta.hpp @@ -123,6 +123,23 @@ public: if (!value.empty()) md.Set(Metadata::FMD_FLATS, value); } + else if (k == "height") + { + string const & value = ValidateAndFormat_height(v); + if (!value.empty()) + md.Set(Metadata::FMD_HEIGHT, value); + } + else if (k == "building:levels") + { + // Ignoring if FMD_HEIGHT already set + if (md.Get(Metadata::FMD_HEIGHT).empty()) + { + // Converting this attribute into height + string const & value = ValidateAndFormat_building_levels(v); + if (!value.empty()) + md.Set(Metadata::FMD_HEIGHT, value); + } + } return false; } @@ -213,5 +230,24 @@ protected: { return v; } + string ValidateAndFormat_height(string const & v) const + { + double val = 0; + string corrected(v, 0, v.find(" ")); + if(!strings::to_double(corrected, val) || val == 0) + return string(); + stringstream ss; + ss << fixed << setw(2) << setprecision(1) << val; + return ss.str(); + } + string ValidateAndFormat_building_levels(string const & v) const + { + double val = 0; + if(!strings::to_double(v, val) || val == 0) + return string(); + stringstream ss; + ss << fixed << setw(2) << setprecision(1) << (val * 3 /*levels multiplied by 3 meters per level*/); + return ss.str(); + } string ValidateAndFormat_wikipedia(string v) const; }; diff --git a/indexer/feature_meta.hpp b/indexer/feature_meta.hpp index 3a082f32eb..27e1c850d5 100644 --- a/indexer/feature_meta.hpp +++ b/indexer/feature_meta.hpp @@ -37,6 +37,7 @@ namespace feature FMD_WIKIPEDIA = 16, FMD_MAXSPEED = 17, FMD_FLATS = 18, + FMD_HEIGHT = 19, FMD_COUNT }; From fdb46b12f35507a8dd9084b5037ca44779b6f2d5 Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Fri, 11 Dec 2015 19:28:25 +0300 Subject: [PATCH 2/3] Fix classificator loading --- generator/generator_tests/feature_merger_test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/generator/generator_tests/feature_merger_test.cpp b/generator/generator_tests/feature_merger_test.cpp index c43c080898..1a21f1624b 100644 --- a/generator/generator_tests/feature_merger_test.cpp +++ b/generator/generator_tests/feature_merger_test.cpp @@ -2,6 +2,7 @@ #include "generator/feature_merger.hpp" +#include "indexer/classificator_loader.hpp" namespace { @@ -32,6 +33,8 @@ namespace UNIT_TEST(FeatureMerger_MultipleTypes) { + classificator::Load(); + P arrPt[] = { P(0, 0), P(1, 1), P(2, 2), P(3, 3) }; size_t const count = ARRAY_SIZE(arrPt)-1; @@ -75,6 +78,8 @@ UNIT_TEST(FeatureMerger_MultipleTypes) UNIT_TEST(FeatureMerger_Branches) { + classificator::Load(); + /* Try to unite next configuration o /\ @@ -135,6 +140,8 @@ UNIT_TEST(FeatureMerger_Branches) UNIT_TEST(FeatureMerger_Rounds) { + classificator::Load(); + vector vF; vF.push_back(FeatureBuilder1()); From d762298e7b12f2839e070e5d70d9a937a89bcc97 Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Fri, 11 Dec 2015 19:29:00 +0300 Subject: [PATCH 3/3] Tests for FMD_HEIGHT --- .../generator_tests/metadata_parser_test.cpp | 73 +++++++++++++++++++ .../generator_tool.xcodeproj/project.pbxproj | 12 +-- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/generator/generator_tests/metadata_parser_test.cpp b/generator/generator_tests/metadata_parser_test.cpp index 9ba9dda939..6022b98fe5 100644 --- a/generator/generator_tests/metadata_parser_test.cpp +++ b/generator/generator_tests/metadata_parser_test.cpp @@ -139,6 +139,79 @@ UNIT_TEST(Metadata_ValidateAndFormat_ele) md.Drop(Metadata::FMD_ELE); } +UNIT_TEST(Metadata_ValidateAndFormat_height) +{ + FeatureParams params; + MetadataTagProcessor p(params); + Metadata & md = params.GetMetadata(); + + p("height", "0"); + TEST(md.Empty(), ()); + + p("height", "0,0000"); + TEST(md.Empty(), ()); + + p("height", "0.0"); + TEST(md.Empty(), ()); + + p("height", "123"); + TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "123.0", ()); + md.Drop(Metadata::FMD_HEIGHT); + + p("height", "123.2"); + TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "123.2", ()); + md.Drop(Metadata::FMD_HEIGHT); + + p("height", "2 m"); + TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "2.0", ()); + md.Drop(Metadata::FMD_HEIGHT); + + p("height", "3-6"); + TEST(md.Empty(), ()); +} + +UNIT_TEST(Metadata_ValidateAndFormat_building_levels) +{ + FeatureParams params; + MetadataTagProcessor p(params); + Metadata & md = params.GetMetadata(); + + p("building:levels", "0"); + TEST(md.Empty(), ()); + + p("building:levels", "0,0000"); + TEST(md.Empty(), ()); + + p("building:levels", "0.0"); + TEST(md.Empty(), ()); + + p("building:levels", "1"); + TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "3.0", ()); + md.Drop(Metadata::FMD_HEIGHT); + + p("building:levels", "3.2"); + TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "9.6", ()); + md.Drop(Metadata::FMD_HEIGHT); + + p("building:levels", "1.0"); + TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "3.0", ()); + md.Drop(Metadata::FMD_HEIGHT); + + + p("building:levels", "1.0"); + p("height", "4.0"); + TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "4.0", ()); + md.Drop(Metadata::FMD_HEIGHT); + + p("height", "4.0"); + p("building:levels", "1.0"); + TEST_EQUAL(md.Get(Metadata::FMD_HEIGHT), "4.0", ()); + md.Drop(Metadata::FMD_HEIGHT); + + p("building:levels", "Level 1"); + TEST(md.Empty(), ()); +} + UNIT_TEST(Metadata_ValidateAndFormat_wikipedia) { char const * kWikiKey = "wikipedia"; diff --git a/xcode/generator_tool/generator_tool.xcodeproj/project.pbxproj b/xcode/generator_tool/generator_tool.xcodeproj/project.pbxproj index ea3c65b315..60a362f4b0 100644 --- a/xcode/generator_tool/generator_tool.xcodeproj/project.pbxproj +++ b/xcode/generator_tool/generator_tool.xcodeproj/project.pbxproj @@ -45,9 +45,9 @@ 675341631A3F54F600A0A8C3 /* generator_tool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 675341621A3F54F600A0A8C3 /* generator_tool.cpp */; }; 675343E31A3F607600A0A8C3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 675343E21A3F607600A0A8C3 /* Cocoa.framework */; }; 675344431A3F65E800A0A8C3 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 675343E01A3F600D00A0A8C3 /* IOKit.framework */; }; + 677792521C1B2E9700EC9499 /* metadata_parser_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 677792501C1B2E9300EC9499 /* metadata_parser_test.cpp */; }; 67AB92C21B73C27300AB5194 /* source_data.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 67AB92B31B738DE800AB5194 /* source_data.cpp */; }; 67AB92C31B73C29000AB5194 /* source_to_element_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 674A39D21B727589001DDB91 /* source_to_element_test.cpp */; }; - 67AB92CF1B75156000AB5194 /* classificator_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C1E41A4C28D5005EEA39 /* classificator_tests.cpp */; }; 67AB92D01B75156400AB5194 /* coasts_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C1E51A4C28D5005EEA39 /* coasts_test.cpp */; }; 67AB92D11B75156700AB5194 /* feature_builder_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C1E61A4C28D5005EEA39 /* feature_builder_test.cpp */; }; 67AB92D21B75156B00AB5194 /* feature_merger_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C1E71A4C28D5005EEA39 /* feature_merger_test.cpp */; }; @@ -55,7 +55,6 @@ 67AB92D51B75157400AB5194 /* osm_type_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C1EA1A4C28D5005EEA39 /* osm_type_test.cpp */; }; 67AB92D61B75157700AB5194 /* tesselator_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C1EB1A4C28D5005EEA39 /* tesselator_test.cpp */; }; 67AB92D71B75157A00AB5194 /* triangles_tree_coding_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C1EC1A4C28D5005EEA39 /* triangles_tree_coding_test.cpp */; }; - 67AB92D81B75157D00AB5194 /* metadata_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C26C1A4C5009005EEA39 /* metadata_test.cpp */; }; 67AB92D91B75158300AB5194 /* osm_o5m_source_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6764B8931ADD6FC100DD8B15 /* osm_o5m_source_test.cpp */; }; /* End PBXBuildFile section */ @@ -139,7 +138,6 @@ 6719DD5D1B95AB0F0018166F /* libtess2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtess2.a; path = "../../../omim-xcode-build/Debug/libtess2.a"; sourceTree = ""; }; 671F58B71B86109B0032311E /* intermediate_data_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = intermediate_data_test.cpp; sourceTree = ""; }; 6726C1E31A4C28D5005EEA39 /* check_mwms.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = check_mwms.cpp; sourceTree = ""; }; - 6726C1E41A4C28D5005EEA39 /* classificator_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = classificator_tests.cpp; sourceTree = ""; }; 6726C1E51A4C28D5005EEA39 /* coasts_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = coasts_test.cpp; sourceTree = ""; }; 6726C1E61A4C28D5005EEA39 /* feature_builder_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = feature_builder_test.cpp; sourceTree = ""; }; 6726C1E71A4C28D5005EEA39 /* feature_merger_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = feature_merger_test.cpp; sourceTree = ""; }; @@ -149,7 +147,6 @@ 6726C1EC1A4C28D5005EEA39 /* triangles_tree_coding_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = triangles_tree_coding_test.cpp; sourceTree = ""; }; 6726C2351A4C2BBD005EEA39 /* generator_tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = generator_tests; sourceTree = BUILT_PRODUCTS_DIR; }; 6726C2401A4C2D9F005EEA39 /* testingmain.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = testingmain.cpp; path = ../../testing/testingmain.cpp; sourceTree = ""; }; - 6726C26C1A4C5009005EEA39 /* metadata_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = metadata_test.cpp; sourceTree = ""; }; 674A28C71B1C7FC9001A525C /* libexpat.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libexpat.a; path = "../../../omim-xcode-build/Debug/libexpat.a"; sourceTree = ""; }; 674A28C91B1C7FED001A525C /* libcoding.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcoding.a; path = "../../../omim-xcode-build/Debug/libcoding.a"; sourceTree = ""; }; 674A28CA1B1C7FED001A525C /* libgenerator.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgenerator.a; path = "../../../omim-xcode-build/Debug/libgenerator.a"; sourceTree = ""; }; @@ -173,6 +170,7 @@ 675343E01A3F600D00A0A8C3 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; }; 675343E21A3F607600A0A8C3 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 6764B8931ADD6FC100DD8B15 /* osm_o5m_source_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = osm_o5m_source_test.cpp; sourceTree = ""; }; + 677792501C1B2E9300EC9499 /* metadata_parser_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = metadata_parser_test.cpp; sourceTree = ""; }; 67AB92B31B738DE800AB5194 /* source_data.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = source_data.cpp; sourceTree = ""; }; 67AB92B41B738DE800AB5194 /* source_data.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = source_data.hpp; sourceTree = ""; }; 67AB92C61B73D03500AB5194 /* libmap.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmap.a; path = "/Volumes/AltHD/omim/xcode/map/../../../omim-xcode-build/Debug/libmap.a"; sourceTree = ""; }; @@ -298,9 +296,9 @@ 6726C1D71A4C27A5005EEA39 /* Tests */ = { isa = PBXGroup; children = ( + 677792501C1B2E9300EC9499 /* metadata_parser_test.cpp */, 6726C2401A4C2D9F005EEA39 /* testingmain.cpp */, 6726C1E31A4C28D5005EEA39 /* check_mwms.cpp */, - 6726C1E41A4C28D5005EEA39 /* classificator_tests.cpp */, 6726C1E51A4C28D5005EEA39 /* coasts_test.cpp */, 6726C1E61A4C28D5005EEA39 /* feature_builder_test.cpp */, 6726C1E71A4C28D5005EEA39 /* feature_merger_test.cpp */, @@ -308,7 +306,6 @@ 6726C1EA1A4C28D5005EEA39 /* osm_type_test.cpp */, 6726C1EB1A4C28D5005EEA39 /* tesselator_test.cpp */, 6726C1EC1A4C28D5005EEA39 /* triangles_tree_coding_test.cpp */, - 6726C26C1A4C5009005EEA39 /* metadata_test.cpp */, 6764B8931ADD6FC100DD8B15 /* osm_o5m_source_test.cpp */, 674A39D21B727589001DDB91 /* source_to_element_test.cpp */, 67AB92B31B738DE800AB5194 /* source_data.cpp */, @@ -456,9 +453,7 @@ files = ( 671F58B91B8611360032311E /* intermediate_data_test.cpp in Sources */, 67AB92D51B75157400AB5194 /* osm_type_test.cpp in Sources */, - 67AB92D81B75157D00AB5194 /* metadata_test.cpp in Sources */, 67AB92D71B75157A00AB5194 /* triangles_tree_coding_test.cpp in Sources */, - 67AB92CF1B75156000AB5194 /* classificator_tests.cpp in Sources */, 67AB92D01B75156400AB5194 /* coasts_test.cpp in Sources */, 670F291B1BA6CE4F00F2ABF4 /* check_mwms.cpp in Sources */, 67AB92D91B75158300AB5194 /* osm_o5m_source_test.cpp in Sources */, @@ -467,6 +462,7 @@ 67AB92D21B75156B00AB5194 /* feature_merger_test.cpp in Sources */, 67AB92C31B73C29000AB5194 /* source_to_element_test.cpp in Sources */, 67AB92D31B75156E00AB5194 /* osm_id_test.cpp in Sources */, + 677792521C1B2E9700EC9499 /* metadata_parser_test.cpp in Sources */, 67AB92D11B75156700AB5194 /* feature_builder_test.cpp in Sources */, 67AB92C21B73C27300AB5194 /* source_data.cpp in Sources */, );