fixing line endings
This commit is contained in:
Vendored
+128
@@ -0,0 +1,128 @@
|
||||
#ifndef OSMIUM_HANDLER_CHAIN_HPP
|
||||
#define OSMIUM_HANDLER_CHAIN_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (http://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2014 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 <tuple>
|
||||
|
||||
#include <osmium/handler.hpp>
|
||||
|
||||
#define OSMIUM_CHAIN_HANDLER_CALL(_func_, _type_) \
|
||||
template <int N, int SIZE, class THandlers> \
|
||||
struct call_ ## _func_ { \
|
||||
void operator()(THandlers& handlers, osmium::_type_& object) { \
|
||||
std::get<N>(handlers)._func_(object); \
|
||||
call_ ## _func_<N+1, SIZE, THandlers>()(handlers, object); \
|
||||
} \
|
||||
}; \
|
||||
template <int SIZE, class THandlers> \
|
||||
struct call_ ## _func_<SIZE, SIZE, THandlers> { \
|
||||
void operator()(THandlers&, osmium::_type_&) {} \
|
||||
};
|
||||
|
||||
namespace osmium {
|
||||
|
||||
class Node;
|
||||
class Way;
|
||||
class Relation;
|
||||
class Area;
|
||||
class Changeset;
|
||||
|
||||
namespace handler {
|
||||
|
||||
/**
|
||||
* This handler allows chaining of any number of handlers into a single
|
||||
* handler.
|
||||
*/
|
||||
template <class ...THandler>
|
||||
class ChainHandler : public osmium::handler::Handler {
|
||||
|
||||
typedef std::tuple<THandler&...> handlers_type;
|
||||
handlers_type m_handlers;
|
||||
|
||||
template <int N, int SIZE, class THandlers>
|
||||
struct call_flush {
|
||||
void operator()(THandlers& handlers) {
|
||||
std::get<N>(handlers).flush();
|
||||
call_flush<N+1, SIZE, THandlers>()(handlers);
|
||||
}
|
||||
};
|
||||
|
||||
template <int SIZE, class THandlers>
|
||||
struct call_flush<SIZE, SIZE, THandlers> {
|
||||
void operator()(THandlers&) {}
|
||||
};
|
||||
|
||||
OSMIUM_CHAIN_HANDLER_CALL(node, Node)
|
||||
OSMIUM_CHAIN_HANDLER_CALL(way, Way)
|
||||
OSMIUM_CHAIN_HANDLER_CALL(relation, Relation)
|
||||
OSMIUM_CHAIN_HANDLER_CALL(changeset, Changeset)
|
||||
OSMIUM_CHAIN_HANDLER_CALL(area, Area)
|
||||
|
||||
public:
|
||||
|
||||
explicit ChainHandler(THandler&... handlers) :
|
||||
m_handlers(handlers...) {
|
||||
}
|
||||
|
||||
void node(osmium::Node& node) {
|
||||
call_node<0, sizeof...(THandler), handlers_type>()(m_handlers, node);
|
||||
}
|
||||
|
||||
void way(osmium::Way& way) {
|
||||
call_way<0, sizeof...(THandler), handlers_type>()(m_handlers, way);
|
||||
}
|
||||
|
||||
void relation(osmium::Relation& relation) {
|
||||
call_relation<0, sizeof...(THandler), handlers_type>()(m_handlers, relation);
|
||||
}
|
||||
|
||||
void changeset( osmium::Changeset& changeset) {
|
||||
call_changeset<0, sizeof...(THandler), handlers_type>()(m_handlers, changeset);
|
||||
}
|
||||
|
||||
void area(osmium::Area& area) {
|
||||
call_area<0, sizeof...(THandler), handlers_type>()(m_handlers, area);
|
||||
}
|
||||
|
||||
void flush() {
|
||||
call_flush<0, sizeof...(THandler), handlers_type>()(m_handlers);
|
||||
}
|
||||
|
||||
}; // class ChainHandler
|
||||
|
||||
} // namespace handler
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_HANDLER_CHAIN_HPP
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
#ifndef OSMIUM_HANDLER_DISK_STORE_HPP
|
||||
#define OSMIUM_HANDLER_DISK_STORE_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (http://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013,2014 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 <cstddef>
|
||||
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/index/map.hpp>
|
||||
#include <osmium/io/detail/read_write.hpp>
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/memory/item_iterator.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
#include <osmium/osm/relation.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/osm/way.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace handler {
|
||||
|
||||
/**
|
||||
*
|
||||
* Note: This handler will only work if either all object IDs are
|
||||
* positive or all object IDs are negative.
|
||||
*/
|
||||
class DiskStore : public osmium::handler::Handler {
|
||||
|
||||
typedef osmium::index::map::Map<unsigned_object_id_type, size_t> offset_index_type;
|
||||
|
||||
size_t m_offset = 0;
|
||||
int m_data_fd;
|
||||
|
||||
offset_index_type& m_node_index;
|
||||
offset_index_type& m_way_index;
|
||||
offset_index_type& m_relation_index;
|
||||
|
||||
public:
|
||||
|
||||
explicit DiskStore(int data_fd, offset_index_type& node_index, offset_index_type& way_index, offset_index_type& relation_index) :
|
||||
m_data_fd(data_fd),
|
||||
m_node_index(node_index),
|
||||
m_way_index(way_index),
|
||||
m_relation_index(relation_index) {
|
||||
}
|
||||
|
||||
DiskStore(const DiskStore&) = delete;
|
||||
DiskStore& operator=(const DiskStore&) = delete;
|
||||
|
||||
~DiskStore() noexcept = default;
|
||||
|
||||
void node(const osmium::Node& node) {
|
||||
m_node_index.set(node.positive_id(), m_offset);
|
||||
m_offset += node.byte_size();
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) {
|
||||
m_way_index.set(way.positive_id(), m_offset);
|
||||
m_offset += way.byte_size();
|
||||
}
|
||||
|
||||
void relation(const osmium::Relation& relation) {
|
||||
m_relation_index.set(relation.positive_id(), m_offset);
|
||||
m_offset += relation.byte_size();
|
||||
}
|
||||
|
||||
// XXX
|
||||
void operator()(const osmium::memory::Buffer& buffer) {
|
||||
osmium::io::detail::reliable_write(m_data_fd, buffer.data(), buffer.committed());
|
||||
|
||||
osmium::apply(buffer.begin(), buffer.end(), *this);
|
||||
}
|
||||
|
||||
}; // class DiskStore
|
||||
|
||||
} // namespace handler
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_HANDLER_DISK_STORE_HPP
|
||||
Vendored
+294
@@ -0,0 +1,294 @@
|
||||
#ifndef OSMIUM_HANDLER_DUMP_HPP
|
||||
#define OSMIUM_HANDLER_DUMP_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (http://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013,2014 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
|
||||
@@ -0,0 +1,148 @@
|
||||
#ifndef OSMIUM_HANDLER_NODE_LOCATIONS_FOR_WAYS_HPP
|
||||
#define OSMIUM_HANDLER_NODE_LOCATIONS_FOR_WAYS_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (http://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013,2014 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/index/index.hpp>
|
||||
#include <osmium/index/map/dummy.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
#include <osmium/osm/node_ref.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/osm/way.hpp>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace handler {
|
||||
|
||||
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> dummy_type;
|
||||
|
||||
/**
|
||||
* Handler to retrieve locations from nodes and add them to ways.
|
||||
*
|
||||
* @tparam TStoragePosIDs Class that handles the actual storage of the node locations
|
||||
* (for positive IDs). It must support the set(id, value) and
|
||||
* get(id) methods.
|
||||
* @tparam TStorageNegIDs Same but for negative IDs.
|
||||
*/
|
||||
template <class TStoragePosIDs, class TStorageNegIDs = dummy_type>
|
||||
class NodeLocationsForWays : public osmium::handler::Handler {
|
||||
|
||||
/// Object that handles the actual storage of the node locations (with positive IDs).
|
||||
TStoragePosIDs& m_storage_pos;
|
||||
|
||||
/// Object that handles the actual storage of the node locations (with negative IDs).
|
||||
TStorageNegIDs& m_storage_neg;
|
||||
|
||||
bool m_ignore_errors {false};
|
||||
|
||||
bool m_must_sort {false};
|
||||
|
||||
// It is okay to have this static dummy instance, even when using several threads,
|
||||
// because it is read-only.
|
||||
static dummy_type& get_dummy() {
|
||||
static dummy_type instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
explicit NodeLocationsForWays(TStoragePosIDs& storage_pos,
|
||||
TStorageNegIDs& storage_neg = get_dummy()) :
|
||||
m_storage_pos(storage_pos),
|
||||
m_storage_neg(storage_neg) {
|
||||
}
|
||||
|
||||
NodeLocationsForWays(const NodeLocationsForWays&) = delete;
|
||||
NodeLocationsForWays& operator=(const NodeLocationsForWays&) = delete;
|
||||
|
||||
~NodeLocationsForWays() noexcept = default;
|
||||
|
||||
void ignore_errors() {
|
||||
m_ignore_errors = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the location of the node in the storage.
|
||||
*/
|
||||
void node(const osmium::Node& node) {
|
||||
m_must_sort = true;
|
||||
const osmium::object_id_type id = node.id();
|
||||
if (id >= 0) {
|
||||
m_storage_pos.set(id, node.location());
|
||||
} else {
|
||||
m_storage_neg.set(-id, node.location());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get location of node with given id.
|
||||
*/
|
||||
osmium::Location get_node_location(const osmium::object_id_type id) const {
|
||||
return id >= 0 ? m_storage_pos.get(id) : m_storage_neg.get(-id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve locations of all nodes in the way from storage and add
|
||||
* them to the way object.
|
||||
*/
|
||||
void way(osmium::Way& way) {
|
||||
if (m_must_sort) {
|
||||
m_storage_pos.sort();
|
||||
m_storage_neg.sort();
|
||||
m_must_sort = false;
|
||||
}
|
||||
bool error = false;
|
||||
for (auto& node_ref : way.nodes()) {
|
||||
try {
|
||||
node_ref.location(get_node_location(node_ref.ref()));
|
||||
if (!node_ref.location()) {
|
||||
error = true;
|
||||
}
|
||||
} catch (osmium::not_found&) {
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
if (error && !m_ignore_errors) {
|
||||
throw osmium::not_found("not found");
|
||||
}
|
||||
}
|
||||
|
||||
}; // class NodeLocationsForWays
|
||||
|
||||
} // namespace handler
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_HANDLER_NODE_LOCATIONS_FOR_WAYS_HPP
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
#ifndef OSMIUM_HANDLER_OBJECT_RELATIONS_HPP
|
||||
#define OSMIUM_HANDLER_OBJECT_RELATIONS_HPP
|
||||
|
||||
/*
|
||||
|
||||
This file is part of Osmium (http://osmcode.org/libosmium).
|
||||
|
||||
Copyright 2013,2014 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/index/multimap.hpp>
|
||||
#include <osmium/osm/node_ref.hpp>
|
||||
#include <osmium/osm/item_type.hpp>
|
||||
#include <osmium/osm/relation.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/osm/way.hpp>
|
||||
|
||||
namespace osmium {
|
||||
|
||||
namespace handler {
|
||||
|
||||
/**
|
||||
*
|
||||
* Note: This handler will only work if either all object IDs are
|
||||
* positive or all object IDs are negative.
|
||||
*/
|
||||
class ObjectRelations : public osmium::handler::Handler {
|
||||
|
||||
typedef osmium::index::multimap::Multimap<unsigned_object_id_type, unsigned_object_id_type> index_type;
|
||||
|
||||
index_type& m_index_n2w;
|
||||
index_type& m_index_n2r;
|
||||
index_type& m_index_w2r;
|
||||
index_type& m_index_r2r;
|
||||
|
||||
public:
|
||||
|
||||
explicit ObjectRelations(index_type& n2w, index_type& n2r, index_type& w2r, index_type& r2r) :
|
||||
m_index_n2w(n2w),
|
||||
m_index_n2r(n2r),
|
||||
m_index_w2r(w2r),
|
||||
m_index_r2r(r2r) {
|
||||
}
|
||||
|
||||
ObjectRelations(const ObjectRelations&) = delete;
|
||||
ObjectRelations& operator=(const ObjectRelations&) = delete;
|
||||
|
||||
~ObjectRelations() noexcept = default;
|
||||
|
||||
void way(const osmium::Way& way) {
|
||||
for (const auto& node_ref : way.nodes()) {
|
||||
m_index_n2w.set(node_ref.positive_ref(), way.positive_id());
|
||||
}
|
||||
}
|
||||
|
||||
void relation(const osmium::Relation& relation) {
|
||||
for (const auto& member : relation.members()) {
|
||||
switch (member.type()) {
|
||||
case osmium::item_type::node:
|
||||
m_index_n2r.set(member.positive_ref(), relation.positive_id());
|
||||
break;
|
||||
case osmium::item_type::way:
|
||||
m_index_w2r.set(member.positive_ref(), relation.positive_id());
|
||||
break;
|
||||
case osmium::item_type::relation:
|
||||
m_index_r2r.set(member.positive_ref(), relation.positive_id());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}; // class ObjectRelations
|
||||
|
||||
} // namespace handler
|
||||
|
||||
} // namespace osmium
|
||||
|
||||
#endif // OSMIUM_HANDLER_OBJECT_RELATIONS_HPP
|
||||
Reference in New Issue
Block a user