Libosmium
2.5.4
Fast and flexible C++ library for working with OpenStreetMap data
|
#include <collector.hpp>
Classes | |
class | HandlerPass1 |
class | HandlerPass2 |
Public Member Functions | |
Collector () | |
uint64_t | used_memory () const |
HandlerPass2 & | handler (const callback_func_type &callback=nullptr) |
osmium::memory::Buffer & | members_buffer () |
size_t | get_offset (osmium::item_type type, osmium::object_id_type id) |
template<typename TIter > | |
void | read_relations (TIter begin, TIter end) |
template<typename TSource > | |
void | read_relations (TSource &source) |
void | moving_in_buffer (size_t old_offset, size_t new_offset) |
void | possibly_purge_removed_members () |
std::vector< const osmium::Relation * > | get_incomplete_relations () const |
Protected Member Functions | |
std::vector< MemberMeta > & | member_meta (const item_type type) |
callback_func_type | callback () |
const std::vector< RelationMeta > & | relations () const |
bool | keep_relation (const osmium::Relation &) const |
bool | keep_member (const osmium::relations::RelationMeta &, const osmium::RelationMember &) const |
void | node_not_in_any_relation (const osmium::Node &) |
void | way_not_in_any_relation (const osmium::Way &) |
void | relation_not_in_any_relation (const osmium::Relation &) |
void | flush () |
void | clean_assembled_relations () |
const osmium::Relation & | get_relation (size_t offset) const |
const osmium::Relation & | get_relation (const RelationMeta &relation_meta) const |
osmium::OSMObject & | get_member (size_t offset) const |
Private Types | |
typedef std::function< void(osmium::memory::Buffer &&)> | callback_func_type |
Private Member Functions | |
void | add_relation (const osmium::Relation &relation) |
void | sort_member_meta () |
bool | find_and_add_object (const osmium::OSMObject &object) |
void | clear_member_metas (const osmium::relations::RelationMeta &relation_meta) |
Private Attributes | |
HandlerPass2 | m_handler_pass2 |
osmium::memory::Buffer | m_relations_buffer |
osmium::memory::Buffer | m_members_buffer |
std::vector< RelationMeta > | m_relations |
Vector with all relations we are interested in. More... | |
std::vector< MemberMeta > | m_member_meta [3] |
int | m_count_complete = 0 |
callback_func_type | m_callback |
Static Private Attributes | |
static constexpr size_t | initial_buffer_size = 1024 * 1024 |
The Collector class collects members of a relation. This is a generic base class that can be used to assemble all kinds of relations. It has numerous hooks you can implement in derived classes to customize its behaviour.
The collector provides two handlers (HandlerPass1 and HandlerPass2) for a first and second pass through an input file, respectively. In the first pass all relations we are interested in are stored in RelationMeta objects in the m_relations vector. All members we are interested in are stored in MemberMeta objects in the m_member_meta vectors. The MemberMeta objects also store the information where the relations containing those members are to be found.
Later the m_member_meta vectors are sorted according to the member ids so that a binary search (with std::equal_range) can be used in the second pass to find the parent relations for each node, way, or relation coming along. The member objects are stored together with their relation and once a relation is complete the complete_relation() method is called which you must overwrite in a derived class of Collector.
TCollector | Derived class of this class. |
TNodes | Are we interested in member nodes? |
TWays | Are we interested in member ways? |
TRelations | Are we interested in member relations? |
|
private |
|
inline |
Create an Collector.
|
inlineprivate |
Tell the Collector that you are interested in this relation and want it kept until all members have been assembled and it is handed back to you.
The relation is copied and stored in a buffer inside the collector.
|
inlineprotected |
|
inlineprotected |
This removes all relations that have already been assembled from the m_relations vector.
|
inlineprivate |
|
inlineprivate |
Find this object in the member vectors and add it to all relations that need it.
|
inlineprotected |
This method is called from the 2nd pass handler when all objects of types we are interested in have been seen.
Overwrite this method in a child class if you are interested in this.
Note that even after this call members might be missing if they were not in the input file! The derived class has to handle this case.
|
inline |
Get a vector with pointers to all Relations that could not be completed, because members were missing in the input data.
Note that these pointers point into memory allocated and owned by the Collector object.
|
inlineprotected |
|
inline |
|
inlineprotected |
|
inlineprotected |
Get the relation from a relation_meta.
|
inline |
Return reference to second pass handler.
|
inlineprotected |
This method is called for every member of every relation that should be kept. It should decide if the member is interesting or not and return true or false to signal that. Only interesting members are later added to the relation.
Overwrite this method in a child class. In the MultiPolygonCollector this is for instance used to only keep members of type way and ignore all others.
|
inlineprotected |
This method is called from the first pass handler for every relation in the input, to check whether it should be kept.
Overwrite this method in a child class to only add relations you are interested in, for instance depending on the type tag. Storing relations takes a lot of memory, so it makes sense to filter this as much as possible.
|
inlineprotected |
|
inline |
|
inline |
|
inlineprotected |
This method is called for all nodes that are not a member of any relation.
Overwrite this method in a child class if you are interested in this.
|
inline |
Decide whether to purge removed members and then do it.
Currently the purging is done every thousand calls. This could probably be improved upon.
|
inline |
|
inline |
|
inlineprotected |
This method is called for all relations that are not a member of any relation.
Overwrite this method in a child class if you are interested in this.
|
inlineprotected |
|
inlineprivate |
Sort the vectors with the member infos so that we can do binary search on them.
|
inline |
|
inlineprotected |
This method is called for all ways that are not a member of any relation.
Overwrite this method in a child class if you are interested in this.
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
One vector each for nodes, ways, and relations containing all mappings from member ids to their relations.
|
private |
|
private |
Vector with all relations we are interested in.
|
private |