problem_reporter_ogr.hpp
Go to the documentation of this file.
#ifndef OSMIUM_AREA_PROBLEM_REPORTER_OGR_HPP
#define OSMIUM_AREA_PROBLEM_REPORTER_OGR_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <memory>
#include <gdalcpp.hpp>
#include <osmium/area/problem_reporter.hpp>
#include <osmium/geom/factory.hpp>
#include <osmium/geom/ogr.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/types.hpp>
namespace osmium {
namespace area {
class ProblemReporterOGR : public ProblemReporter {
osmium::geom::OGRFactory<> m_ogr_factory;
gdalcpp::Layer m_layer_perror;
gdalcpp::Layer m_layer_lerror;
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();
}
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();
}
public:
explicit ProblemReporterOGR(gdalcpp::Dataset& dataset) :
m_layer_perror(dataset, "perrors", wkbPoint),
m_layer_lerror(dataset, "lerrors", wkbLineString) {
m_layer_perror.add_field("id1", OFTReal, 10);
m_layer_perror.add_field("id2", OFTReal, 10);
m_layer_perror.add_field("problem_type", OFTString, 30);
m_layer_lerror.add_field("id1", OFTReal, 10);
m_layer_lerror.add_field("id2", OFTReal, 10);
m_layer_lerror.add_field("problem_type", OFTString, 30);
}
~ProblemReporterOGR() override = default;
void report_duplicate_node(osmium::object_id_type node_id1, osmium::object_id_type node_id2, osmium::Location location) override {
write_point("duplicate_node", node_id1, node_id2, location);
}
void report_intersection(osmium::object_id_type way1_id, osmium::Location way1_seg_start, osmium::Location way1_seg_end,
osmium::object_id_type way2_id, osmium::Location way2_seg_start, osmium::Location way2_seg_end, osmium::Location intersection) override {
write_point("intersection", m_object_id, 0, intersection);
write_line("intersection", m_object_id, way1_id, way1_seg_start, way1_seg_end);
write_line("intersection", m_object_id, way2_id, way2_seg_start, way2_seg_end);
}
void report_ring_not_closed(osmium::Location end1, osmium::Location end2) override {
write_point("ring_not_closed", m_object_id, 0, end1);
write_point("ring_not_closed", m_object_id, 0, end2);
}
void report_role_should_be_outer(osmium::object_id_type way_id, osmium::Location seg_start, osmium::Location seg_end) override {
write_line("role_should_be_outer", m_object_id, way_id, seg_start, seg_end);
}
void report_role_should_be_inner(osmium::object_id_type way_id, osmium::Location seg_start, osmium::Location seg_end) override {
write_line("role_should_be_inner", m_object_id, way_id, seg_start, seg_end);
}
}; // class ProblemReporterOGR
} // namespace area
} // namespace osmium
#endif // OSMIUM_AREA_PROBLEM_REPORTER_OGR_HPP
osmium::area::ProblemReporterOGR::report_role_should_be_outer
void report_role_should_be_outer(osmium::object_id_type way_id, osmium::Location seg_start, osmium::Location seg_end) override
Definition: problem_reporter_ogr.hpp:125
osmium::geom::GeometryFactory
Definition: factory.hpp:146
osmium::area::ProblemReporterOGR::write_point
void write_point(const char *problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location location)
Definition: problem_reporter_ogr.hpp:70
osmium::area::ProblemReporter::m_object_id
osmium::object_id_type m_object_id
Definition: problem_reporter.hpp:63
location.hpp
ogr.hpp
osmium::area::ProblemReporterOGR::report_intersection
void report_intersection(osmium::object_id_type way1_id, osmium::Location way1_seg_start, osmium::Location way1_seg_end, osmium::object_id_type way2_id, osmium::Location way2_seg_start, osmium::Location way2_seg_end, osmium::Location intersection) override
Definition: problem_reporter_ogr.hpp:113
osmium::osm_entity_bits::area
Definition: entity_bits.hpp:67
osmium::area::ProblemReporterOGR::~ProblemReporterOGR
~ProblemReporterOGR() override=default
types.hpp
osmium::area::ProblemReporterOGR::m_layer_lerror
gdalcpp::Layer m_layer_lerror
Definition: problem_reporter_ogr.hpp:68
osmium::area::ProblemReporterOGR::ProblemReporterOGR
ProblemReporterOGR(gdalcpp::Dataset &dataset)
Definition: problem_reporter_ogr.hpp:94
osmium::object_id_type
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
osmium
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
osmium::area::ProblemReporter
Definition: problem_reporter.hpp:55
osmium::geom::GeometryFactory::create_point
point_type create_point(const osmium::Location &location) const
Definition: factory.hpp:202
osmium::area::ProblemReporterOGR::report_duplicate_node
void report_duplicate_node(osmium::object_id_type node_id1, osmium::object_id_type node_id2, osmium::Location location) override
Definition: problem_reporter_ogr.hpp:109
problem_reporter.hpp
osmium::area::ProblemReporterOGR::write_line
void write_line(const char *problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location loc1, osmium::Location loc2)
Definition: problem_reporter_ogr.hpp:78
osmium::area::ProblemReporterOGR
Definition: problem_reporter_ogr.hpp:63
osmium::Location
Definition: location.hpp:79
osmium::area::ProblemReporterOGR::m_ogr_factory
osmium::geom::OGRFactory m_ogr_factory
Definition: problem_reporter_ogr.hpp:65
osmium::area::ProblemReporterOGR::m_layer_perror
gdalcpp::Layer m_layer_perror
Definition: problem_reporter_ogr.hpp:67
osmium::area::ProblemReporterOGR::report_role_should_be_inner
void report_role_should_be_inner(osmium::object_id_type way_id, osmium::Location seg_start, osmium::Location seg_end) override
Definition: problem_reporter_ogr.hpp:129
osmium::area::ProblemReporterOGR::report_ring_not_closed
void report_ring_not_closed(osmium::Location end1, osmium::Location end2) override
Definition: problem_reporter_ogr.hpp:120
factory.hpp