multipolygon_type create_multipolygon(const osmium::Area& area) { size_t num_polygons = 0; size_t num_rings = 0; m_impl.multipolygon_start(); for (auto it = area.cbegin(); it != area.cend(); ++it) { const osmium::OuterRing& ring = static_cast<const osmium::OuterRing&>(*it); if (it->type() == osmium::item_type::outer_ring) { if (num_polygons > 0) { m_impl.multipolygon_polygon_finish(); } m_impl.multipolygon_polygon_start(); m_impl.multipolygon_outer_ring_start(); add_points(ring); m_impl.multipolygon_outer_ring_finish(); ++num_rings; ++num_polygons; } else if (it->type() == osmium::item_type::inner_ring) { m_impl.multipolygon_inner_ring_start(); add_points(ring); m_impl.multipolygon_inner_ring_finish(); ++num_rings; } } // if there are no rings, this area is invalid if (num_rings == 0) { throw osmium::geometry_error("invalid area"); } m_impl.multipolygon_polygon_finish(); return m_impl.multipolygon_finish(); }
void update(const osmium::Area& area) { update(static_cast<const osmium::OSMObject&>(area)); for (auto it = area.cbegin(); it != area.cend(); ++it) { if (it->type() == osmium::item_type::outer_ring || it->type() == osmium::item_type::inner_ring) { update(static_cast<const osmium::NodeRefList&>(*it)); } } }
osmium_builder_t::wkbs_t osmium_builder_t::create_polygons(osmium::Area const &area) { wkbs_t ret; try { size_t num_rings = 0; for (auto it = area.cbegin(); it != area.cend(); ++it) { if (it->type() == osmium::item_type::outer_ring) { auto &ring = static_cast<const osmium::OuterRing &>(*it); if (num_rings > 0) { ret.push_back(m_writer.polygon_finish(num_rings)); num_rings = 0; } m_writer.polygon_start(); m_writer.polygon_ring_start(); auto num_points = add_mp_points(ring); m_writer.polygon_ring_finish(num_points); ++num_rings; } else if (it->type() == osmium::item_type::inner_ring) { auto &ring = static_cast<const osmium::InnerRing &>(*it); m_writer.polygon_ring_start(); auto num_points = add_mp_points(ring); m_writer.polygon_ring_finish(num_points); ++num_rings; } } auto wkb = m_writer.polygon_finish(num_rings); if (num_rings > 0) { ret.push_back(wkb); } } catch (const osmium::geometry_error &) { /* ignored */ } return ret; }