[generator] Preparing for generation 'osm only'

This commit is contained in:
Maksim Andrianov 2019-05-07 11:49:47 +03:00 committed by mpimenov
parent 58d86f929f
commit 265a12dd73
7 changed files with 48 additions and 11 deletions

View file

@ -112,6 +112,7 @@ DEFINE_uint64(planet_version, base::SecondsSinceEpoch(),
// Preprocessing and feature generator.
DEFINE_bool(preprocess, false, "1st pass - create nodes/ways/relations data.");
DEFINE_bool(generate_features, false, "2nd pass - generate intermediate features.");
DEFINE_bool(no_ads, false, "generation without ads.");
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,
@ -332,7 +333,8 @@ int GeneratorToolMain(int argc, char ** argv)
if (FLAGS_generate_features)
{
auto emitter = CreateEmitter(EmitterType::Country, genInfo);
translators.Append(CreateTranslator(TranslatorType::Country, emitter, cacheLoader.GetCache(), genInfo));
auto const translatorType = FLAGS_no_ads ? TranslatorType::Country : TranslatorType::CountryWithAds;
translators.Append(CreateTranslator(translatorType, emitter, cacheLoader.GetCache(), genInfo));
}
if (FLAGS_generate_world)

View file

@ -7,7 +7,7 @@ using namespace std;
namespace generator
{
void MixFakeNodes(istream & stream, function<void(OsmElement *)> processor)
void MixFakeNodes(istream & stream, function<void(OsmElement &)> processor)
{
if (stream.fail())
return;
@ -31,7 +31,7 @@ void MixFakeNodes(istream & stream, function<void(OsmElement *)> processor)
{
if (completionFlag == kCFAll)
{
processor(&p);
processor(p);
count++;
p.Clear();
p.id = baseNodeId + count;
@ -69,7 +69,7 @@ void MixFakeNodes(istream & stream, function<void(OsmElement *)> processor)
if (completionFlag == kCFAll)
{
processor(&p);
processor(p);
count++;
}

View file

@ -8,9 +8,9 @@
namespace generator
{
void MixFakeNodes(std::istream & stream, std::function<void(OsmElement *)> processor);
void MixFakeNodes(std::istream & stream, std::function<void(OsmElement &)> processor);
inline void MixFakeNodes(std::string const filePath, std::function<void(OsmElement *)> processor)
inline void MixFakeNodes(std::string const filePath, std::function<void(OsmElement &)> processor)
{
std::ifstream stream(filePath);
MixFakeNodes(stream, processor);

View file

@ -1,7 +1,6 @@
#include "generator/osm_source.hpp"
#include "generator/intermediate_elements.hpp"
#include "generator/node_mixer.hpp"
#include "generator/osm_element.hpp"
#include "generator/osm_o5m_source.hpp"
#include "generator/osm_xml_source.hpp"
@ -18,6 +17,7 @@
#include "coding/file_name_utils.hpp"
#include "coding/parse_xml.hpp"
#include <fstream>
#include <memory>
#include <set>
@ -224,7 +224,6 @@ bool GenerateRaw(feature::GenerateInfo & info, TranslatorInterface & translators
}
LOG(LINFO, ("Processing", info.m_osmFileName, "done."));
MixFakeNodes(GetPlatform().ResourcesDir() + MIXED_NODES_FILE, fn);
if (!translators.Finish())
return false;

View file

@ -11,6 +11,7 @@
#include "generator/intermediate_data.hpp"
#include "generator/maxspeeds_collector.hpp"
#include "generator/metalines_builder.hpp"
#include "generator/node_mixer.hpp"
#include "generator/restriction_writer.hpp"
#include "generator/road_access_generator.hpp"
@ -74,7 +75,6 @@ TranslatorCountry::TranslatorCountry(std::shared_ptr<EmitterInterface> emitter,
: Translator(emitter, cache, std::make_shared<FeatureMaker>(cache))
, m_tagAdmixer(info.GetIntermediateFileName("ways", ".csv"), info.GetIntermediateFileName("towns", ".csv"))
, m_tagReplacer(base::JoinPath(GetPlatform().ResourcesDir(), REPLACED_TAGS_FILE))
, m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE))
{
AddFilter(std::make_shared<FilterPlanet>());
AddFilter(std::make_shared<FilterElements>(base::JoinPath(GetPlatform().ResourcesDir(), SKIPPED_ELEMENTS_FILE)));
@ -97,8 +97,6 @@ void TranslatorCountry::Preprocess(OsmElement & element)
{
// Here we can add new tags to the elements!
m_tagReplacer(element);
m_tagAdmixer(element);
m_osmTagMixer(element);
CollectFromRelations(element);
}
@ -110,4 +108,24 @@ void TranslatorCountry::CollectFromRelations(OsmElement const & element)
else if (element.IsWay())
m_cache.ForEachRelationByWayCached(element.id, collector);
}
TranslatorCountryWithAds::TranslatorCountryWithAds(std::shared_ptr<EmitterInterface> emitter,
cache::IntermediateDataReader & cache,
feature::GenerateInfo const & info)
: TranslatorCountry(emitter, cache, info)
, m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE)) {}
void TranslatorCountryWithAds::Preprocess(OsmElement & element)
{
// Here we can add new tags to the elements!
m_osmTagMixer(element);
TranslatorCountry::Preprocess(element);
}
bool TranslatorCountryWithAds::Finish()
{
MixFakeNodes(GetPlatform().ResourcesDir() + MIXED_NODES_FILE,
std::bind(&TranslatorCountryWithAds::Emit, this, std::placeholders::_1));
return TranslatorCountry::Finish();
}
} // namespace generator

View file

@ -33,6 +33,21 @@ private:
TagAdmixer m_tagAdmixer;
TagReplacer m_tagReplacer;
};
// The TranslatorCountryWithAds class implements translator for building countries with advertising.
class TranslatorCountryWithAds : public TranslatorCountry
{
public:
explicit TranslatorCountryWithAds(std::shared_ptr<EmitterInterface> emitter,
cache::IntermediateDataReader & cache,
feature::GenerateInfo const & info);
// TranslatorInterface overrides:
void Preprocess(OsmElement & element) override;
bool Finish() override;
private:
OsmTagMixer m_osmTagMixer;
};
} // namespace generator

View file

@ -22,6 +22,7 @@ enum class TranslatorType
Streets,
GeoObjects,
Country,
CountryWithAds,
Coastline,
World
};
@ -35,6 +36,8 @@ std::shared_ptr<TranslatorInterface> CreateTranslator(TranslatorType type, Args&
return create<TranslatorCoastline>(std::forward<Args>(args)...);
case TranslatorType::Country:
return create<TranslatorCountry>(std::forward<Args>(args)...);
case TranslatorType::CountryWithAds:
return create<TranslatorCountryWithAds>(std::forward<Args>(args)...);
case TranslatorType::Regions:
return create<TranslatorRegion>(std::forward<Args>(args)...);
case TranslatorType::Streets: