Libosmium  2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
dump.hpp
Go to the documentation of this file.
1#ifndef OSMIUM_HANDLER_DUMP_HPP
2#define OSMIUM_HANDLER_DUMP_HPP
3
4/*
5
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
36#include <osmium/handler.hpp>
39#include <osmium/osm/area.hpp>
40#include <osmium/osm/box.hpp>
44#include <osmium/osm/node.hpp>
46#include <osmium/osm/object.hpp>
48#include <osmium/osm/tag.hpp>
50#include <osmium/osm/way.hpp>
51#include <osmium/visitor.hpp>
52
53#include <iomanip>
54#include <iostream>
55#include <string>
56
57namespace osmium {
58
59 namespace handler {
60
62
63 std::ostream* m_out;
65 std::string m_prefix;
66
67 void print_title(const char* title, const osmium::memory::Item& item) {
68 *m_out << m_prefix
69 << title
70 << ":";
71
72 if (m_with_size) {
73 *m_out << " ["
74 << item.byte_size()
75 << "]";
76 }
77
78 *m_out << "\n";
79 }
80
81 void print_meta(const osmium::OSMObject& object) {
82 *m_out << m_prefix
83 << " id="
84 << object.id()
85 << "\n";
86 *m_out << m_prefix
87 << " version="
88 << object.version()
89 << "\n";
90 *m_out << m_prefix
91 << " uid="
92 << object.uid()
93 << "\n";
94 *m_out << m_prefix
95 << " user=|"
96 << object.user()
97 << "|\n";
98 *m_out << m_prefix
99 << " changeset="
100 << object.changeset()
101 << "\n";
102 *m_out << m_prefix
103 << " timestamp="
104 << object.timestamp().to_iso()
105 << "\n";
106 *m_out << m_prefix
107 << " visible="
108 << (object.visible() ? "yes" : "no")
109 << "\n";
110
111 Dump dump{*m_out, m_with_size, m_prefix + " "};
112 osmium::apply(object.cbegin(), object.cend(), dump);
113 }
114
116 const osmium::Location& location = node.location();
117
118 if (location) {
119 *m_out << m_prefix
120 << " lon="
121 << std::fixed
122 << std::setprecision(7)
123 << location.lon_without_check()
124 << "\n";
125 *m_out << m_prefix
126 << " lat="
127 << location.lat_without_check()
128 << "\n";
129 } else {
130 *m_out << m_prefix
131 << " lon=\n"
132 << m_prefix
133 << " lat=\n";
134 }
135 }
136
137 public:
138
139 explicit Dump(std::ostream& out, bool with_size = true, std::string prefix = "") :
140 m_out(&out),
141 m_with_size(with_size),
142 m_prefix(std::move(prefix)) {
143 }
144
145 void tag_list(const osmium::TagList& tags) {
146 print_title("TAGS", tags);
147 for (const auto& tag : tags) {
148 *m_out << m_prefix
149 << " k=|"
150 << tag.key()
151 << "| v=|"
152 << tag.value()
153 << "|"
154 << "\n";
155 }
156 }
157
159 print_title("NODES", wnl);
160 for (const auto& node_ref : wnl) {
161 *m_out << m_prefix
162 << " ref="
163 << node_ref.ref();
164 if (node_ref.location()) {
165 *m_out << " pos="
166 << node_ref.location();
167 }
168 *m_out << "\n";
169 }
170 }
171
173 print_title("MEMBERS", rml);
174 for (const auto& member : rml) {
175 *m_out << m_prefix
176 << " type="
177 << item_type_to_name(member.type())
178 << " ref="
179 << member.ref()
180 << " role=|"
181 << member.role()
182 << "|\n";
183 if (member.full_member()) {
184 Dump dump(*m_out, m_with_size, m_prefix + " | ");
185 osmium::apply_item(member.get_object(), dump);
186 }
187 }
188 }
189
190 void outer_ring(const osmium::OuterRing& ring) {
191 print_title("OUTER RING", ring);
192 for (const auto& node_ref : ring) {
193 *m_out << m_prefix
194 << " ref="
195 << node_ref.ref();
196 if (node_ref.location()) {
197 *m_out << " pos="
198 << node_ref.location();
199 }
200 *m_out << "\n";
201 }
202 }
203
204 void inner_ring(const osmium::InnerRing& ring) {
205 print_title("INNER RING", ring);
206 for (const auto& node_ref : ring) {
207 *m_out << m_prefix
208 << " ref="
209 << node_ref.ref();
210 if (node_ref.location()) {
211 *m_out << " pos="
212 << node_ref.location();
213 }
214 *m_out << "\n";
215 }
216 }
217
218 void node(const osmium::Node& node) {
219 print_title("NODE", node);
222 }
223
224 void way(const osmium::Way& way) {
225 print_title("WAY", way);
227 }
228
230 print_title("RELATION", relation);
232 }
233
234 void area(const osmium::Area& area) {
235 print_title("AREA", area);
237 }
238
240 print_title("CHANGESET", changeset);
241 *m_out << m_prefix
242 << " id="
243 << changeset.id()
244 << "\n";
245 *m_out << m_prefix
246 << " num_changes="
247 << changeset.num_changes()
248 << "\n";
249 *m_out << m_prefix
250 << " uid="
251 << changeset.uid()
252 << "\n";
253 *m_out << m_prefix
254 << " user=|"
255 << changeset.user()
256 << "|\n";
257 *m_out << m_prefix
258 << " created_at="
259 << changeset.created_at().to_iso()
260 << "\n";
261 *m_out << m_prefix
262 << " closed_at="
263 << changeset.closed_at().to_iso()
264 << "\n";
265 *m_out << m_prefix
266 << " bounds=";
267
268 if (changeset.bounds()) {
269 *m_out << '('
270 << changeset.bounds().bottom_left().lon_without_check()
271 << ','
272 << changeset.bounds().bottom_left().lat_without_check()
273 << ','
274 << changeset.bounds().top_right().lon_without_check()
275 << ','
276 << changeset.bounds().top_right().lat_without_check()
277 << ')';
278 } else {
279 *m_out << "(undefined)";
280 }
281
282 *m_out << "\n";
283
284 Dump dump{*m_out, m_with_size, m_prefix + " "};
285 osmium::apply(changeset.cbegin(), changeset.cend(), dump);
286 }
287
288 }; // class Dump
289
290 } // namespace handler
291
292} // namespace osmium
293
294#endif // OSMIUM_HANDLER_DUMP_HPP
Definition: area.hpp:125
An OSM Changeset, a group of changes made by a single user over a short period of time.
Definition: changeset.hpp:146
Definition: area.hpp:80
Definition: location.hpp:271
double lon_without_check() const noexcept
Definition: location.hpp:410
double lat_without_check() const noexcept
Definition: location.hpp:429
Definition: node.hpp:48
Definition: object.hpp:64
Definition: area.hpp:60
Definition: relation.hpp:147
Definition: relation.hpp:161
Definition: tag.hpp:119
Definition: way.hpp:55
Definition: way.hpp:72
Definition: dump.hpp:61
void area(const osmium::Area &area)
Definition: dump.hpp:234
void tag_list(const osmium::TagList &tags)
Definition: dump.hpp:145
void print_meta(const osmium::OSMObject &object)
Definition: dump.hpp:81
void outer_ring(const osmium::OuterRing &ring)
Definition: dump.hpp:190
bool m_with_size
Definition: dump.hpp:64
std::string m_prefix
Definition: dump.hpp:65
void way(const osmium::Way &way)
Definition: dump.hpp:224
void relation_member_list(const osmium::RelationMemberList &rml)
Definition: dump.hpp:172
void print_title(const char *title, const osmium::memory::Item &item)
Definition: dump.hpp:67
Dump(std::ostream &out, bool with_size=true, std::string prefix="")
Definition: dump.hpp:139
void changeset(const osmium::Changeset &changeset)
Definition: dump.hpp:239
void node(const osmium::Node &node)
Definition: dump.hpp:218
void print_location(const osmium::Node &node)
Definition: dump.hpp:115
void relation(const osmium::Relation &relation)
Definition: dump.hpp:229
std::ostream * m_out
Definition: dump.hpp:63
void inner_ring(const osmium::InnerRing &ring)
Definition: dump.hpp:204
void way_node_list(const osmium::WayNodeList &wnl)
Definition: dump.hpp:158
Definition: handler.hpp:71
Definition: item.hpp:105
item_size_type byte_size() const noexcept
Definition: item.hpp:163
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
void apply_item(TItem &item, THandlers &&... handlers)
Definition: visitor.hpp:306
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:154
void apply(TIterator it, TIterator end, THandlers &&... handlers)
Definition: visitor.hpp:326
Definition: location.hpp:555