From 8e6b39e0917f7e6c406b45d62d776a6038369cc5 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 27 Jan 2014 14:41:39 +0300 Subject: [PATCH] [search] Added basic code to extract addresses for search unit tests --- generator/osm2type.cpp | 2 ++ generator/osm_element.hpp | 23 ++++++++++++++++++++++- indexer/feature_data.cpp | 5 +++++ indexer/feature_data.hpp | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/generator/osm2type.cpp b/generator/osm2type.cpp index 0e4dac26dc..d6364674b3 100644 --- a/generator/osm2type.cpp +++ b/generator/osm2type.cpp @@ -194,6 +194,8 @@ namespace ftype m_params.AddHouseNumber(v); if (k == "addr:housename") m_params.AddHouseName(v); + if (k == "addr:street") + m_params.AddStreetAddress(v); if (k == "addr:flats") m_params.flats = v; diff --git a/generator/osm_element.hpp b/generator/osm_element.hpp index 91be8124a9..c8b4a8c13c 100644 --- a/generator/osm_element.hpp +++ b/generator/osm_element.hpp @@ -12,6 +12,8 @@ #include "../base/logging.hpp" #include "../base/stl_add.hpp" +#include "../platform/platform.hpp" + #include "../std/unordered_map.hpp" #include "../std/list.hpp" @@ -395,7 +397,6 @@ protected: return; bool const isClosed = (count > 2 && ft.IsGeometryClosed()); - // Try to set area feature (point and linear types are also suitable for this) if (isClosed && feature::IsDrawableLike(fValue.m_Types, FEATURE_TYPE_AREA)) base_type::FinishAreaFeature(id, ft); @@ -411,7 +412,18 @@ protected: f.SetParams(params); f.SetCenter(ft.GetGeometryCenter()); if (f.PreSerialize()) + { + if (!params.m_streetAddress.empty() && !params.house.IsEmpty()) + { + m2::PointD p = ft.GetLimitRect().Center(); + string const s = params.m_streetAddress + "|" + params.house.Get() + "|" + + strings::to_string(MercatorBounds::YToLat(p.y)) + "|" + + strings::to_string(MercatorBounds::XToLon(p.x)) + '\n'; + FileWriter writer = FileWriter(GetPlatform().WritableDir() + "/adresses.txt", FileWriter::OP_APPEND, false); + writer.Write(s.c_str(), s.size()); + } base_type::m_emitter(f); + } } } @@ -478,6 +490,15 @@ protected: ft.SetParams(fValue); if (ft.PreSerialize()) { + if (!fValue.m_streetAddress.empty() && !fValue.house.IsEmpty()) + { + m2::PointD p = ft.GetLimitRect().Center(); + string const s = fValue.m_streetAddress + "|" + fValue.house.Get() + "|" + + strings::to_string(MercatorBounds::YToLat(p.y)) + "|" + + strings::to_string(MercatorBounds::XToLon(p.x)) + '\n'; + FileWriter writer = FileWriter(GetPlatform().WritableDir() + "/adresses.txt", FileWriter::OP_APPEND, false); + writer.Write(s.c_str(), s.size()); + } // add osm id for debugging ft.AddOsmId(p->name, id); base_type::m_emitter(ft); diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index 0d3fe24da0..d8f12ec33c 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -125,6 +125,11 @@ void FeatureParamsBase::AddHouseNumber(string const & ss) house.Set(house.IsEmpty() ? s : s + ", " + house.Get()); } +void FeatureParamsBase::AddStreetAddress(string const & s) +{ + m_streetAddress = s; +} + void FeatureParams::SetGeomType(feature::EGeomType t) { switch (t) diff --git a/indexer/feature_data.hpp b/indexer/feature_data.hpp index 9c8e47fe2b..8ca13a6da0 100644 --- a/indexer/feature_data.hpp +++ b/indexer/feature_data.hpp @@ -112,6 +112,8 @@ struct FeatureParamsBase string flats; int8_t layer; uint8_t rank; + /// We use it now only for search unit tests + string m_streetAddress; FeatureParamsBase() : layer(0), rank(0) {} @@ -125,6 +127,7 @@ struct FeatureParamsBase void AddHouseName(string const & s); void AddHouseNumber(string const & s); + void AddStreetAddress(string const & s); template void Write(TSink & sink, uint8_t header) const