diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 1592d7589b..b7bd26ce97 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -145,12 +145,12 @@ set(SRC relation_tags_enricher.hpp region_meta.cpp region_meta.hpp - regions/city.hpp regions/collector_region_info.cpp regions/collector_region_info.hpp regions/level_region.hpp regions/node.cpp regions/node.hpp + regions/place_point.hpp regions/region.cpp regions/region.hpp regions/region_base.cpp diff --git a/generator/regions/city.hpp b/generator/regions/city.hpp deleted file mode 100644 index ce97c10b41..0000000000 --- a/generator/regions/city.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "generator/feature_builder.hpp" -#include "generator/regions/collector_region_info.hpp" -#include "generator/regions/region_base.hpp" - -#include - -namespace generator -{ -namespace regions -{ -class City : public RegionWithName, public RegionWithData -{ -public: - explicit City(FeatureBuilder1 const & fb, RegionDataProxy const & rd) - : RegionWithName(fb.GetParams().name), - RegionWithData(rd) - { - auto const p = fb.GetKeyPoint(); - m_center = {p.x, p.y}; - } - - BoostPoint GetCenter() const { return m_center; } - -private: - BoostPoint m_center; -}; - -using PointCitiesMap = std::unordered_map; -} // namespace regions -} // namespace generator diff --git a/generator/regions/place_point.hpp b/generator/regions/place_point.hpp new file mode 100644 index 0000000000..f7109fcd03 --- /dev/null +++ b/generator/regions/place_point.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "generator/feature_builder.hpp" +#include "generator/regions/collector_region_info.hpp" +#include "generator/regions/region_base.hpp" + +#include + +namespace generator +{ +namespace regions +{ +class PlacePoint; +using PlacePointsMap = std::unordered_map; + +// PlacePoint objects presents centers (place=* nodes) of localities (city/town/village/...) +// and their subdivision parts (suburb/quarter/...). +// PlacePoint objects are converted to Region objects with approximated boundaries +// when there is no the same places with original boundaries. +// Approximation depends on place type of point (see MakePolygonWithRadius()). +// Conversion is performed by Region constructor: Region{placePoint}. +class PlacePoint : public RegionWithName, public RegionWithData +{ +public: + explicit PlacePoint(FeatureBuilder1 const & fb, RegionDataProxy const & rd) + : RegionWithName(fb.GetParams().name), + RegionWithData(rd) + { + auto const p = fb.GetKeyPoint(); + m_position = {p.x, p.y}; + } + + BoostPoint GetPosition() const { return m_position; } + +private: + BoostPoint m_position; +}; +} // namespace regions +} // namespace generator diff --git a/generator/regions/region.cpp b/generator/regions/region.cpp index fd49967718..371a1657ef 100644 --- a/generator/regions/region.cpp +++ b/generator/regions/region.cpp @@ -1,8 +1,8 @@ #include "generator/regions/region.hpp" #include "generator/boost_helpers.hpp" -#include "generator/regions/city.hpp" #include "generator/regions/collector_region_info.hpp" +#include "generator/regions/place_point.hpp" #include "geometry/mercator.hpp" @@ -43,13 +43,13 @@ Region::Region(FeatureBuilder1 const & fb, RegionDataProxy const & rd) m_area = boost::geometry::area(*m_polygon); } -Region::Region(City const & city) - : RegionWithName(city.GetMultilangName()) - , RegionWithData(city.GetRegionData()) +Region::Region(PlacePoint const & place) + : RegionWithName(place.GetMultilangName()) + , RegionWithData(place.GetRegionData()) , m_polygon(std::make_shared()) { - auto const radius = GetRadiusByPlaceType(city.GetPlaceType()); - *m_polygon = MakePolygonWithRadius(city.GetCenter(), radius); + auto const radius = GetRadiusByPlaceType(place.GetPlaceType()); + *m_polygon = MakePolygonWithRadius(place.GetPosition(), radius); boost::geometry::envelope(*m_polygon, m_rect); m_area = boost::geometry::area(*m_polygon); } @@ -139,11 +139,11 @@ BoostPoint Region::GetCenter() const return p; } -bool Region::Contains(City const & cityPoint) const +bool Region::Contains(PlacePoint const & place) const { CHECK(m_polygon, ()); - return Contains(cityPoint.GetCenter()); + return Contains(place.GetPosition()); } bool Region::Contains(BoostPoint const & point) const @@ -154,7 +154,7 @@ bool Region::Contains(BoostPoint const & point) const boost::geometry::covered_by(point, *m_polygon); } -bool FeatureCityPointToRegion(RegionInfo const & regionInfo, FeatureBuilder1 & feature) +bool FeaturePlacePointToRegion(RegionInfo const & regionInfo, FeatureBuilder1 & feature) { if (!feature.IsPoint()) return false; diff --git a/generator/regions/region.hpp b/generator/regions/region.hpp index af000e83fd..f888c9508f 100644 --- a/generator/regions/region.hpp +++ b/generator/regions/region.hpp @@ -13,7 +13,7 @@ class RegionDataProxy; namespace regions { -class City; +class PlacePoint; // This is a helper class that is needed to represent the region. // With this view, further processing is simplified. @@ -22,13 +22,13 @@ class Region : public RegionWithName, public RegionWithData public: explicit Region(FeatureBuilder1 const & fb, RegionDataProxy const & rd); // Build a region and its boundary based on the heuristic. - explicit Region(City const & city); + explicit Region(PlacePoint const & place); // After calling DeletePolygon, you cannot use Contains, ContainsRect, CalculateOverlapPercentage. void DeletePolygon(); bool Contains(Region const & smaller) const; bool ContainsRect(Region const & smaller) const; - bool Contains(City const & cityPoint) const; + bool Contains(PlacePoint const & place) const; bool Contains(BoostPoint const & point) const; double CalculateOverlapPercentage(Region const & other) const; BoostPoint GetCenter() const; @@ -48,6 +48,6 @@ private: double m_area; }; -bool FeatureCityPointToRegion(RegionInfo const & regionInfo, FeatureBuilder1 & feature); +bool FeaturePlacePointToRegion(RegionInfo const & regionInfo, FeatureBuilder1 & feature); } // namespace regions } // namespace generator diff --git a/generator/regions/regions.cpp b/generator/regions/regions.cpp index c925855f8d..74866524fe 100644 --- a/generator/regions/regions.cpp +++ b/generator/regions/regions.cpp @@ -3,7 +3,7 @@ #include "generator/feature_builder.hpp" #include "generator/feature_generator.hpp" #include "generator/generate_info.hpp" -#include "generator/regions/city.hpp" +#include "generator/regions/place_point.hpp" #include "generator/regions/regions.hpp" #include "generator/regions/node.hpp" #include "generator/regions/regions_builder.hpp" @@ -100,11 +100,11 @@ private: RepackTmpMwm(setIds); } - std::tuple + std::tuple ReadDatasetFromTmpMwm(std::string const & tmpMwmFilename, RegionInfo & collector) { RegionsBuilder::Regions regions; - PointCitiesMap pointCitiesMap; + PlacePointsMap placePointsMap; auto const toDo = [&](FeatureBuilder1 const & fb, uint64_t /* currPos */) { if (fb.IsArea() && fb.IsGeometryClosed()) { @@ -115,20 +115,20 @@ private: else if (fb.IsPoint()) { auto const id = fb.GetMostGenericOsmId(); - pointCitiesMap.emplace(id, City(fb, collector.Get(id))); + placePointsMap.emplace(id, PlacePoint{fb, collector.Get(id)}); } }; feature::ForEachFromDatRawFormat(tmpMwmFilename, toDo); - return std::make_tuple(std::move(regions), std::move(pointCitiesMap)); + return std::make_tuple(std::move(regions), std::move(placePointsMap)); } RegionsBuilder::Regions ReadAndFixData() { RegionsBuilder::Regions regions; - PointCitiesMap pointCitiesMap; - std::tie(regions, pointCitiesMap) = ReadDatasetFromTmpMwm(m_pathInRegionsTmpMwm, m_regionsInfoCollector); - FixRegionsWithPlacePointApproximation(pointCitiesMap, regions); + PlacePointsMap placePointsMap; + std::tie(regions, placePointsMap) = ReadDatasetFromTmpMwm(m_pathInRegionsTmpMwm, m_regionsInfoCollector); + FixRegionsWithPlacePointApproximation(placePointsMap, regions); FilterRegions(regions); return regions; } @@ -152,7 +152,7 @@ private: feature::FeaturesCollector collector(m_pathOutRepackedRegionsTmpMwm); auto const toDo = [this, &collector, &ids](FeatureBuilder1 & fb, uint64_t /* currPos */) { if (ids.count(fb.GetMostGenericOsmId()) == 0 || - (fb.IsPoint() && !FeatureCityPointToRegion(m_regionsInfoCollector, fb))) + (fb.IsPoint() && !FeaturePlacePointToRegion(m_regionsInfoCollector, fb))) { return; } diff --git a/generator/regions/regions_fixer.cpp b/generator/regions/regions_fixer.cpp index 4348cd3e64..3faf310afe 100644 --- a/generator/regions/regions_fixer.cpp +++ b/generator/regions/regions_fixer.cpp @@ -33,14 +33,14 @@ public: } } - bool CityExistsAsRegion(City const & city) + bool PlaceExistsAsRegion(PlacePoint const & place) { - auto const cityType = city.GetPlaceType(); - auto const range = m_nameRegionMap.equal_range(city.GetName()); + auto const placeType = place.GetPlaceType(); + auto const range = m_nameRegionMap.equal_range(place.GetName()); for (auto it = range.first; it != range.second; ++it) { - Region const & r = it->second; - if (r.GetPlaceType() == cityType && r.Contains(city)) + Region const & region = it->second; + if (placeType == region.GetPlaceType() && region.Contains(place)) return true; } @@ -55,8 +55,8 @@ class RegionsFixerWithPlacePointApproximation { public: explicit RegionsFixerWithPlacePointApproximation(RegionsBuilder::Regions && regions, - PointCitiesMap const & pointCitiesMap) - : m_regions(std::move(regions)), m_pointCitiesMap(pointCitiesMap) {} + PlacePointsMap const & placePointsMap) + : m_regions(std::move(regions)), m_placePointsMap(placePointsMap) {} RegionsBuilder::Regions && GetFixedRegions() @@ -64,38 +64,38 @@ public: RegionLocalityChecker regionsChecker(m_regions); RegionsBuilder::Regions approximatedRegions; size_t countOfFixedRegions = 0; - for (auto const & cityKeyValue : m_pointCitiesMap) + for (auto const & placeKeyValue : m_placePointsMap) { - auto const & city = cityKeyValue.second; - if (NeedCity(city) && !regionsChecker.CityExistsAsRegion(city)) + auto const & place = placeKeyValue.second; + if (IsApproximable(place) && !regionsChecker.PlaceExistsAsRegion(place)) { - approximatedRegions.push_back(Region(city)); + approximatedRegions.push_back(Region(place)); ++countOfFixedRegions; } } - LOG(LINFO, ("City boundaries restored by approximation:", countOfFixedRegions)); + LOG(LINFO, ("Place boundaries restored by approximation:", countOfFixedRegions)); std::move(std::begin(approximatedRegions), std::end(approximatedRegions), std::back_inserter(m_regions)); return std::move(m_regions); } private: - bool NeedCity(const City & city) + bool IsApproximable(PlacePoint const & place) { - auto const placeType = city.GetPlaceType(); + auto const placeType = place.GetPlaceType(); return placeType >= PlaceType::City; } RegionsBuilder::Regions m_regions; - PointCitiesMap const & m_pointCitiesMap; + PlacePointsMap const & m_placePointsMap; }; } // namespace -void FixRegionsWithPlacePointApproximation(PointCitiesMap const & pointCitiesMap, +void FixRegionsWithPlacePointApproximation(PlacePointsMap const & placePointsMap, RegionsBuilder::Regions & regions) { - RegionsFixerWithPlacePointApproximation fixer(std::move(regions), pointCitiesMap); + RegionsFixerWithPlacePointApproximation fixer(std::move(regions), placePointsMap); regions = fixer.GetFixedRegions(); } } // namespace regions diff --git a/generator/regions/regions_fixer.hpp b/generator/regions/regions_fixer.hpp index 1678700bb3..8452c0ecde 100644 --- a/generator/regions/regions_fixer.hpp +++ b/generator/regions/regions_fixer.hpp @@ -1,6 +1,6 @@ #pragma once -#include "generator/regions/city.hpp" +#include "generator/regions/place_point.hpp" #include "generator/regions/regions_builder.hpp" #include "base/geo_object_id.hpp" @@ -12,7 +12,7 @@ namespace generator namespace regions { // This function will build a boundary from point based on place. -void FixRegionsWithPlacePointApproximation(PointCitiesMap const & pointCitiesMap, +void FixRegionsWithPlacePointApproximation(PlacePointsMap const & placePointsMap, RegionsBuilder::Regions & regions); } // namespace regions } // namespace generator