From bd920a65d578cf5f643d50492e996ff76d477251 Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 7 Jul 2015 14:07:07 +0300 Subject: [PATCH] =?UTF-8?q?[generator]=20Better=20=E2=80=9Cplace-XXX?= =?UTF-8?q?=E2=80=9D=20filtering=20according=20to=20the=20classificator=20?= =?UTF-8?q?type.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generator/osm_element.hpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/generator/osm_element.hpp b/generator/osm_element.hpp index cca56698df..a0e4f8cd48 100644 --- a/generator/osm_element.hpp +++ b/generator/osm_element.hpp @@ -274,6 +274,14 @@ class SecondPassParser : public BaseOSMParser static constexpr double EQUAL_PLACE_SEARCH_RADIUS_M = 20000.0; bool IsPoint() const { return (m_ft.GetGeomType() == feature::GEOM_POINT); } + static bool IsEqualTypes(uint32_t t1, uint32_t t2) + { + // Use 2-arity places comparison for filtering. + // ("place-city-capital-2" is equal to "place-city") + ftype::TruncValue(t1, 2); + ftype::TruncValue(t2, 2); + return (t1 == t2); + } public: Place(FeatureBuilderT const & ft, uint32_t type) @@ -288,21 +296,33 @@ class SecondPassParser : public BaseOSMParser return MercatorBounds::RectByCenterXYAndSizeInMeters(m_pt, EQUAL_PLACE_SEARCH_RADIUS_M); } - /// @name Always replace point features and leave area features. - //@{ bool IsEqual(Place const & r) const { - return (m_type == r.m_type && + return (IsEqualTypes(m_type, r.m_type) && m_ft.GetName() == r.m_ft.GetName() && (IsPoint() || r.IsPoint()) && MercatorBounds::DistanceOnEarth(m_pt, r.m_pt) < EQUAL_PLACE_SEARCH_RADIUS_M); } - bool NeedReplace(Place const & r) const + /// Check whether we need to replace place @r with place @this. + bool IsBetterThan(Place const & r) const { - return (r.IsPoint() && (!IsPoint() || r.m_ft.GetRank() < m_ft.GetRank())); + // Area places has priority before point places. + if (!r.IsPoint()) + return false; + if (!IsPoint()) + return true; + + // Check types length. + // ("place-city-capital-2" is better than "place-city"). + uint8_t const l1 = ftype::GetLevel(m_type); + uint8_t const l2 = ftype::GetLevel(r.m_type); + if (l1 != l2) + return (l2 < l1); + + // Check ranks. + return (r.m_ft.GetRank() < m_ft.GetRank()); } - //@} }; m4::Tree m_places; @@ -323,7 +343,7 @@ class SecondPassParser : public BaseOSMParser { m_places.ReplaceEqualInRect(Place(ft, type), bind(&Place::IsEqual, _1, _2), - bind(&Place::NeedReplace, _1, _2)); + bind(&Place::IsBetterThan, _1, _2)); } else m_emitter(ft);