forked from organicmaps/organicmaps
[geocoder] Add option to index nodes without address.
This commit is contained in:
parent
c2a9e4855d
commit
25630686bd
3 changed files with 47 additions and 8 deletions
|
@ -101,6 +101,9 @@ DEFINE_bool(generate_world, false, "Generate separate world file.");
|
|||
DEFINE_bool(split_by_polygons, false,
|
||||
"Use countries borders to split planet by regions and countries.");
|
||||
|
||||
DEFINE_string(nodes_list_path, "",
|
||||
"Path to file containing list of node ids we need to add to locality index. May be empty.");
|
||||
|
||||
// Routing.
|
||||
DEFINE_bool(make_routing_index, false, "Make sections with the routing information.");
|
||||
DEFINE_bool(make_cross_mwm, false,
|
||||
|
@ -274,7 +277,7 @@ int main(int argc, char ** argv)
|
|||
|
||||
auto const locDataFile = my::JoinPath(path, FLAGS_output + LOC_DATA_FILE_EXTENSION);
|
||||
auto const outFile = my::JoinPath(path, FLAGS_output + LOC_IDX_FILE_EXTENSION);
|
||||
if (!feature::GenerateLocalityData(genInfo.m_tmpDir, locDataFile))
|
||||
if (!feature::GenerateLocalityData(genInfo.m_tmpDir, FLAGS_nodes_list_path, locDataFile))
|
||||
{
|
||||
LOG(LCRITICAL, ("Error generating locality data."));
|
||||
return -1;
|
||||
|
|
|
@ -18,11 +18,15 @@
|
|||
#include "base/assert.hpp"
|
||||
#include "base/logging.hpp"
|
||||
#include "base/scope_guard.hpp"
|
||||
#include "base/string_utils.hpp"
|
||||
#include "base/timer.hpp"
|
||||
|
||||
#include "defines.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
using namespace feature;
|
||||
|
@ -66,9 +70,6 @@ public:
|
|||
|
||||
void operator()(FeatureBuilder2 & fb)
|
||||
{
|
||||
if (!fb.IsLocalityObject())
|
||||
return;
|
||||
|
||||
// Do not limit inner triangles number to save all geometry without additional sections.
|
||||
GeometryHolder holder(fb, m_header, numeric_limits<uint32_t>::max() /* maxTrianglesNumber */);
|
||||
|
||||
|
@ -124,16 +125,44 @@ FeatureBuilder2 & GetFeatureBuilder2(FeatureBuilder1 & fb)
|
|||
|
||||
namespace feature
|
||||
{
|
||||
bool GenerateLocalityData(string const & featuresDir, string const & dataFilePath)
|
||||
bool GenerateLocalityData(string const & featuresDir, string const & nodesFile,
|
||||
string const & dataFile)
|
||||
{
|
||||
DataHeader header;
|
||||
header.SetCodingParams(serial::CodingParams());
|
||||
header.SetScales({scales::GetUpperScale()});
|
||||
|
||||
set<uint64_t> nodeIds;
|
||||
if (!nodesFile.empty())
|
||||
{
|
||||
ifstream stream(nodesFile);
|
||||
if (!stream)
|
||||
{
|
||||
LOG(LERROR, ("Could not open", nodesFile));
|
||||
return false;
|
||||
}
|
||||
|
||||
string line;
|
||||
size_t lineNumber = 1;
|
||||
while (getline(stream, line))
|
||||
{
|
||||
strings::SimpleTokenizer iter(line, " ");
|
||||
uint64_t nodeId;
|
||||
if (!iter || !strings::to_uint64(*iter, nodeId))
|
||||
{
|
||||
LOG(LERROR, ("Error while parsing node id at line", lineNumber, "Line contents:", line));
|
||||
return false;
|
||||
}
|
||||
|
||||
nodeIds.insert(nodeId);
|
||||
++lineNumber;
|
||||
}
|
||||
}
|
||||
|
||||
// Transform features from raw format to LocalityObject format.
|
||||
try
|
||||
{
|
||||
LocalityCollector collector(dataFilePath, header,
|
||||
LocalityCollector collector(dataFile, header,
|
||||
static_cast<uint32_t>(my::SecondsSinceEpoch()));
|
||||
|
||||
Platform::FilesList files;
|
||||
|
@ -159,7 +188,12 @@ bool GenerateLocalityData(string const & featuresDir, string const & dataFilePat
|
|||
FeatureBuilder1 f;
|
||||
ReadFromSourceRowFormat(src, f);
|
||||
// Emit object.
|
||||
collector(GetFeatureBuilder2(f));
|
||||
auto & fb2 = GetFeatureBuilder2(f);
|
||||
if (fb2.IsLocalityObject() ||
|
||||
(!fb2.GetOsmIds().empty() && nodeIds.count(fb2.GetMostGenericOsmId().EncodedId()) != 0))
|
||||
{
|
||||
collector(fb2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ namespace feature
|
|||
{
|
||||
/// Generates data for LocalityIndexBuilder from input feature-dat-files.
|
||||
/// @param featuresDir - path to folder with pregenerated features data;
|
||||
/// @param nodesFile - path to file with list of node ids we need to add to output;
|
||||
/// @param out - output file name;
|
||||
bool GenerateLocalityData(std::string const & featuresDir, std::string const & out);
|
||||
bool GenerateLocalityData(std::string const & featuresDir, std::string const & nodesFile,
|
||||
std::string const & out);
|
||||
} // namespace feature
|
||||
|
|
Loading…
Add table
Reference in a new issue