From 863d766718e6ccb908e9c3060f81917b4eddbee6 Mon Sep 17 00:00:00 2001 From: tatiana-kondakova Date: Tue, 30 Jan 2018 18:16:06 +0300 Subject: [PATCH] Add LocalityIndex --- indexer/CMakeLists.txt | 1 + indexer/locality_index.hpp | 50 +++++++++++++++++++ .../indexer/indexer.xcodeproj/project.pbxproj | 4 ++ 3 files changed, 55 insertions(+) create mode 100644 indexer/locality_index.hpp diff --git a/indexer/CMakeLists.txt b/indexer/CMakeLists.txt index 2e227b4024..109de339bb 100644 --- a/indexer/CMakeLists.txt +++ b/indexer/CMakeLists.txt @@ -92,6 +92,7 @@ set( index.hpp interval_index_builder.hpp interval_index.hpp + locality_index.hpp locality_index_builder.hpp locality_index_builder.cpp locality_object.hpp diff --git a/indexer/locality_index.hpp b/indexer/locality_index.hpp new file mode 100644 index 0000000000..9acac6fcb3 --- /dev/null +++ b/indexer/locality_index.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include "indexer/cell_id.hpp" +#include "indexer/feature_covering.hpp" +#include "indexer/interval_index.hpp" +#include "indexer/locality_object.hpp" +#include "indexer/scales.hpp" + +#include "geometry/rect2d.hpp" + +#include "base/osm_id.hpp" + +#include +#include + +namespace indexer +{ +// Geometry index which stores osm::Id as object identifier. +// Used for geocoder server, stores only POIs and buildings which have address information. +// Based on IntervalIndex. +template +class LocalityIndex +{ +public: + using ProcessObject = std::function; + + explicit LocalityIndex(Reader const & reader) + { + m_intervalIndex = std::make_unique>(reader); + } + + void ForEachInRect(ProcessObject const & processObject, m2::RectD const & rect) const + { + covering::CoveringGetter cov(rect, covering::CoveringMode::ViewportWithLowLevels); + covering::Intervals const & intervals = cov.Get(scales::GetUpperScale()); + + for (auto const & i : intervals) + { + m_intervalIndex->ForEach( + [&processObject](uint64_t stored_id) { + processObject(LocalityObject::FromStoredId(stored_id)); + }, + i.first, i.second); + } + } + +private: + std::unique_ptr> m_intervalIndex; +}; +} // namespace indexer diff --git a/xcode/indexer/indexer.xcodeproj/project.pbxproj b/xcode/indexer/indexer.xcodeproj/project.pbxproj index 144b336623..171d1015f8 100644 --- a/xcode/indexer/indexer.xcodeproj/project.pbxproj +++ b/xcode/indexer/indexer.xcodeproj/project.pbxproj @@ -74,6 +74,7 @@ 40009064201F5CB000963E18 /* locality_index_builder.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 4000905F201F5CAF00963E18 /* locality_index_builder.hpp */; }; 40009065201F5CB000963E18 /* locality_object.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 40009060201F5CB000963E18 /* locality_object.hpp */; }; 40009066201F5CB000963E18 /* locality_index_builder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 40009061201F5CB000963E18 /* locality_index_builder.cpp */; }; + 4095DEB22020AC0000C591A3 /* locality_index.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 4095DEB12020AC0000C591A3 /* locality_index.hpp */; }; 4099F6491FC7142A002A7B05 /* fake_feature_ids.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4099F6471FC71429002A7B05 /* fake_feature_ids.cpp */; }; 4099F64A1FC7142A002A7B05 /* fake_feature_ids.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 4099F6481FC7142A002A7B05 /* fake_feature_ids.hpp */; }; 456B3FB41EDEEB65009B3D1F /* scales_patch.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 456B3FB31EDEEB65009B3D1F /* scales_patch.hpp */; }; @@ -310,6 +311,7 @@ 4000905F201F5CAF00963E18 /* locality_index_builder.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = locality_index_builder.hpp; sourceTree = ""; }; 40009060201F5CB000963E18 /* locality_object.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = locality_object.hpp; sourceTree = ""; }; 40009061201F5CB000963E18 /* locality_index_builder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = locality_index_builder.cpp; sourceTree = ""; }; + 4095DEB12020AC0000C591A3 /* locality_index.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = locality_index.hpp; sourceTree = ""; }; 4099F6471FC71429002A7B05 /* fake_feature_ids.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fake_feature_ids.cpp; sourceTree = ""; }; 4099F6481FC7142A002A7B05 /* fake_feature_ids.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = fake_feature_ids.hpp; sourceTree = ""; }; 456B3FB31EDEEB65009B3D1F /* scales_patch.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = scales_patch.hpp; sourceTree = ""; }; @@ -682,6 +684,7 @@ 6753409C1A3F53CB00A0A8C3 /* indexer */ = { isa = PBXGroup; children = ( + 4095DEB12020AC0000C591A3 /* locality_index.hpp */, 4000905D201F5CAF00963E18 /* cell_value_pair.hpp */, 40009061201F5CB000963E18 /* locality_index_builder.cpp */, 4000905F201F5CAF00963E18 /* locality_index_builder.hpp */, @@ -854,6 +857,7 @@ 34583BC81C88552100F94664 /* cuisines.hpp in Headers */, 674125151B4C02F100A3E828 /* map_style.hpp in Headers */, 675341291A3F540F00A0A8C3 /* ftypes_matcher.hpp in Headers */, + 4095DEB22020AC0000C591A3 /* locality_index.hpp in Headers */, 675341201A3F540F00A0A8C3 /* feature_processor.hpp in Headers */, 675341341A3F540F00A0A8C3 /* interval_index.hpp in Headers */, 34664CF51D49FEC1003D7096 /* feature_altitude.hpp in Headers */,