[generator:regions] Write path of object's lagest region into KV

This commit is contained in:
Anatoly Serdtcev 2019-07-25 13:20:49 +03:00 committed by Maksim Andrianov
parent 95e77d71c3
commit fd3620978d
2 changed files with 31 additions and 5 deletions

View file

@ -158,6 +158,9 @@ private:
size_t countryRegionsCount = 0;
size_t countryObjectCount = 0;
std::vector<base::GeoObjectId> objectsOrder;
std::map<base::GeoObjectId, NodePath> objectsPaths;
for (auto const & tree : outers)
{
if (m_verbose)
@ -168,6 +171,7 @@ private:
auto const & region = node->GetData();
auto const & objectId = region.GetId();
auto const & regionCountryEmplace = m_regionsCountries.emplace(objectId, country);
bool firstRegionOfObject = regionCountryEmplace.second;
if (!regionCountryEmplace.second && regionCountryEmplace.first->second != country)
{
LOG(LWARNING, ("Failed to place", GetLabel(region.GetLevel()), "region", objectId, "(",
@ -178,20 +182,42 @@ private:
m_objectsRegions.emplace(objectId, node);
++countryRegionsCount;
if (regionCountryEmplace.second)
if (firstRegionOfObject)
{
m_regionsKv << KeyValueStorage::SerializeDref(objectId.GetEncodedId()) << " "
<< KeyValueStorage::Serialize(BuildRegionValue(path)) << "\n";
objectsOrder.push_back(objectId);
++countryObjectCount;
}
auto pathEmplace = objectsPaths.emplace(objectId, path);
if (!pathEmplace.second)
{
auto & objectMaxRegionPath = pathEmplace.first->second;
auto & objectMaxRegion = objectMaxRegionPath.back()->GetData();
if (RegionsBuilder::IsAreaLessRely(objectMaxRegion, region))
objectMaxRegionPath = path;
}
});
}
WriteObjectsInKv(objectsOrder, objectsPaths);
LOG(LINFO, ("Country regions of", *country, "has built:", countryRegionsCount, "total regions.",
countryObjectCount, "objects."));
}
void WriteObjectsInKv(std::vector<base::GeoObjectId> const & objectsOrder,
std::map<base::GeoObjectId, NodePath> const & objectsPaths)
{
for (auto const & objectId : objectsOrder)
{
auto pathIter = objectsPaths.find(objectId);
CHECK(pathIter != objectsPaths.end(), ());
auto const & path = pathIter->second;
m_regionsKv << KeyValueStorage::SerializeDref(objectId.GetEncodedId()) << " "
<< KeyValueStorage::Serialize(BuildRegionValue(path)) << "\n";
}
}
std::tuple<RegionsBuilder::Regions, PlacePointsMap> ReadDatasetFromTmpMwm(
std::string const & tmpMwmFilename, RegionInfo & collector)
{

View file

@ -36,6 +36,7 @@ public:
// Return: 0 - no relation, 1 - |l| contains |r|, -1 - |r| contains |l|.
static int CompareAffiliation(LevelRegion const & l, LevelRegion const & r,
CountrySpecifier const & countrySpecifier);
static bool IsAreaLessRely(Region const & l, Region const & r);
private:
static constexpr double kAreaRelativeErrorPercent = 0.1;
@ -59,7 +60,6 @@ private:
std::vector<Node::Ptr>::const_reverse_iterator forItem) const;
static void InsertIntoSubtree(Node::Ptr & subtree, Node::Ptr && newNode,
CountrySpecifier const & countrySpecifier);
static bool IsAreaLessRely(Region const & l, Region const & r);
Regions m_countriesOuters;
Regions m_regionsInAreaOrder;