MCPcopy Create free account
hub / github.com/comaps/comaps / GetPostcodes

Function GetPostcodes

generator/postcode_points_builder.cpp:47–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45using ZipIndexValue = std::pair<strings::UniString, Uint64IndexValue>;
46
47void GetPostcodes(std::string const & filename, storage::CountryId const & countryId, FieldIndices const & fieldIndices,
48 char const * separator, bool hasHeader, storage::CountryInfoGetter const & infoGetter,
49 std::vector<m2::PointD> & valueMapping, std::vector<ZipIndexValue> & keyValuePairs)
50{
51 ASSERT(!filename.empty(), ());
52 std::ifstream data(filename);
53 if (!data.is_open())
54 {
55 LOG(LERROR, ("Can't open postcodes file:", filename));
56 return;
57 }
58
59 std::string line;
60
61 if (hasHeader && !std::getline(data, line))
62 return;
63
64 while (std::getline(data, line))
65 {
66 std::vector<std::string_view> fields;
67 strings::Tokenize(std::string_view(line), separator, [&fields](std::string_view v)
68 {
69 strings::Trim(v, "\" ");
70 // Maybe empty, checks below should work for actual values.
71 fields.push_back(v);
72 });
73 CHECK_GREATER_OR_EQUAL(fields.size(), fieldIndices.m_datasetCount, (line));
74
75 double lat;
76 CHECK(strings::to_double(fields[fieldIndices.m_latIndex], lat), (line));
77
78 double lon;
79 CHECK(strings::to_double(fields[fieldIndices.m_longIndex], lon), (line));
80
81 auto const p = mercator::FromLatLon(lat, lon);
82
83 std::vector<storage::CountryId> countries;
84 infoGetter.GetRegionsCountryId(p, countries, 200.0 /* lookupRadiusM */);
85 if (std::find(countries.begin(), countries.end(), countryId) == countries.end())
86 continue;
87
88 keyValuePairs.emplace_back(search::NormalizeAndSimplifyString(fields[fieldIndices.m_postcodeIndex]),
89 valueMapping.size());
90 valueMapping.push_back(p);
91 }
92}
93
94void GetUKPostcodes(std::string const & filename, storage::CountryId const & countryId,
95 storage::CountryInfoGetter const & infoGetter, std::vector<m2::PointD> & valueMapping,

Callers 2

GetUKPostcodesFunction · 0.85
GetUSPostcodesFunction · 0.85

Calls 14

ASSERTFunction · 0.85
TrimFunction · 0.85
findFunction · 0.85
GetRegionsCountryIdMethod · 0.80
FromLatLonFunction · 0.70
TokenizeFunction · 0.50
to_doubleFunction · 0.50
emptyMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected