[generator:regions] Fix Hawai as country: ignore enclave ways

This commit is contained in:
Anatoly Serdtcev 2019-12-07 09:31:07 +03:00 committed by Sergey Yershov
parent 152eb7bd1d
commit b09d2df50e
5 changed files with 98 additions and 38 deletions

View file

@ -39,10 +39,10 @@ OsmElement MakeOsmElement(OsmElementData const & elementData)
OsmElement el;
el.m_id = elementData.m_id;
if (!el.m_members.empty())
el.m_type = OsmElement::EntityType::Relation;
if (elementData.m_points.size() == 1)
el.m_type = OsmElement::EntityType::Node;
else if (elementData.m_points.front() == elementData.m_points.back())
el.m_type = OsmElement::EntityType::Relation;
else
el.m_type = OsmElement::EntityType::Way;

View file

@ -7,6 +7,7 @@
#include "generator/regions/collector_region_info.hpp"
#include "generator/regions/place_point.hpp"
#include "generator/regions/regions_builder.hpp"
#include "generator/translator_region.hpp"
#include "indexer/classificator.hpp"
#include "indexer/classificator_loader.hpp"
@ -636,3 +637,33 @@ UNIT_TEST(RegionsBuilderTest_GenerateRusSPetersburgSuburb)
u8"suburb: Центральный район, sublocality: Дворцовый округ"),
());
}
// Enclave way ignoring tests ----------------------------------------------------------------------
UNIT_TEST(RegionsFilterTest_EnclaveWayIgnoring)
{
auto usa = OsmElement{};
usa.m_type = OsmElement::EntityType::Relation;
usa.m_id = 1;
usa.m_nodes = {1, 2, 3, 1};
usa.m_tags = {
{"name", u8"United States of America"},
{"type", "boundary"},
{"boundary", "administrative"},
{"admin_level", "2"}
};
auto hawai = OsmElement{};
hawai.m_type = OsmElement::EntityType::Way;
hawai.m_id = 2;
hawai.m_nodes = {1, 2, 3, 1};
hawai.m_tags = {
{"name", u8"United States of America (Island of Hawai'i territorial waters)"},
{"boundary", "administrative"},
{"admin_level", "2"}
};
auto && regionsFilter = FilterRegions{};
TEST(regionsFilter.IsAccepted(usa), ());
TEST(!regionsFilter.IsAccepted(hawai), ());
}

View file

@ -82,5 +82,5 @@ UNIT_TEST(StreetsIndexTest_SquareIndex)
auto inside = GetObjectsAtPoint(streetsIndex, {1.000 + 0.001, 2.000 + 0.001});
TEST_EQUAL(inside.size(), 1, ());
TEST_EQUAL(inside, Objects({MakeOsmRelation(1)}), ());
TEST_EQUAL(inside, Objects({MakeOsmWay(1)}), ());
}

View file

@ -17,40 +17,7 @@ using namespace feature;
namespace generator
{
namespace
{
class FilterRegions : public FilterInterface
{
public:
// FilterInterface overrides:
std::shared_ptr<FilterInterface> Clone() const override
{
return std::make_shared<FilterRegions>();
}
bool IsAccepted(OsmElement const & element) override
{
for (auto const & t : element.Tags())
{
if (t.m_key == "place" && regions::EncodePlaceType(t.m_value) != regions::PlaceType::Unknown)
return true;
if (t.m_key == "place:PH" && (t.m_value == "district" || t.m_value == "barangay"))
return true;
if (t.m_key == "boundary" && t.m_value == "administrative")
return true;
}
return false;
}
bool IsAccepted(FeatureBuilder const & feature) override
{
return feature.GetParams().IsValid() && !feature.IsLine();
}
};
} // namespace
// TranslatorRegion --------------------------------------------------------------------------------
TranslatorRegion::TranslatorRegion(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<cache::IntermediateData const> const & cache,
std::string const & regionsInfoPath)
@ -76,4 +43,53 @@ void TranslatorRegion::MergeInto(TranslatorRegion & other) const
{
MergeIntoBase(other);
}
// FilterRegions ----------------------------------------------------------------------------------
std::shared_ptr<FilterInterface> FilterRegions::Clone() const
{
return std::make_shared<FilterRegions>();
}
bool FilterRegions::IsAccepted(OsmElement const & element)
{
for (auto const & t : element.Tags())
{
if (t.m_key == "place" && regions::EncodePlaceType(t.m_value) != regions::PlaceType::Unknown)
return true;
if (t.m_key == "place:PH" && (t.m_value == "district" || t.m_value == "barangay"))
return true;
if (t.m_key == "boundary" && t.m_value == "administrative")
{
if (IsEnclaveBoundaryWay(element))
return false;
return true;
}
}
return false;
}
bool FilterRegions::IsAccepted(FeatureBuilder const & feature)
{
return feature.GetParams().IsValid() && !feature.IsLine();
}
bool FilterRegions::IsEnclaveBoundaryWay(OsmElement const & element) const
{
if (!element.IsWay() || !IsGeometryClosed(element))
return false;
if (!element.HasTag("admin_level", "2") || !element.HasTag("boundary", "administrative"))
return false;
return !element.HasTag("type", "boundary") && !element.HasTag("type", "multipolygon");
}
bool FilterRegions::IsGeometryClosed(OsmElement const & element) const
{
auto const & nodes = element.Nodes();
return nodes.size() >= 3 && nodes.front() == nodes.back();
}
} // namespace generator

View file

@ -7,7 +7,7 @@
namespace feature
{
struct GenerateInfo;
class FeatureBuilder;
} // namespace feature
namespace cache
@ -34,4 +34,17 @@ public:
protected:
using Translator::Translator;
};
class FilterRegions : public FilterInterface
{
public:
// FilterInterface overrides:
std::shared_ptr<FilterInterface> Clone() const override;
bool IsAccepted(OsmElement const & element) override;
bool IsAccepted(feature::FeatureBuilder const & feature) override;
protected:
bool IsEnclaveBoundaryWay(OsmElement const & element) const;
bool IsGeometryClosed(OsmElement const & element) const;
};
} // namespace generator