From 230535b2fe3abe2b0486346ac0f43bfcea293dd1 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Wed, 13 Jan 2016 10:57:33 +0300 Subject: [PATCH] ReverseGeocoder::GetNearbyFeatureStreets(). --- search/reverse_geocoder.cpp | 32 ++++++++++++++++++++++++++++---- search/reverse_geocoder.hpp | 3 +++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/search/reverse_geocoder.cpp b/search/reverse_geocoder.cpp index bb87eefab9..f3547170fc 100644 --- a/search/reverse_geocoder.cpp +++ b/search/reverse_geocoder.cpp @@ -11,6 +11,8 @@ #include "base/stl_helpers.hpp" +#include "std/limits.hpp" + namespace search { namespace @@ -114,10 +116,6 @@ void ReverseGeocoder::GetNearbyAddress(m2::PointD const & center, Address & addr GetNearbyStreets(b.m_center, streets); uint32_t ind; - - // TODO (AlexZ): False result of table->Get(...) means that - // there're no street for a building. Somehow it should be used - // in a Features Editor. if (table->Get(b.m_id.m_index, ind) && ind < streets.size()) { addr.m_building = b; @@ -127,6 +125,32 @@ void ReverseGeocoder::GetNearbyAddress(m2::PointD const & center, Address & addr } } +pair, uint32_t> ReverseGeocoder::GetNearbyFeatureStreets( + FeatureType const & feature) const +{ + pair, uint32_t> result; + auto & streetIndex = result.second; + streetIndex = numeric_limits::max(); + + FeatureID const fid = feature.GetID(); + MwmSet::MwmHandle const mwmHandle = m_index.GetMwmHandleById(fid.m_mwmId); + if (!mwmHandle.IsAlive()) + { + LOG(LERROR, ("Feature handle is not alive", feature)); + return result; + } + + auto & streets = result.first; + GetNearbyStreets(feature::GetCenter(feature), streets); + + unique_ptr const table = + search::v2::HouseToStreetTable::Load(*mwmHandle.GetValue()); + + if (table->Get(fid.m_index, streetIndex) && streetIndex >= streets.size()) + LOG(LERROR, ("Critical reverse geocoder error, returned", streetIndex, "for", feature)); + return result; +} + void ReverseGeocoder::GetNearbyBuildings(m2::PointD const & center, vector & buildings) const { GetNearbyBuildings(center, kLookupRadiusM, buildings); diff --git a/search/reverse_geocoder.hpp b/search/reverse_geocoder.hpp index c171b5305b..8c7e509243 100644 --- a/search/reverse_geocoder.hpp +++ b/search/reverse_geocoder.hpp @@ -68,6 +68,9 @@ public: void GetNearbyAddress(m2::PointD const & center, Address & addr) const; + /// @returns street segments (can be duplicate names) sorted by distance to feature's center. + /// uint32_t, if less than vector.size(), contains index of exact feature's street specified in OSM data. + pair, uint32_t> GetNearbyFeatureStreets(FeatureType const & feature) const; void GetNearbyBuildings(m2::PointD const & center, vector & buildings) const;