Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ugc_section_builder.cpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6641bf1b7f3a3b2d4d20d91b742eaaec17fcf16d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "generator/ugc_section_builder.hpp"

#include "generator/ugc_translator.hpp"
#include "generator/utils.hpp"

#include "ugc/binary/index_ugc.hpp"
#include "ugc/binary/serdes.hpp"

#include "indexer/feature_data.hpp"
#include "indexer/feature_processor.hpp"

#include "base/geo_object_id.hpp"

#include <unordered_map>
#include <utility>
#include <vector>

namespace generator
{
bool BuildUgcMwmSection(std::string const & srcDbFilename, std::string const & mwmFile,
                        std::string const & osmToFeatureFilename)
{
  using ugc::binary::IndexUGC;

  LOG(LINFO, ("Build UGC section"));

  std::unordered_map<uint32_t, base::GeoObjectId> featureToOsmId;
  if (!ParseFeatureIdToOsmIdMapping(osmToFeatureFilename, featureToOsmId))
    return false;

  UGCTranslator translator(srcDbFilename);

  std::vector<IndexUGC> content;

  feature::ForEachFromDat(mwmFile, [&](FeatureType & f, uint32_t featureId) {
    auto const it = featureToOsmId.find(featureId);
    // Non-OSM features (coastlines, sponsored objects) are not used.
    if (it == featureToOsmId.cend())
      return;

    ugc::UGC result;
    if (!GetUgcForFeature(it->second, feature::TypesHolder(f), translator, result))
      return;

    content.emplace_back(featureId, result);
  });

  if (content.empty())
    return true;

  FilesContainerW cont(mwmFile, FileWriter::OP_WRITE_EXISTING);
  FileWriter writer = cont.GetWriter(UGC_FILE_TAG);
  ugc::binary::UGCSeriaizer serializer(std::move(content));
  serializer.Serialize(writer);

  return true;
}
}  // namespace generator