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 (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 <iomanip>
#include <iostream>
#include <string>
#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>
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, const std::string& prefix = "") :
m_out(&out),
m_with_size(with_size),
m_prefix(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
osmium::Location::lat_without_check
double lat_without_check() const
Definition: location.hpp:215
collection.hpp
osmium::handler::Dump::m_out
std::ostream * m_out
Definition: dump.hpp:63
osmium::item_type_to_name
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:155
osmium::TagList
Definition: tag.hpp:105
location.hpp
osmium::Changeset::bounds
osmium::Box & bounds() noexcept
Definition: changeset.hpp:340
osmium::handler::Dump::node
void node(const osmium::Node &node)
Definition: dump.hpp:218
osmium::Changeset::uid
user_id_type uid() const noexcept
Get user id.
Definition: changeset.hpp:214
osmium::Box::top_right
constexpr Location top_right() const noexcept
Definition: box.hpp:178
osmium::Relation
Definition: relation.hpp:165
osmium::Changeset::user
const char * user() const
Get user name.
Definition: changeset.hpp:354
osmium::Changeset::id
changeset_id_type id() const noexcept
Get ID of this changeset.
Definition: changeset.hpp:188
osmium::Area
Definition: area.hpp:113
osmium::handler::Handler
Definition: handler.hpp:45
node_ref.hpp
osmium::RelationMemberList
Definition: relation.hpp:148
object.hpp
osmium::InnerRing
Definition: area.hpp:72
box.hpp
osmium::Way
Definition: way.hpp:65
osmium::handler::Dump::m_with_size
bool m_with_size
Definition: dump.hpp:64
item_type.hpp
tag.hpp
osmium::apply
void apply(TIterator it, TIterator end, THandlers &...handlers)
Definition: visitor.hpp:234
osmium::handler::Dump::way_node_list
void way_node_list(const osmium::WayNodeList &wnl)
Definition: dump.hpp:158
osmium::apply_item
void apply_item(const osmium::memory::Item &item, THandlers &...handlers)
Definition: visitor.hpp:224
osmium::handler::Dump
Definition: dump.hpp:61
osmium::handler::Dump::relation_member_list
void relation_member_list(const osmium::RelationMemberList &rml)
Definition: dump.hpp:172
osmium::Changeset::closed_at
osmium::Timestamp closed_at() const noexcept
Definition: changeset.hpp:267
osmium::memory::Item
Definition: item.hpp:97
way.hpp
osmium::Location::lon_without_check
double lon_without_check() const
Definition: location.hpp:196
osmium::handler::Dump::changeset
void changeset(const osmium::Changeset &changeset)
Definition: dump.hpp:239
osmium::WayNodeList
Definition: way.hpp:52
osmium
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
osmium::Changeset::num_changes
num_changes_type num_changes() const noexcept
Get the number of changes in this changeset.
Definition: changeset.hpp:304
osmium::Changeset::cend
const_iterator cend() const
Definition: changeset.hpp:401
area.hpp
relation.hpp
osmium::handler::Dump::way
void way(const osmium::Way &way)
Definition: dump.hpp:224
osmium::OuterRing
Definition: area.hpp:56
handler.hpp
osmium::Changeset::created_at
osmium::Timestamp created_at() const noexcept
Get timestamp when this changeset was created.
Definition: changeset.hpp:257
osmium::Location
Definition: location.hpp:79
osmium::memory::Item::byte_size
item_size_type byte_size() const noexcept
Definition: item.hpp:147
osmium::handler::Dump::print_title
void print_title(const char *title, const osmium::memory::Item &item)
Definition: dump.hpp:67
osmium::handler::Dump::m_prefix
std::string m_prefix
Definition: dump.hpp:65
osmium::handler::Dump::relation
void relation(const osmium::Relation &relation)
Definition: dump.hpp:229
osmium::handler::Dump::print_location
void print_location(const osmium::Node &node)
Definition: dump.hpp:115
item.hpp
osmium::Node::location
osmium::Location location() const noexcept
Definition: node.hpp:61
osmium::Box::bottom_left
constexpr Location bottom_left() const noexcept
Definition: box.hpp:164
osmium::Node
Definition: node.hpp:47
node.hpp
osmium::handler::Dump::Dump
Dump(std::ostream &out, bool with_size=true, const std::string &prefix="")
Definition: dump.hpp:139
osmium::Changeset
An OSM Changeset, a group of changes made by a single user over a short period of time...
Definition: changeset.hpp:154
osmium::Timestamp::to_iso
std::string to_iso() const
Definition: timestamp.hpp:185
osmium::handler::Dump::outer_ring
void outer_ring(const osmium::OuterRing &ring)
Definition: dump.hpp:190
osmium::handler::Dump::area
void area(const osmium::Area &area)
Definition: dump.hpp:234
osmium::Changeset::cbegin
const_iterator cbegin() const
Definition: changeset.hpp:397
changeset.hpp
visitor.hpp
osmium::handler::Dump::print_meta
void print_meta(const osmium::OSMObject &object)
Definition: dump.hpp:81
osmium::handler::Dump::tag_list
void tag_list(const osmium::TagList &tags)
Definition: dump.hpp:145
timestamp.hpp
osmium::handler::Dump::inner_ring
void inner_ring(const osmium::InnerRing &ring)
Definition: dump.hpp:204
osmium::OSMObject
Definition: object.hpp:58