示例#1
0
            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();
            }
示例#2
0
    void area(const osmium::Area& area) {
        const char* building = area.tags()["building"];
        if (building) {
            try {
                std::unique_ptr<OGRMultiPolygon> ogr_polygon = m_factory.create_multipolygon(area);
                OGRFeature* feature = OGRFeature::CreateFeature(m_layer_polygon->GetLayerDefn());
                feature->SetGeometry(ogr_polygon.get());
                feature->SetField("id", static_cast<int>(area.id()));
                feature->SetField("type", building);

                std::string type = "";
                if (area.from_way()) {
                    type += "w";
                } else {
                    type += "r";
                }
                feature->SetField("type", type.c_str());

                if (m_layer_polygon->CreateFeature(feature) != OGRERR_NONE) {
                    std::cerr << "Failed to create feature.\n";
                    exit(1);
                }

                OGRFeature::DestroyFeature(feature);
            } catch (osmium::geometry_error&) {
                std::cerr << "Ignoring illegal geometry for area " << area.id() << " created from " << (area.from_way() ? "way" : "relation") << " with id=" << area.orig_id() << ".\n";
            }
        }
    }
示例#3
0
 void errormsg(const osmium::Area &area) {
     cerr << "IndicateFalsePositives: Error at ";
     if (area.from_way())
         cerr << "way: ";
     else
         cerr << "relation: ";
     cerr << area.orig_id() << endl;
 }
示例#4
0
 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));
         }
     }
 }
    void area(const osmium::Area& area) {
        const char* amenity = area.tags()["amenity"];
        if (amenity) {
            // Use the center of the first outer ring. Because we set
            // create_empty_areas = false in the assembler config, we can
            // be sure there will always be at least one outer ring.
            const auto center = calc_center(*area.cbegin<osmium::OuterRing>());

            print_amenity(amenity, area.tags()["name"], center);
        }
    }
    void area(const osmium::Area& area) {
        if (m_first_out) {
            m_out << "[\n";
            m_first_out = false;
        } else {
            m_out << ",\n";
        }
        m_out << "{\n  \"test_id\": " << (area.orig_id() / 1000) << ",\n  \"area_id\": " << area.id() << ",\n  \"from_id\": " << area.orig_id() << ",\n  \"from_type\": \"" << (area.from_way() ? "way" : "relation") << "\",\n  \"wkt\": \"";
        try {
            std::string wkt = m_wkt_factory.create_multipolygon(area);
            m_out << wkt << "\",\n  \"tags\": {";

            auto tagmap = create_map(area.tags());
            bool first = true;
            for (auto& tag : tagmap) {
                if (first) {
                    first = false;
                } else {
                    m_out << ", ";
                }
                m_out << '"' << tag.first << "\": \"" << tag.second << '"';
            }
            m_out << "}\n}";
        } catch (osmium::geometry_error&) {
            m_out << "INVALID\"\n}";
        }
        try {
            std::unique_ptr<OGRMultiPolygon> ogr_polygon = m_ogr_factory.create_multipolygon(area);
            OGRFeature* feature = OGRFeature::CreateFeature(m_layer_polygon->GetLayerDefn());
            feature->SetGeometry(ogr_polygon.get());
            feature->SetField("id", static_cast<int>(area.orig_id()));

            std::string from_type;
            if (area.from_way()) {
                from_type = "w";
            } else {
                from_type = "r";
            }
            feature->SetField("from_type", from_type.c_str());

            if (m_layer_polygon->CreateFeature(feature) != OGRERR_NONE) {
                std::cerr << "Failed to create feature.\n";
                exit(1);
            }

            OGRFeature::DestroyFeature(feature);
        } catch (osmium::geometry_error&) {
            std::cerr << "Ignoring illegal geometry for area " << area.id() << " created from " << (area.from_way() ? "way" : "relation") << " with id=" << area.orig_id() << ".\n";
        }
    }
 void area(const osmium::Area& area) {
     try {
         gdalcpp::Feature feature{m_layer_multipolygon, m_factory.create_multipolygon(area)};
         feature.set_field("id", int32_t(area.id()));
         add_feature(feature, area);
     } catch (const osmium::geometry_error&) {
         std::cerr << "Ignoring illegal geometry for area "
                     << area.id()
                     << " created from "
                     << (area.from_way() ? "way" : "relation")
                     << " with id="
                     << area.orig_id() << ".\n";
     }
 }
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;
}
void ExportFormatJSON::area(const osmium::Area& area) {
    start_feature("a", area.id());
    m_factory.create_multipolygon(area);
    finish_feature(area);
}