Loading...
Searching...
No Matches
dump.hpp
Go to the documentation of this file.
#ifndef OSMIUM_HANDLER_DUMP_HPP
#define OSMIUM_HANDLER_DUMP_HPP
/*
This file is part of Osmium (https://osmcode.org/libosmium).
Copyright 2013-2025 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 <osmium/handler.hpp>
#include <osmium/memory/collection.hpp>
#include <osmium/memory/item.hpp>
#include <osmium/osm/area.hpp>
#include <osmium/osm/box.hpp>
#include <osmium/osm/changeset.hpp>
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/node.hpp>
#include <osmium/osm/node_ref.hpp>
#include <osmium/osm/object.hpp>
#include <osmium/osm/relation.hpp>
#include <osmium/osm/tag.hpp>
#include <osmium/osm/timestamp.hpp>
#include <osmium/osm/way.hpp>
#include <osmium/visitor.hpp>
#include <iomanip>
#include <iostream>
#include <string>
namespace osmium {
namespace handler {
class Dump : public osmium::handler::Handler {
std::ostream* m_out;
bool m_with_size;
std::string m_prefix;
void print_title(const char* title, const osmium::memory::Item& item) {
*m_out << m_prefix
<< title
<< ":";
if (m_with_size) {
*m_out << " ["
<< item.byte_size()
<< "]";
}
*m_out << "\n";
}
void print_meta(const osmium::OSMObject& object) {
*m_out << m_prefix
<< " id="
<< object.id()
<< "\n";
*m_out << m_prefix
<< " version="
<< object.version()
<< "\n";
*m_out << m_prefix
<< " uid="
<< object.uid()
<< "\n";
*m_out << m_prefix
<< " user=|"
<< object.user()
<< "|\n";
*m_out << m_prefix
<< " changeset="
<< object.changeset()
<< "\n";
*m_out << m_prefix
<< " timestamp="
<< object.timestamp().to_iso()
<< "\n";
*m_out << m_prefix
<< " visible="
<< (object.visible() ? "yes" : "no")
<< "\n";
Dump dump{*m_out, m_with_size, m_prefix + " "};
osmium::apply(object.cbegin(), object.cend(), dump);
}
void print_location(const osmium::Node& node) {
const osmium::Location& location = node.location();
if (location) {
*m_out << m_prefix
<< " lon="
<< std::fixed
<< std::setprecision(7)
<< location.lon_without_check()
<< "\n";
*m_out << m_prefix
<< " lat="
<< location.lat_without_check()
<< "\n";
} else {
*m_out << m_prefix
<< " lon=\n"
<< m_prefix
<< " lat=\n";
}
}
public:
explicit Dump(std::ostream& out, bool with_size = true, std::string prefix = "") :
m_out(&out),
m_with_size(with_size),
m_prefix(std::move(prefix)) {
}
void tag_list(const osmium::TagList& tags) {
print_title("TAGS", tags);
for (const auto& tag : tags) {
*m_out << m_prefix
<< " k=|"
<< tag.key()
<< "| v=|"
<< tag.value()
<< "|"
<< "\n";
}
}
void way_node_list(const osmium::WayNodeList& wnl) {
print_title("NODES", wnl);
for (const auto& node_ref : wnl) {
*m_out << m_prefix
<< " ref="
<< node_ref.ref();
if (node_ref.location()) {
*m_out << " pos="
<< node_ref.location();
}
*m_out << "\n";
}
}
void relation_member_list(const osmium::RelationMemberList& rml) {
print_title("MEMBERS", rml);
for (const auto& member : rml) {
*m_out << m_prefix
<< " type="
<< item_type_to_name(member.type())
<< " ref="
<< member.ref()
<< " role=|"
<< member.role()
<< "|\n";
if (member.full_member()) {
Dump dump(*m_out, m_with_size, m_prefix + " | ");
osmium::apply_item(member.get_object(), dump);
}
}
}
void outer_ring(const osmium::OuterRing& ring) {
print_title("OUTER RING", ring);
for (const auto& node_ref : ring) {
*m_out << m_prefix
<< " ref="
<< node_ref.ref();
if (node_ref.location()) {
*m_out << " pos="
<< node_ref.location();
}
*m_out << "\n";
}
}
void inner_ring(const osmium::InnerRing& ring) {
print_title("INNER RING", ring);
for (const auto& node_ref : ring) {
*m_out << m_prefix
<< " ref="
<< node_ref.ref();
if (node_ref.location()) {
*m_out << " pos="
<< node_ref.location();
}
*m_out << "\n";
}
}
void node(const osmium::Node& node) {
print_title("NODE", node);
print_meta(node);
print_location(node);
}
void way(const osmium::Way& way) {
print_title("WAY", way);
print_meta(way);
}
void relation(const osmium::Relation& relation) {
print_title("RELATION", relation);
print_meta(relation);
}
void area(const osmium::Area& area) {
print_title("AREA", area);
print_meta(area);
}
void changeset(const osmium::Changeset& changeset) {
print_title("CHANGESET", changeset);
*m_out << m_prefix
<< " id="
<< changeset.id()
<< "\n";
*m_out << m_prefix
<< " num_changes="
<< changeset.num_changes()
<< "\n";
*m_out << m_prefix
<< " uid="
<< changeset.uid()
<< "\n";
*m_out << m_prefix
<< " user=|"
<< changeset.user()
<< "|\n";
*m_out << m_prefix
<< " created_at="
<< changeset.created_at().to_iso()
<< "\n";
*m_out << m_prefix
<< " closed_at="
<< changeset.closed_at().to_iso()
<< "\n";
*m_out << m_prefix
<< " bounds=";
if (changeset.bounds()) {
*m_out << '('
<< changeset.bounds().bottom_left().lon_without_check()
<< ','
<< changeset.bounds().bottom_left().lat_without_check()
<< ','
<< changeset.bounds().top_right().lon_without_check()
<< ','
<< changeset.bounds().top_right().lat_without_check()
<< ')';
} else {
*m_out << "(undefined)";
}
*m_out << "\n";
Dump dump{*m_out, m_with_size, m_prefix + " "};
osmium::apply(changeset.cbegin(), changeset.cend(), dump);
}
}; // class Dump
} // namespace handler
} // namespace osmium
#endif // OSMIUM_HANDLER_DUMP_HPP
area.hpp
box.hpp
changeset.hpp
osmium::Area
Definition area.hpp:125
osmium::Changeset
An OSM Changeset, a group of changes made by a single user over a short period of time.
Definition changeset.hpp:146
osmium::InnerRing
Definition area.hpp:80
osmium::Location
Definition location.hpp:271
osmium::Location::lon_without_check
double lon_without_check() const noexcept
Definition location.hpp:410
osmium::Location::lat_without_check
double lat_without_check() const noexcept
Definition location.hpp:429
osmium::Node
Definition node.hpp:48
osmium::OSMObject
Definition object.hpp:64
osmium::OuterRing
Definition area.hpp:60
osmium::RelationMemberList
Definition relation.hpp:147
osmium::Relation
Definition relation.hpp:161
osmium::TagList
Definition tag.hpp:119
osmium::WayNodeList
Definition way.hpp:55
osmium::Way
Definition way.hpp:72
osmium::handler::Dump::area
void area(const osmium::Area &area)
Definition dump.hpp:234
osmium::handler::Dump::tag_list
void tag_list(const osmium::TagList &tags)
Definition dump.hpp:145
osmium::handler::Dump::print_meta
void print_meta(const osmium::OSMObject &object)
Definition dump.hpp:81
osmium::handler::Dump::outer_ring
void outer_ring(const osmium::OuterRing &ring)
Definition dump.hpp:190
osmium::handler::Dump::m_with_size
bool m_with_size
Definition dump.hpp:64
osmium::handler::Dump::m_prefix
std::string m_prefix
Definition dump.hpp:65
osmium::handler::Dump::way
void way(const osmium::Way &way)
Definition dump.hpp:224
osmium::handler::Dump::relation_member_list
void relation_member_list(const osmium::RelationMemberList &rml)
Definition dump.hpp:172
osmium::handler::Dump::print_title
void print_title(const char *title, const osmium::memory::Item &item)
Definition dump.hpp:67
osmium::handler::Dump::Dump
Dump(std::ostream &out, bool with_size=true, std::string prefix="")
Definition dump.hpp:139
osmium::handler::Dump::changeset
void changeset(const osmium::Changeset &changeset)
Definition dump.hpp:239
osmium::handler::Dump::node
void node(const osmium::Node &node)
Definition dump.hpp:218
osmium::handler::Dump::print_location
void print_location(const osmium::Node &node)
Definition dump.hpp:115
osmium::handler::Dump::relation
void relation(const osmium::Relation &relation)
Definition dump.hpp:229
osmium::handler::Dump::m_out
std::ostream * m_out
Definition dump.hpp:63
osmium::handler::Dump::inner_ring
void inner_ring(const osmium::InnerRing &ring)
Definition dump.hpp:204
osmium::handler::Dump::way_node_list
void way_node_list(const osmium::WayNodeList &wnl)
Definition dump.hpp:158
osmium::handler::Handler
Definition handler.hpp:71
osmium::memory::Item
Definition item.hpp:105
osmium::memory::Item::byte_size
item_size_type byte_size() const noexcept
Definition item.hpp:163
collection.hpp
handler.hpp
item.hpp
item_type.hpp
location.hpp
osmium::handler
Osmium handlers provide callbacks for OSM objects.
Definition dynamic_handler.hpp:49
osmium::tags
Code related to working with OSM tags.
Definition filter.hpp:47
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::apply_item
void apply_item(TItem &item, THandlers &&... handlers)
Definition visitor.hpp:306
osmium::item_type_to_name
const char * item_type_to_name(const item_type type) noexcept
Definition item_type.hpp:154
osmium::apply
void apply(TIterator it, TIterator end, THandlers &&... handlers)
Definition visitor.hpp:326
std
Definition location.hpp:555
node.hpp
node_ref.hpp
object.hpp
relation.hpp
tag.hpp
timestamp.hpp
visitor.hpp
way.hpp