forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollector_boundary_postcode.cpp
75 lines (59 loc) · 2.12 KB
/
collector_boundary_postcode.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "generator/collector_boundary_postcode.hpp"
#include "generator/feature_builder.hpp"
#include "generator/intermediate_data.hpp"
#include "platform/platform.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/read_write_utils.hpp"
#include "coding/string_utf8_multilang.hpp"
#include "base/assert.hpp"
using namespace feature;
namespace generator
{
BoundaryPostcodeCollector::BoundaryPostcodeCollector(
std::string const & filename, std::shared_ptr<cache::IntermediateDataReaderInterface> const & cache)
: CollectorInterface(filename)
, m_writer(std::make_unique<FileWriter>(GetTmpFilename()))
, m_cache(cache)
, m_featureMakerSimple(cache)
{
}
std::shared_ptr<CollectorInterface> BoundaryPostcodeCollector::Clone(
std::shared_ptr<cache::IntermediateDataReaderInterface> const & cache) const
{
return std::make_shared<BoundaryPostcodeCollector>(GetFilename(), cache ? cache : m_cache);
}
void BoundaryPostcodeCollector::Collect(OsmElement const & el)
{
if (el.m_type != OsmElement::EntityType::Relation)
return;
if (!el.HasTag("boundary", "postal_code"))
return;
auto const postcode = el.GetTag("postal_code");
if (postcode.empty())
return;
auto osmElementCopy = el;
feature::FeatureBuilder feature;
m_featureMakerSimple.Add(osmElementCopy);
while (m_featureMakerSimple.GetNextFeature(feature))
{
utils::WriteString(*m_writer, postcode);
rw::WriteVectorOfPOD(*m_writer, feature.GetOuterGeometry());
}
}
void BoundaryPostcodeCollector::Finish() { m_writer.reset(); }
void BoundaryPostcodeCollector::Save()
{
CHECK(!m_writer, ("Finish() has not been called."));
if (Platform::IsFileExistsByFullPath(GetTmpFilename()))
CHECK(base::CopyFileX(GetTmpFilename(), GetFilename()), ());
}
void BoundaryPostcodeCollector::Merge(generator::CollectorInterface const & collector)
{
collector.MergeInto(*this);
}
void BoundaryPostcodeCollector::MergeInto(BoundaryPostcodeCollector & collector) const
{
CHECK(!m_writer || !collector.m_writer, ("Finish() has not been called."));
base::AppendFileToFile(GetTmpFilename(), collector.GetTmpFilename());
}
} // namespace generator