Libosmium  2.6.0
Fast and flexible C++ library for working with OpenStreetMap data
problem_reporter_ogr.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_AREA_PROBLEM_REPORTER_OGR_HPP
2 #define OSMIUM_AREA_PROBLEM_REPORTER_OGR_HPP
3 
4 /*
5 
6 This file is part of Osmium (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2016 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS IN THE SOFTWARE.
33 
34 */
35 
45 #include <memory>
46 
47 #include <gdalcpp.hpp>
48 
50 #include <osmium/geom/factory.hpp>
51 #include <osmium/geom/ogr.hpp>
52 #include <osmium/osm/location.hpp>
53 #include <osmium/osm/types.hpp>
54 
55 namespace osmium {
56 
57  namespace area {
58 
64 
66 
67  gdalcpp::Layer m_layer_perror;
68  gdalcpp::Layer m_layer_lerror;
69 
70  void write_point(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location location) {
71  gdalcpp::Feature feature(m_layer_perror, m_ogr_factory.create_point(location));
72  feature.set_field("id1", static_cast<double>(id1));
73  feature.set_field("id2", static_cast<double>(id2));
74  feature.set_field("problem_type", problem_type);
75  feature.add_to_layer();
76  }
77 
78  void write_line(const char* problem_type, osmium::object_id_type id1, osmium::object_id_type id2, osmium::Location loc1, osmium::Location loc2) {
79  std::unique_ptr<OGRPoint> ogr_point1 = m_ogr_factory.create_point(loc1);
80  std::unique_ptr<OGRPoint> ogr_point2 = m_ogr_factory.create_point(loc2);
81  std::unique_ptr<OGRLineString> ogr_linestring = std::unique_ptr<OGRLineString>(new OGRLineString());
82  ogr_linestring->addPoint(ogr_point1.get());
83  ogr_linestring->addPoint(ogr_point2.get());
84 
85  gdalcpp::Feature feature(m_layer_lerror, std::move(ogr_linestring));
86  feature.set_field("id1", static_cast<double>(id1));
87  feature.set_field("id2", static_cast<double>(id2));
88  feature.set_field("problem_type", problem_type);
89  feature.add_to_layer();
90  }
91 
92  public:
93 
94  explicit ProblemReporterOGR(gdalcpp::Dataset& dataset) :
95  m_layer_perror(dataset, "perrors", wkbPoint),
96  m_layer_lerror(dataset, "lerrors", wkbLineString) {
97 
98  m_layer_perror.add_field("id1", OFTReal, 10);
99  m_layer_perror.add_field("id2", OFTReal, 10);
100  m_layer_perror.add_field("problem_type", OFTString, 30);
101 
102  m_layer_lerror.add_field("id1", OFTReal, 10);
103  m_layer_lerror.add_field("id2", OFTReal, 10);
104  m_layer_lerror.add_field("problem_type", OFTString, 30);
105  }
106 
107  ~ProblemReporterOGR() override = default;
108 
110  write_point("duplicate_node", node_id1, node_id2, location);
111  }
112 
114  osmium::object_id_type way2_id, osmium::Location way2_seg_start, osmium::Location way2_seg_end, osmium::Location intersection) override {
115  write_point("intersection", m_object_id, 0, intersection);
116  write_line("intersection", m_object_id, way1_id, way1_seg_start, way1_seg_end);
117  write_line("intersection", m_object_id, way2_id, way2_seg_start, way2_seg_end);
118  }
119 
121  write_point("ring_not_closed", m_object_id, 0, end1);
122  write_point("ring_not_closed", m_object_id, 0, end2);
123  }
124 
126  write_line("role_should_be_outer", m_object_id, way_id, seg_start, seg_end);
127  }
128 
130  write_line("role_should_be_inner", m_object_id, way_id, seg_start, seg_end);
131  }
132 
133  }; // class ProblemReporterOGR
134 
135  } // namespace area
136 
137 } // namespace osmium
138 
139 #endif // OSMIUM_AREA_PROBLEM_REPORTER_OGR_HPP
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
Definition: factory.hpp:146
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::object_id_type m_object_id
Definition: problem_reporter.hpp:63
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
Definition: entity_bits.hpp:67
~ProblemReporterOGR() override=default
gdalcpp::Layer m_layer_lerror
Definition: problem_reporter_ogr.hpp:68
ProblemReporterOGR(gdalcpp::Dataset &dataset)
Definition: problem_reporter_ogr.hpp:94
int64_t object_id_type
Type for OSM object (node, way, or relation) IDs.
Definition: types.hpp:45
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
Definition: problem_reporter.hpp:55
point_type create_point(const osmium::Location &location) const
Definition: factory.hpp:202
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
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
Definition: problem_reporter_ogr.hpp:63
Definition: location.hpp:79
osmium::geom::OGRFactory m_ogr_factory
Definition: problem_reporter_ogr.hpp:65
gdalcpp::Layer m_layer_perror
Definition: problem_reporter_ogr.hpp:67
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
void report_ring_not_closed(osmium::Location end1, osmium::Location end2) override
Definition: problem_reporter_ogr.hpp:120