mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-23 14:43:43 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
62
generator/boundary_postcodes_enricher.cpp
Normal file
62
generator/boundary_postcodes_enricher.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "generator/boundary_postcodes_enricher.hpp"
|
||||
|
||||
#include "indexer/ftypes_matcher.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include "coding/read_write_utils.hpp"
|
||||
|
||||
#include "geometry/point2d.hpp"
|
||||
|
||||
namespace generator
|
||||
{
|
||||
BoundaryPostcodesEnricher::BoundaryPostcodesEnricher(std::string const & boundaryPostcodesFilename)
|
||||
{
|
||||
// May be absent for tests because TestMwmBuilder cannot collect data from osm elements.
|
||||
if (!Platform::IsFileExistsByFullPath(boundaryPostcodesFilename))
|
||||
return;
|
||||
|
||||
FileReader reader(boundaryPostcodesFilename);
|
||||
ReaderSource<FileReader> src(reader);
|
||||
|
||||
while (src.Size() > 0)
|
||||
{
|
||||
std::string postcode;
|
||||
utils::ReadString(src, postcode);
|
||||
std::vector<m2::PointD> geometry;
|
||||
rw::ReadVectorOfPOD(src, geometry);
|
||||
CHECK(!postcode.empty() && !geometry.empty(), ());
|
||||
|
||||
m_boundaryPostcodes.emplace_back(std::move(postcode), std::move(geometry));
|
||||
m_boundariesTree.Add(m_boundaryPostcodes.size() - 1,
|
||||
m_boundaryPostcodes.back().second.GetRect());
|
||||
}
|
||||
}
|
||||
|
||||
void BoundaryPostcodesEnricher::Enrich(feature::FeatureBuilder & fb) const
|
||||
{
|
||||
auto & params = fb.GetParams();
|
||||
if (!params.GetPostcode().empty() || !ftypes::IsAddressObjectChecker::Instance()(fb.GetTypes()))
|
||||
return;
|
||||
|
||||
auto const hasName = !fb.GetMultilangName().IsEmpty();
|
||||
auto const hasHouseNumber = !params.house.IsEmpty();
|
||||
|
||||
// We do not save postcodes for unnamed features without house number to reduce amount of data.
|
||||
// For example with this filter we have +100Kb for Turkey_Marmara Region_Istanbul.mwm, without
|
||||
// filter we have +3Mb because of huge amount of unnamed houses without number.
|
||||
if (!hasName && !hasHouseNumber)
|
||||
return;
|
||||
|
||||
auto const center = fb.GetKeyPoint();
|
||||
m_boundariesTree.ForAnyInRect(m2::RectD(center, center), [&](size_t i)
|
||||
{
|
||||
CHECK_LESS(i, m_boundaryPostcodes.size(), ());
|
||||
if (!m_boundaryPostcodes[i].second.Contains(center))
|
||||
return false;
|
||||
|
||||
params.SetPostcode(m_boundaryPostcodes[i].first);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
} // namespace generator
|
||||
Reference in New Issue
Block a user