From f3d8045593715c2f1381e6b29b343d3bc5822936 Mon Sep 17 00:00:00 2001 From: Anatoly Serdtcev Date: Tue, 23 Apr 2019 13:30:40 +0300 Subject: [PATCH] [generator:streets] Generate streets in separate process --- generator/CMakeLists.txt | 18 +++++--- generator/generator_tool/generator_tool.cpp | 26 ++++++++++- .../geo_objects/geo_object_info_getter.hpp | 2 +- generator/geo_objects/geo_objects.cpp | 25 +++-------- generator/geo_objects/geo_objects_filter.cpp | 12 +----- generator/geo_objects/geo_objects_filter.hpp | 2 - .../{geo_objects => }/key_value_storage.cpp | 5 +-- .../{geo_objects => }/key_value_storage.hpp | 3 -- .../region_info_getter.cpp | 8 ++-- .../region_info_getter.hpp | 6 +-- generator/streets/streets.cpp | 43 +++++++++++++++++++ generator/streets/streets.hpp | 17 ++++++++ .../streets_builder.cpp | 36 ++++++++-------- .../streets_builder.hpp | 21 ++++----- generator/streets/streets_filter.cpp | 26 +++++++++++ generator/streets/streets_filter.hpp | 21 +++++++++ generator/translator_factory.hpp | 4 ++ generator/translator_streets.cpp | 16 +++++++ generator/translator_streets.hpp | 23 ++++++++++ 19 files changed, 233 insertions(+), 81 deletions(-) rename generator/{geo_objects => }/key_value_storage.cpp (94%) rename generator/{geo_objects => }/key_value_storage.hpp (95%) rename generator/{geo_objects => regions}/region_info_getter.cpp (94%) rename generator/{geo_objects => regions}/region_info_getter.hpp (92%) create mode 100644 generator/streets/streets.cpp create mode 100644 generator/streets/streets.hpp rename generator/{geo_objects => streets}/streets_builder.cpp (84%) rename generator/{geo_objects => streets}/streets_builder.hpp (69%) create mode 100644 generator/streets/streets_filter.cpp create mode 100644 generator/streets/streets_filter.hpp create mode 100644 generator/translator_streets.cpp create mode 100644 generator/translator_streets.hpp diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index f8f96ed540..b87dba5f0b 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -96,17 +96,13 @@ set(SRC geo_objects/geo_object_info_getter.hpp geo_objects/geo_objects_filter.cpp geo_objects/geo_objects_filter.hpp - geo_objects/key_value_storage.cpp - geo_objects/key_value_storage.hpp - geo_objects/region_info_getter.cpp - geo_objects/region_info_getter.hpp - geo_objects/streets_builder.cpp - geo_objects/streets_builder.hpp holes.cpp holes.hpp intermediate_data.cpp intermediate_data.hpp intermediate_elements.hpp + key_value_storage.cpp + key_value_storage.hpp locality_sorter.cpp locality_sorter.hpp maxspeeds_builder.cpp @@ -163,6 +159,8 @@ set(SRC regions/region_base.hpp regions/region_info.cpp regions/region_info.hpp + regions/region_info_getter.cpp + regions/region_info_getter.hpp regions/regions.cpp regions/regions.hpp regions/regions_builder.cpp @@ -195,6 +193,12 @@ set(SRC srtm_parser.hpp statistics.cpp statistics.hpp + streets/streets.cpp + streets/streets.hpp + streets/streets_builder.cpp + streets/streets_builder.hpp + streets/streets_filter.cpp + streets/streets_filter.hpp tag_admixer.hpp tesselator.cpp tesselator.hpp @@ -218,6 +222,8 @@ set(SRC translator_interface.hpp translator_region.cpp translator_region.hpp + translator_streets.cpp + translator_streets.hpp translator_world.cpp translator_world.hpp type_helper.cpp diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index ffdec1a7dc..e61967fce9 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -27,6 +27,7 @@ #include "generator/road_access_generator.hpp" #include "generator/routing_index_generator.hpp" #include "generator/search_index_builder.hpp" +#include "generator/streets/streets.hpp" #include "generator/statistics.hpp" #include "generator/traffic_generator.hpp" #include "generator/transit_generator.hpp" @@ -113,6 +114,8 @@ DEFINE_bool(preprocess, false, "1st pass - create nodes/ways/relations data."); DEFINE_bool(generate_features, false, "2nd pass - generate intermediate features."); DEFINE_bool(generate_region_features, false, "Generate intermediate features for regions to use in regions index and borders generation."); +DEFINE_bool(generate_streets_features, false, + "Generate intermediate features for streets to use in server-side forward geocoder."); DEFINE_bool(generate_geo_objects_features, false, "Generate intermediate features for geo objects to use in geo objects index."); DEFINE_bool(generate_geometry, false, @@ -196,6 +199,8 @@ DEFINE_bool(generate_traffic_keys, false, // Generating geo objects key-value. DEFINE_string(regions_index, "", "Input regions index file."); DEFINE_string(regions_key_value, "", "Input regions key-value file."); +DEFINE_string(streets_features, "", "Input tmp.mwm file with streets."); +DEFINE_string(streets_key_value, "", "Output streets key-value file."); DEFINE_string(geo_objects_features, "", "Input tmp.mwm file with geo objects."); DEFINE_string(ids_without_addresses, "", "Output file with objects ids without addresses."); DEFINE_string(geo_objects_key_value, "", "Output geo objects key-value file."); @@ -293,6 +298,7 @@ int GeneratorToolMain(int argc, char ** argv) FLAGS_make_routing_index || FLAGS_make_cross_mwm || FLAGS_make_transit_cross_mwm || FLAGS_make_city_roads || FLAGS_generate_maxspeed || FLAGS_generate_traffic_keys || FLAGS_transit_path != "" || FLAGS_ugc_data != "" || FLAGS_popular_places_data != "" || + FLAGS_generate_streets_features || FLAGS_streets_key_value != "" || FLAGS_generate_geo_objects_features || FLAGS_geo_objects_key_value != "" || FLAGS_dump_wikipedia_urls != "" || FLAGS_wikipedia_pages != "" || FLAGS_popularity_csv != "") { @@ -361,12 +367,15 @@ int GeneratorToolMain(int argc, char ** argv) } } } - else if (FLAGS_generate_region_features || FLAGS_generate_geo_objects_features) + else if (FLAGS_generate_region_features || FLAGS_generate_streets_features || + FLAGS_generate_geo_objects_features) { CHECK(!FLAGS_generate_features && !FLAGS_make_coasts, ("FLAGS_generate_features and FLAGS_make_coasts should " "not be used with FLAGS_generate_region_features")); - CHECK(!(FLAGS_generate_region_features && FLAGS_generate_geo_objects_features), ()); + CHECK((FLAGS_generate_region_features + FLAGS_generate_streets_features + + FLAGS_generate_geo_objects_features) == 1, + ("At most one features generation option is allowed simultaneously")); genInfo.m_fileName = FLAGS_output; @@ -378,6 +387,12 @@ int GeneratorToolMain(int argc, char ** argv) translators.Append(CreateTranslator(TranslatorType::Regions, emitter, cacheLoader.GetCache(), genInfo)); } + if (FLAGS_generate_streets_features) + { + auto emitter = CreateEmitter(EmitterType::SimpleWithPreserialize, genInfo); + translators.Append(CreateTranslator(TranslatorType::Streets, emitter, cacheLoader.GetCache())); + } + if (FLAGS_generate_geo_objects_features) { auto emitter = CreateEmitter(EmitterType::SimpleWithPreserialize, genInfo); @@ -388,6 +403,13 @@ int GeneratorToolMain(int argc, char ** argv) return EXIT_FAILURE; } + if (!FLAGS_streets_key_value.empty()) + { + streets::GenerateStreets(FLAGS_regions_index, FLAGS_regions_key_value, + FLAGS_streets_features, FLAGS_geo_objects_features, + FLAGS_streets_key_value, FLAGS_verbose); + } + if (!FLAGS_geo_objects_key_value.empty()) { if (!geo_objects::GenerateGeoObjects(FLAGS_regions_index, FLAGS_regions_key_value, diff --git a/generator/geo_objects/geo_object_info_getter.hpp b/generator/geo_objects/geo_object_info_getter.hpp index 23a0a8e051..f922f910d1 100644 --- a/generator/geo_objects/geo_object_info_getter.hpp +++ b/generator/geo_objects/geo_object_info_getter.hpp @@ -1,6 +1,6 @@ #pragma once -#include "generator/geo_objects/key_value_storage.hpp" +#include "generator/key_value_storage.hpp" #include "indexer/locality_index.hpp" diff --git a/generator/geo_objects/geo_objects.cpp b/generator/geo_objects/geo_objects.cpp index 4a085d83d6..46471ddf24 100644 --- a/generator/geo_objects/geo_objects.cpp +++ b/generator/geo_objects/geo_objects.cpp @@ -4,11 +4,10 @@ #include "generator/feature_generator.hpp" #include "generator/geo_objects/geo_object_info_getter.hpp" #include "generator/geo_objects/geo_objects_filter.hpp" -#include "generator/geo_objects/key_value_storage.hpp" -#include "generator/geo_objects/region_info_getter.hpp" -#include "generator/geo_objects/streets_builder.hpp" +#include "generator/key_value_storage.hpp" #include "generator/locality_sorter.hpp" #include "generator/regions/region_base.hpp" +#include "generator/regions/region_info_getter.hpp" #include "indexer/classificator.hpp" #include "indexer/ftypes_matcher.hpp" @@ -136,7 +135,7 @@ MakeTempGeoObjectsIndex(std::string const & pathToGeoObjectsTmpMwm) void FilterAddresslessByCountryAndRepackMwm(std::string const & pathInGeoObjectsTmpMwm, std::string_view const & includeCountries, - RegionInfoGetter const & regionInfoGetter) + regions::RegionInfoGetter const & regionInfoGetter) { auto const path = Platform().TmpPathForFile(); feature::FeaturesCollector collector(path); @@ -168,13 +167,13 @@ void FilterAddresslessByCountryAndRepackMwm(std::string const & pathInGeoObjects LOG(LERROR, ("Error: Cannot rename", path, "to", pathInGeoObjectsTmpMwm)); } -void BuildGeoObjectsWithAddresses(RegionInfoGetter const & regionInfoGetter, +void BuildGeoObjectsWithAddresses(regions::RegionInfoGetter const & regionInfoGetter, std::string const & pathInGeoObjectsTmpMwm, std::ostream & streamGeoObjectsKv, bool) { size_t countGeoObjects = 0; auto const fn = [&](FeatureBuilder1 & fb, uint64_t /* currPos */) { - if (!(GeoObjectsFilter::IsBuilding(fb) || GeoObjectsFilter::HasHouse(fb))) + if (!GeoObjectsFilter::IsBuilding(fb) && !GeoObjectsFilter::HasHouse(fb)) return; auto regionKeyValue = regionInfoGetter.FindDeepest(fb.GetKeyPoint()); @@ -200,7 +199,7 @@ void BuildGeoObjectsWithoutAddresses(GeoObjectInfoGetter const & geoObjectInfoGe auto const fn = [&](FeatureBuilder1 & fb, uint64_t /* currPos */) { if (!GeoObjectsFilter::IsPoi(fb)) return; - if (GeoObjectsFilter::IsBuilding(fb) || GeoObjectsFilter::HasHouse(fb) || GeoObjectsFilter::IsStreet(fb)) + if (GeoObjectsFilter::IsBuilding(fb) || GeoObjectsFilter::HasHouse(fb)) return; auto const house = FindHousePoi(fb, geoObjectInfoGetter); @@ -217,14 +216,6 @@ void BuildGeoObjectsWithoutAddresses(GeoObjectInfoGetter const & geoObjectInfoGe feature::ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, fn); LOG(LINFO, ("Added ", countGeoObjects, "geo objects without addresses.")); } - -void BuildStreets(RegionInfoGetter const & regionInfoGetter, - std::string const & pathInGeoObjectsTmpMwm, - std::ostream & streamGeoObjectsKv, bool /* verbose */) -{ - StreetsBuilder streetsBuilder{regionInfoGetter}; - streetsBuilder.Build(pathInGeoObjectsTmpMwm, streamGeoObjectsKv); -} } // namespace bool GenerateGeoObjects(std::string const & pathInRegionsIndex, @@ -240,7 +231,7 @@ bool GenerateGeoObjects(std::string const & pathInRegionsIndex, LOG(LINFO, ("Finish generating geo objects.", timer.ElapsedSeconds(), "seconds.")); }); - RegionInfoGetter regionInfoGetter{pathInRegionsIndex, pathInRegionsKv}; + regions::RegionInfoGetter regionInfoGetter{pathInRegionsIndex, pathInRegionsKv}; LOG(LINFO, ("Size of regions key-value storage:", regionInfoGetter.GetStorage().Size())); if (allowAddresslessForCountries != "*") @@ -255,8 +246,6 @@ bool GenerateGeoObjects(std::string const & pathInRegionsIndex, pathInGeoObjectsTmpMwm); std::ofstream streamGeoObjectsKv(pathOutGeoObjectsKv); - BuildStreets(regionInfoGetter, pathInGeoObjectsTmpMwm, streamGeoObjectsKv, verbose); - LOG(LINFO, ("Streets were built.")); BuildGeoObjectsWithAddresses(regionInfoGetter, pathInGeoObjectsTmpMwm, streamGeoObjectsKv, verbose); LOG(LINFO, ("Geo objects with addresses were built.")); diff --git a/generator/geo_objects/geo_objects_filter.cpp b/generator/geo_objects/geo_objects_filter.cpp index dc46110e31..adfaa7cf67 100644 --- a/generator/geo_objects/geo_objects_filter.cpp +++ b/generator/geo_objects/geo_objects_filter.cpp @@ -1,6 +1,5 @@ #include "generator/geo_objects/geo_objects_filter.hpp" -#include "generator/geo_objects/streets_builder.hpp" #include "generator/osm_element_helpers.hpp" #include "indexer/ftypes_matcher.hpp" @@ -11,8 +10,7 @@ namespace geo_objects { bool GeoObjectsFilter::IsAccepted(OsmElement const & element) { - return osm_element::IsBuilding(element) || osm_element::HasHouse(element) || osm_element::IsPoi(element) || - geo_objects::StreetsBuilder::IsStreet(element); + return osm_element::IsBuilding(element) || osm_element::HasHouse(element) || osm_element::IsPoi(element); } bool GeoObjectsFilter::IsAccepted(FeatureBuilder1 const & feature) @@ -20,7 +18,7 @@ bool GeoObjectsFilter::IsAccepted(FeatureBuilder1 const & feature) if (!feature.GetParams().IsValid()) return false; - return IsBuilding(feature) || HasHouse(feature) || IsPoi(feature) || IsStreet(feature); + return IsBuilding(feature) || HasHouse(feature) || IsPoi(feature); } // static @@ -42,11 +40,5 @@ bool GeoObjectsFilter::IsPoi(FeatureBuilder1 const & fb) auto const & poiChecker = ftypes::IsPoiChecker::Instance(); return poiChecker(fb.GetTypes()); } - -// static -bool GeoObjectsFilter::IsStreet(FeatureBuilder1 const & fb) -{ - return geo_objects::StreetsBuilder::IsStreet(fb); -} } // namespace geo_objects } // namespace generator diff --git a/generator/geo_objects/geo_objects_filter.hpp b/generator/geo_objects/geo_objects_filter.hpp index 5d61dd0431..97d3d6ed1d 100644 --- a/generator/geo_objects/geo_objects_filter.hpp +++ b/generator/geo_objects/geo_objects_filter.hpp @@ -2,7 +2,6 @@ #include "generator/feature_builder.hpp" #include "generator/filter_interface.hpp" -#include "generator/intermediate_data.hpp" #include "generator/osm_element.hpp" namespace generator @@ -19,7 +18,6 @@ public: static bool IsBuilding(FeatureBuilder1 const & fb); static bool HasHouse(FeatureBuilder1 const & fb); static bool IsPoi(FeatureBuilder1 const & fb); - static bool IsStreet(FeatureBuilder1 const & fb); }; } // namespace geo_objects } // namespace generator diff --git a/generator/geo_objects/key_value_storage.cpp b/generator/key_value_storage.cpp similarity index 94% rename from generator/geo_objects/key_value_storage.cpp rename to generator/key_value_storage.cpp index 6bffaa5933..2c4271285a 100644 --- a/generator/geo_objects/key_value_storage.cpp +++ b/generator/key_value_storage.cpp @@ -1,4 +1,4 @@ -#include "generator/geo_objects/key_value_storage.hpp" +#include "generator/key_value_storage.hpp" #include "coding/reader.hpp" @@ -7,8 +7,6 @@ namespace generator { -namespace geo_objects -{ KeyValueStorage::KeyValueStorage(std::string const & path, std::function const & pred) { @@ -77,5 +75,4 @@ size_t KeyValueStorage::Size() const { return m_values.size(); } -} // namespace geo_objects } // namespace generator diff --git a/generator/geo_objects/key_value_storage.hpp b/generator/key_value_storage.hpp similarity index 95% rename from generator/geo_objects/key_value_storage.hpp rename to generator/key_value_storage.hpp index cd94124bd2..eb4947e4a8 100644 --- a/generator/geo_objects/key_value_storage.hpp +++ b/generator/key_value_storage.hpp @@ -13,8 +13,6 @@ namespace generator { -namespace geo_objects -{ using KeyValue = std::pair; class KeyValueStorage @@ -38,5 +36,4 @@ private: std::unordered_map m_values; }; -} // namespace geo_objects } // namespace generator diff --git a/generator/geo_objects/region_info_getter.cpp b/generator/regions/region_info_getter.cpp similarity index 94% rename from generator/geo_objects/region_info_getter.cpp rename to generator/regions/region_info_getter.cpp index 9ebf4dcef5..f910d0711a 100644 --- a/generator/geo_objects/region_info_getter.cpp +++ b/generator/regions/region_info_getter.cpp @@ -1,4 +1,4 @@ -#include "generator/geo_objects/region_info_getter.hpp" +#include "generator/regions/region_info_getter.hpp" #include "coding/mmap_reader.hpp" @@ -6,7 +6,7 @@ namespace generator { -namespace geo_objects +namespace regions { RegionInfoGetter::RegionInfoGetter(std::string const & indexPath, std::string const & kvPath) : m_index{indexer::ReadIndex, MmapReader>(indexPath)} @@ -84,7 +84,7 @@ int RegionInfoGetter::GetRank(base::Json const & json) const boost::optional RegionInfoGetter::GetPid(base::Json const & json) const { auto && properties = base::GetJSONObligatoryField(json.get(), "properties"); - auto && pid = base::GetJSONOptionalField(json.get(), "pid"); + auto && pid = base::GetJSONOptionalField(properties, "pid"); if (!pid || base::JSONIsNull(pid)) return {}; return static_cast(FromJSON(pid)); @@ -94,5 +94,5 @@ KeyValueStorage const & RegionInfoGetter::GetStorage() const noexcept { return m_storage; } -} // namespace geo_objects +} // namespace regions } // namespace generator diff --git a/generator/geo_objects/region_info_getter.hpp b/generator/regions/region_info_getter.hpp similarity index 92% rename from generator/geo_objects/region_info_getter.hpp rename to generator/regions/region_info_getter.hpp index 3c62304294..eabbba0e68 100644 --- a/generator/geo_objects/region_info_getter.hpp +++ b/generator/regions/region_info_getter.hpp @@ -1,6 +1,6 @@ #pragma once -#include "generator/geo_objects/key_value_storage.hpp" +#include "generator/key_value_storage.hpp" #include "indexer/borders.hpp" #include "indexer/locality_index.hpp" @@ -20,7 +20,7 @@ namespace generator { -namespace geo_objects +namespace regions { class RegionInfoGetter { @@ -47,5 +47,5 @@ private: indexer::Borders m_borders; KeyValueStorage m_storage; }; -} // namespace geo_objects +} // namespace regions } // namespace generator diff --git a/generator/streets/streets.cpp b/generator/streets/streets.cpp new file mode 100644 index 0000000000..d4ad3f142c --- /dev/null +++ b/generator/streets/streets.cpp @@ -0,0 +1,43 @@ +#include "generator/streets/streets.hpp" + +#include "generator/regions/region_info_getter.hpp" +#include "generator/streets/streets_builder.hpp" + +#include "base/logging.hpp" +#include "base/scope_guard.hpp" +#include "base/timer.hpp" + +#include + +namespace generator +{ +namespace streets +{ +void GenerateStreets(std::string const & pathInRegionsIndex, std::string const & pathInRegionsKv, + std::string const & pathInStreetsTmpMwm, + std::string const & pathInGeoObjectsTmpMwm, + std::string const & pathOutStreetsKv, bool verbose) +{ + LOG(LINFO, ("Start generating streets...")); + auto timer = base::Timer(); + SCOPE_GUARD(finishGeneratingStreets, [&timer]() { + LOG(LINFO, ("Finish generating streets.", timer.ElapsedSeconds(), "seconds.")); + }); + + regions::RegionInfoGetter regionInfoGetter{pathInRegionsIndex, pathInRegionsKv}; + LOG(LINFO, ("Size of regions key-value storage:", regionInfoGetter.GetStorage().Size())); + + StreetsBuilder streetsBuilder{regionInfoGetter}; + + streetsBuilder.AssembleStreets(pathInStreetsTmpMwm); + LOG(LINFO, ("Streets were built.")); + + streetsBuilder.AssembleBindings(pathInGeoObjectsTmpMwm); + LOG(LINFO, ("Binding's streets were built.")); + + std::ofstream streamStreetsKv(pathOutStreetsKv); + streetsBuilder.SaveStreetsKv(streamStreetsKv); + LOG(LINFO, ("Streets key-value storage saved to", pathOutStreetsKv)); +} +} // namespace streets +} // namespace generator diff --git a/generator/streets/streets.hpp b/generator/streets/streets.hpp new file mode 100644 index 0000000000..c56e6be54e --- /dev/null +++ b/generator/streets/streets.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace generator +{ +namespace streets +{ +// This function generates key-value pairs for streets. +// Streets are generated by highway features and from geo object features with addresses (houses and POI). +// Locality of street are defined through region index file and key-value pairs file of regions. +void GenerateStreets(std::string const & pathInRegionsIndex, std::string const & pathInRegionsKv, + std::string const & pathInStreetsTmpMwm, + std::string const & pathInGeoObjectsTmpMwm, + std::string const & pathOutStreetsKv, bool verbose); +} // namespace streets +} // namespace generator diff --git a/generator/geo_objects/streets_builder.cpp b/generator/streets/streets_builder.cpp similarity index 84% rename from generator/geo_objects/streets_builder.cpp rename to generator/streets/streets_builder.cpp index 813e21daca..29dce2daa1 100644 --- a/generator/geo_objects/streets_builder.cpp +++ b/generator/streets/streets_builder.cpp @@ -1,4 +1,4 @@ -#include "generator/geo_objects/streets_builder.hpp" +#include "generator/streets/streets_builder.hpp" #include "indexer/classificator.hpp" #include "indexer/ftypes_matcher.hpp" @@ -11,38 +11,38 @@ namespace generator { -namespace geo_objects +namespace streets { -StreetsBuilder::StreetsBuilder(RegionInfoGetter const & regionInfoGetter) +StreetsBuilder::StreetsBuilder(regions::RegionInfoGetter const & regionInfoGetter) : m_regionInfoGetter{regionInfoGetter} { } -void StreetsBuilder::Build(std::string const & pathInGeoObjectsTmpMwm, std::ostream & streamGeoObjectsKv) +void StreetsBuilder::AssembleStreets(std::string const & pathInStreetsTmpMwm) { - auto const transform = [this, &streamGeoObjectsKv](FeatureBuilder1 & fb, uint64_t /* currPos */) { - if (IsStreet(fb)) - { - AddStreet(fb); - return; - } + auto const transform = [this](FeatureBuilder1 & fb, uint64_t /* currPos */) { + AddStreet(fb); + }; + feature::ForEachFromDatRawFormat(pathInStreetsTmpMwm, transform); +} +void StreetsBuilder::AssembleBindings(std::string const & pathInGeoObjectsTmpMwm) +{ + auto const transform = [this](FeatureBuilder1 & fb, uint64_t /* currPos */) { auto streetName = fb.GetParams().GetStreet(); if (!streetName.empty()) AddStreetBinding(std::move(streetName), fb); }; feature::ForEachFromDatRawFormat(pathInGeoObjectsTmpMwm, transform); - - SaveStreetGeoObjects(streamGeoObjectsKv); } -void StreetsBuilder::SaveStreetGeoObjects(std::ostream & streamGeoObjectsKv) +void StreetsBuilder::SaveStreetsKv(std::ostream & streamStreetsKv) { for (auto const & region : m_regions) - SaveRegionStreetGeoObjects(streamGeoObjectsKv, region.first, region.second); + SaveRegionStreetsKv(streamStreetsKv, region.first, region.second); } -void StreetsBuilder::SaveRegionStreetGeoObjects(std::ostream & streamGeoObjectsKv, uint64_t regionId, - RegionStreets const & streets) +void StreetsBuilder::SaveRegionStreetsKv(std::ostream & streamStreetsKv, uint64_t regionId, + RegionStreets const & streets) { auto const & regionsStorage = m_regionInfoGetter.GetStorage(); auto const && regionObject = regionsStorage.Find(regionId); @@ -56,7 +56,7 @@ void StreetsBuilder::SaveRegionStreetGeoObjects(std::ostream & streamGeoObjectsK auto const id = static_cast(streetId.GetEncodedId()); auto const value = MakeStreetValue(regionId, *regionObject, street.first); - streamGeoObjectsKv << id << " " << value.get() << "\n"; + streamStreetsKv << id << " " << value.get() << "\n"; } } @@ -192,5 +192,5 @@ bool StreetsBuilder::IsStreet(FeatureBuilder1 const & fb) return false; } -} // namespace geo_objects +} // namespace streets } // namespace generator diff --git a/generator/geo_objects/streets_builder.hpp b/generator/streets/streets_builder.hpp similarity index 69% rename from generator/geo_objects/streets_builder.hpp rename to generator/streets/streets_builder.hpp index 7f5bb2a397..21ed6f2ecb 100644 --- a/generator/geo_objects/streets_builder.hpp +++ b/generator/streets/streets_builder.hpp @@ -1,9 +1,9 @@ #pragma once #include "generator/feature_builder.hpp" -#include "generator/geo_objects/key_value_storage.hpp" -#include "generator/geo_objects/region_info_getter.hpp" +#include "generator/key_value_storage.hpp" #include "generator/osm_element.hpp" +#include "generator/regions/region_info_getter.hpp" #include "coding/reader.hpp" @@ -21,14 +21,16 @@ namespace generator { -namespace geo_objects +namespace streets { class StreetsBuilder { public: - StreetsBuilder(RegionInfoGetter const & regionInfoGetter); + explicit StreetsBuilder(regions::RegionInfoGetter const & regionInfoGetter); - void Build(std::string const & pathInGeoObjectsTmpMwm, std::ostream & streamGeoObjectsKv); + void AssembleStreets(std::string const & pathInStreetsTmpMwm); + void AssembleBindings(std::string const & pathInGeoObjectsTmpMwm); + void SaveStreetsKv(std::ostream & streamStreetsKv); static bool IsStreet(OsmElement const & element); static bool IsStreet(FeatureBuilder1 const & fb); @@ -36,9 +38,8 @@ public: private: using RegionStreets = std::unordered_map; - void SaveStreetGeoObjects(std::ostream & streamGeoObjectsKv); - void SaveRegionStreetGeoObjects(std::ostream & streamGeoObjectsKv, uint64_t regionId, - RegionStreets const & streets); + void SaveRegionStreetsKv(std::ostream & streamStreetsKv, uint64_t regionId, + RegionStreets const & streets); void AddStreet(FeatureBuilder1 & fb); void AddStreetBinding(std::string && streetName, FeatureBuilder1 & fb); @@ -51,8 +52,8 @@ private: base::GeoObjectId NextOsmSurrogateId(); std::unordered_map m_regions; - RegionInfoGetter const & m_regionInfoGetter; + regions::RegionInfoGetter const & m_regionInfoGetter; uint64_t m_osmSurrogateCounter{0}; }; -} // namespace geo_objects +} // namespace streets } // namespace generator diff --git a/generator/streets/streets_filter.cpp b/generator/streets/streets_filter.cpp new file mode 100644 index 0000000000..69479e22e9 --- /dev/null +++ b/generator/streets/streets_filter.cpp @@ -0,0 +1,26 @@ +#include "generator/streets/streets_filter.hpp" + +#include "generator/streets/streets_builder.hpp" +#include "generator/osm_element_helpers.hpp" + +namespace generator +{ +namespace streets +{ +bool StreetsFilter::IsAccepted(OsmElement const & element) +{ + return StreetsBuilder::IsStreet(element); +} + +bool StreetsFilter::IsAccepted(FeatureBuilder1 const & feature) +{ + return feature.GetParams().IsValid() && IsStreet(feature); +} + +// static +bool StreetsFilter::IsStreet(FeatureBuilder1 const & fb) +{ + return StreetsBuilder::IsStreet(fb); +} +} // namespace streets +} // namespace generator diff --git a/generator/streets/streets_filter.hpp b/generator/streets/streets_filter.hpp new file mode 100644 index 0000000000..00edafc800 --- /dev/null +++ b/generator/streets/streets_filter.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "generator/feature_builder.hpp" +#include "generator/filter_interface.hpp" +#include "generator/osm_element.hpp" + +namespace generator +{ +namespace streets +{ +class StreetsFilter : public FilterInterface +{ +public: + // FilterInterface overrides: + bool IsAccepted(OsmElement const & element) override; + bool IsAccepted(FeatureBuilder1 const & feature) override; + + static bool IsStreet(FeatureBuilder1 const & fb); +}; +} // namespace streets +} // namespace generator diff --git a/generator/translator_factory.hpp b/generator/translator_factory.hpp index 0f1dd016b0..1bb10af39d 100644 --- a/generator/translator_factory.hpp +++ b/generator/translator_factory.hpp @@ -3,6 +3,7 @@ #include "generator/factory_utils.hpp" #include "generator/translator_coastline.hpp" #include "generator/translator_country.hpp" +#include "generator/translator_streets.hpp" #include "generator/translator_geo_objects.hpp" #include "generator/translator_interface.hpp" #include "generator/translator_region.hpp" @@ -18,6 +19,7 @@ namespace generator enum class TranslatorType { Regions, + Streets, GeoObjects, Country, Coastline, @@ -35,6 +37,8 @@ std::shared_ptr CreateTranslator(TranslatorType type, Args& return create(std::forward(args)...); case TranslatorType::Regions: return create(std::forward(args)...); + case TranslatorType::Streets: + return create(std::forward(args)...); case TranslatorType::GeoObjects: return create(std::forward(args)...); case TranslatorType::World: diff --git a/generator/translator_streets.cpp b/generator/translator_streets.cpp new file mode 100644 index 0000000000..b5f43c18de --- /dev/null +++ b/generator/translator_streets.cpp @@ -0,0 +1,16 @@ +#include "generator/translator_streets.hpp" + +#include "generator/feature_maker.hpp" +#include "generator/streets/streets_filter.hpp" +#include "generator/intermediate_data.hpp" + +namespace generator +{ +TranslatorStreets::TranslatorStreets(std::shared_ptr emitter, + cache::IntermediateDataReader & cache) + : Translator(emitter, cache, std::make_shared(cache)) + +{ + AddFilter(std::make_shared()); +} +} // namespace generator diff --git a/generator/translator_streets.hpp b/generator/translator_streets.hpp new file mode 100644 index 0000000000..b34f38f9c4 --- /dev/null +++ b/generator/translator_streets.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "generator/emitter_interface.hpp" +#include "generator/translator.hpp" + +#include + +namespace cache +{ +class IntermediateDataReader; +} // namespace cache + +namespace generator +{ +// The TranslatorStreets class implements translator for streets. +// Every Street is either a highway or a place=square. +class TranslatorStreets : public Translator +{ +public: + explicit TranslatorStreets(std::shared_ptr emitter, + cache::IntermediateDataReader & cache); +}; +} // namespace generator