forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[indexer][generator][editor] Return postcodes to metadata.
- Loading branch information
1 parent
12021ce
commit dd24ed3
Showing
31 changed files
with
139 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "generator/boundary_postcodes_enricher.hpp" | ||
|
||
#include "indexer/ftypes_matcher.hpp" | ||
|
||
#include "platform/platform.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)) | ||
{ | ||
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); | ||
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 | ||
{ | ||
if (!ftypes::IsAddressObjectChecker::Instance()(fb.GetTypes())) | ||
return; | ||
|
||
auto const hasName = !fb.GetMultilangName().IsEmpty(); | ||
|
||
auto const hasHouseNumber = !fb.GetParams().house.Get().empty(); | ||
|
||
// 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; | ||
|
||
fb.GetMetadata().Set(feature::Metadata::FMD_POSTCODE, m_boundaryPostcodes[i].first); | ||
return true; | ||
}); | ||
} | ||
} // namespace generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "generator/feature_builder.hpp" | ||
|
||
#include "geometry/region2d.hpp" | ||
#include "geometry/tree4d.hpp" | ||
|
||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace generator | ||
{ | ||
class BoundaryPostcodesEnricher | ||
{ | ||
public: | ||
explicit BoundaryPostcodesEnricher(std::string const & boundaryPostcodesFilename); | ||
|
||
void Enrich(feature::FeatureBuilder & fb) const; | ||
|
||
private: | ||
std::vector<std::pair<std::string, m2::RegionD>> m_boundaryPostcodes; | ||
m4::Tree<size_t> m_boundariesTree; | ||
}; | ||
} // namespace generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.