diff --git a/indexer/indexer_tool/kml_parser.cpp b/indexer/indexer_tool/kml_parser.cpp index 60a1393c50..463198e8eb 100644 --- a/indexer/indexer_tool/kml_parser.cpp +++ b/indexer/indexer_tool/kml_parser.cpp @@ -1,6 +1,7 @@ #include "kml_parser.hpp" #include "../../base/string_utils.hpp" +#include "../../base/logging.hpp" #include "../../coding/parse_xml.hpp" #include "../../coding/file_reader.hpp" @@ -47,15 +48,15 @@ namespace kml return true; } - template + template class PointsCollector { - RegionT & m_region; + PointsContainerT & m_container; m2::RectD & m_rect; public: - PointsCollector(RegionT & region, m2::RectD & rect) - : m_region(region), m_rect(rect) {} + PointsCollector(PointsContainerT & container, m2::RectD & rect) + : m_container(container), m_rect(rect) {} void operator()(string const & latLon) { @@ -80,7 +81,7 @@ namespace kml typedef CellIdConverter CellIdConverterType; uint32_t const ix = static_cast(CellIdConverterType::XToCellIdX(x)); uint32_t const iy = static_cast(CellIdConverterType::YToCellIdY(y)); - m_region.AddPoint(Region::value_type(ix, iy)); + m_container.push_back(Region::value_type(ix, iy)); } }; @@ -97,15 +98,23 @@ namespace kml if (m_tags[size - 3] == "outerBoundaryIs") { - Region reg; + typedef vector ContainerT; + ContainerT points; m2::RectD rect; - PointsCollector collector(reg, rect); + PointsCollector collector(points, rect); utils::TokenizeString(m_data, " \n\r\a", collector); - if (reg.IsValid()) + size_t const numPoints = points.size(); + if (numPoints > 3 && points[numPoints - 1] == points[0]) { - m_country.m_regions.push_back(reg); + // remove last point which is equal to first + points.pop_back(); + m_country.m_regions.push_back(Region(points.begin(), points.end())); m_country.m_rect.Add(rect); } + else + { + LOG(LWARNING, ("Invalid region for country", m_country.m_name)); + } } else if (m_tags[size - 3] == "innerBoundaryIs") { // currently we're ignoring holes diff --git a/indexer/indexer_tool/polygonizer.hpp b/indexer/indexer_tool/polygonizer.hpp index e358d0c8ab..5f4de80380 100644 --- a/indexer/indexer_tool/polygonizer.hpp +++ b/indexer/indexer_tool/polygonizer.hpp @@ -50,9 +50,9 @@ namespace feature { for (size_t i = 0; i < m_regions.size(); ++i) { - m2::PointU uPoint(static_cast(CellIdConverterType::XToCellIdX(pt.x)), + kml::Region::value_type const point(static_cast(CellIdConverterType::XToCellIdX(pt.x)), static_cast(CellIdConverterType::YToCellIdY(pt.y))); - if (m_regions[i].Contains(uPoint)) + if (m_regions[i].Contains(point)) { m_belongs = true; // stop points processing