Exemplo n.º 1
0
    void node(const osmium::Node& node) {
        const char* label = node.tags().get_value_by_key("label");
        if (label) {
            OGRFeature* feature = OGRFeature::CreateFeature(m_layer_labels->GetLayerDefn());
            std::unique_ptr<OGRPoint> ogr_point = m_factory.create_point(node);
            feature->SetGeometry(ogr_point.get());
            feature->SetField("id", static_cast<double>(node.id()));
            feature->SetField("label", label);

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

            OGRFeature::DestroyFeature(feature);
        } else {
            OGRFeature* feature = OGRFeature::CreateFeature(m_layer_nodes->GetLayerDefn());
            std::unique_ptr<OGRPoint> ogr_point = m_factory.create_point(node);
            feature->SetGeometry(ogr_point.get());
            feature->SetField("id", static_cast<double>(node.id()));

            if (m_layer_nodes->CreateFeature(feature) != OGRERR_NONE) {
                std::cerr << "Failed to create feature.\n";
                exit(1);
            }
            OGRFeature::DestroyFeature(feature);
        }
    }
Exemplo n.º 2
0
 void write_point(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location location) {
     gdalcpp::Feature feature(m_layer_perror, m_ogr_factory.create_point(location));
     feature.set_field("id1", static_cast<double>(id1));
     feature.set_field("id2", static_cast<double>(id2));
     feature.set_field("problem_type", problem_type);
     feature.add_to_layer();
 }
Exemplo n.º 3
0
            void write_line(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location loc1, osmium::Location loc2) {
                std::unique_ptr<OGRPoint> ogr_point1 = m_ogr_factory.create_point(loc1);
                std::unique_ptr<OGRPoint> ogr_point2 = m_ogr_factory.create_point(loc2);
                std::unique_ptr<OGRLineString> ogr_linestring = std::unique_ptr<OGRLineString>(new OGRLineString());
                ogr_linestring->addPoint(ogr_point1.get());
                ogr_linestring->addPoint(ogr_point2.get());

                gdalcpp::Feature feature(m_layer_lerror, std::move(ogr_linestring));
                feature.set_field("id1", static_cast<double>(id1));
                feature.set_field("id2", static_cast<double>(id2));
                feature.set_field("problem_type", problem_type);
                feature.add_to_layer();
            }
Exemplo n.º 4
0
            void write_point(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location location) {
                OGRFeature* feature = OGRFeature::CreateFeature(m_layer_perror->GetLayerDefn());
                std::unique_ptr<OGRPoint> ogr_point = m_ogr_factory.create_point(location);
                feature->SetGeometry(ogr_point.get());
                feature->SetField("id1", static_cast<double>(id1));
                feature->SetField("id2", static_cast<double>(id2));
                feature->SetField("problem_type", problem_type);

                if (m_layer_perror->CreateFeature(feature) != OGRERR_NONE) {
                    std::runtime_error("Failed to create feature on layer 'perrors'");
                }

                OGRFeature::DestroyFeature(feature);
            }
Exemplo n.º 5
0
    void node(const osmium::Node& node) {
        const char* amenity = node.tags()["amenity"];
        if (amenity && !strcmp(amenity, "post_box")) {
            OGRFeature* feature = OGRFeature::CreateFeature(m_layer_point->GetLayerDefn());
            std::unique_ptr<OGRPoint> ogr_point = m_factory.create_point(node);
            feature->SetGeometry(ogr_point.get());
            feature->SetField("id", static_cast<double>(node.id()));
            feature->SetField("operator", node.tags()["operator"]);

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

            OGRFeature::DestroyFeature(feature);
        }
    }
Exemplo n.º 6
0
            void write_line(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location loc1, osmium::Location loc2) {
                std::unique_ptr<OGRPoint> ogr_point1 = m_ogr_factory.create_point(loc1);
                std::unique_ptr<OGRPoint> ogr_point2 = m_ogr_factory.create_point(loc2);
                std::unique_ptr<OGRLineString> ogr_linestring = std::unique_ptr<OGRLineString>(new OGRLineString());
                ogr_linestring->addPoint(ogr_point1.get());
                ogr_linestring->addPoint(ogr_point2.get());
                OGRFeature* feature = OGRFeature::CreateFeature(m_layer_lerror->GetLayerDefn());
                feature->SetGeometry(ogr_linestring.get());
                feature->SetField("id1", static_cast<double>(id1));
                feature->SetField("id2", static_cast<double>(id2));
                feature->SetField("problem_type", problem_type);

                if (m_layer_lerror->CreateFeature(feature) != OGRERR_NONE) {
                    std::runtime_error("Failed to create feature on layer 'lerrors'");
                }

                OGRFeature::DestroyFeature(feature);
            }
Exemplo n.º 7
0
#include "catch.hpp"

#include <osmium/geom/ogr.hpp>

#include "area_helper.hpp"
#include "wnl_helper.hpp"

TEST_CASE("OGR_Geometry") {

SECTION("point") {
    osmium::geom::OGRFactory<> factory;

    std::unique_ptr<OGRPoint> point {factory.create_point(osmium::Location(3.2, 4.2))};
    REQUIRE(3.2 == point->getX());
    REQUIRE(4.2 == point->getY());
}

SECTION("empty_point") {
    osmium::geom::OGRFactory<> factory;

    REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
}

SECTION("linestring") {
    osmium::geom::OGRFactory<> factory;

    osmium::memory::Buffer buffer(10000);
    auto &wnl = create_test_wnl_okay(buffer);

    {
        std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl)};
Exemplo n.º 8
0
std::string to_wkb(const OGRGeometry* geometry) {
    std::string buffer;
    buffer.resize(geometry->WkbSize());

    geometry->exportToWkb(wkbNDR, reinterpret_cast<unsigned char*>(&*buffer.begin()));

    return buffer;
}

TEST_CASE("compare WKB point against GDAL/OGR") {
    osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
    osmium::geom::OGRFactory<> ogr_factory;

    const osmium::Location loc{3.2, 4.2};
    const std::string wkb{wkb_factory.create_point(loc)};
    const std::unique_ptr<OGRPoint> geometry = ogr_factory.create_point(loc);
    REQUIRE(to_wkb(geometry.get()) == wkb);
}

TEST_CASE("compare WKB linestring against GDAL/OGR") {
    osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
    osmium::geom::OGRFactory<> ogr_factory;
    osmium::memory::Buffer buffer{10000};

    const auto& wnl = create_test_wnl_okay(buffer);

    SECTION("linestring") {
        const std::string wkb{wkb_factory.create_linestring(wnl)};
        const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl);
        REQUIRE(to_wkb(geometry.get()) == wkb);
    }