Optimization step 'generate_features': Old code support.

This commit is contained in:
Maksim Andrianov 2019-07-02 18:06:10 +03:00 committed by Tatiana Yan
parent 123cb09d2a
commit d4c6d29cb2
2 changed files with 17 additions and 9 deletions

View file

@ -73,6 +73,9 @@ public:
});
}
// TODO(maksimandrianov): Remove it, after removing Polygonizer class.
mutable int32_t m_index = -1;
private:
std::string m_name;
RegionsContainer m_regions;
@ -101,6 +104,13 @@ public:
return m_regions.count(name) != 0;
}
// TODO(maksimandrianov): Remove it, after removing Polygonizer class.
void Add(CountryPolygons const & country, m2::RectD const & rect)
{
m_regions.emplace(country.GetName(), country);
m_regionsTree.Add(country, rect);
}
CountryPolygons const & GetRegionByName(std::string const & name) const
{
return m_regions.at(name);

View file

@ -31,11 +31,12 @@ public:
{
// Insert fake country polygon equal to whole world to
// create only one output file which contains all features.
borders::RegionsContainer regions;
auto const rect = MercatorBounds::FullRect();
auto countries = borders::CountryPolygons(info.m_fileName);
std::vector<m2::PointD> points {rect.LeftBottom(), rect.LeftTop(), rect.RightTop(),
rect.RightBottom(), rect.LeftBottom()};
countries.m_regions.Add(m2::RegionD(std::move(points)), rect);
regions.Add(m2::RegionD(std::move(points)), rect);
auto countries = borders::CountryPolygons(info.m_fileName, regions);
m_countries.Add(std::move(countries), rect);
}
}
@ -49,10 +50,7 @@ public:
{
m_countries.ForEachInRect(fb.GetLimitRect(), [&](auto const & countryPolygons) {
auto const need = fb.ForAnyGeometryPoint([&](auto const & point) {
auto const & regions = countryPolygons.m_regions;
return regions.ForAnyInRect(m2::RectD(point, point), [&](auto const & rgn) {
return rgn.Contains(point);
});
return countryPolygons.Contains(point);
});
if (need)
@ -73,15 +71,15 @@ public:
{
if (countryPolygons.m_index == -1)
{
m_names.push_back(countryPolygons.m_name);
m_buckets.emplace_back(new FeatureOut(m_info.GetTmpFileName(countryPolygons.m_name)));
m_names.push_back(countryPolygons.GetName());
m_buckets.emplace_back(new FeatureOut(m_info.GetTmpFileName(countryPolygons.GetName())));
countryPolygons.m_index = static_cast<int>(m_buckets.size()) - 1;
}
if (!m_currentNames.empty())
m_currentNames += ';';
m_currentNames += countryPolygons.m_name;
m_currentNames += countryPolygons.GetName();
m_buckets[countryPolygons.m_index]->Collect(fb);
}