Exemple #1
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";
            }
        }
    }
 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";
     }
 }
    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";
        }
    }
Exemple #4
0
            multipolygon_type create_multipolygon(const osmium::Area& area) {
                try {
                    size_t num_polygons = 0;
                    size_t num_rings = 0;
                    m_impl.multipolygon_start();

                    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_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) {
                            auto& ring = static_cast<const osmium::InnerRing&>(*it);
                            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();
                } catch (osmium::geometry_error& e) {
                    e.set_id("area", area.id());
                    throw;
                }
            }
void ExportFormatJSON::area(const osmium::Area& area) {
    start_feature("a", area.id());
    m_factory.create_multipolygon(area);
    finish_feature(area);
}