Libosmium  2.1.0
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
osmium::relations::Collector< TCollector, TNodes, TWays, TRelations > Class Template Reference

#include <collector.hpp>

Collaboration diagram for osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >:
Collaboration graph
[legend]

Classes

class  HandlerPass1
 
class  HandlerPass2
 

Public Types

typedef std::function< void(osmium::memory::Buffer &&)> callback_func_type
 

Public Member Functions

 Collector ()
 
uint64_t used_memory () const
 
HandlerPass2handler (const callback_func_type &callback=nullptr)
 
osmium::memory::Buffermembers_buffer ()
 
size_t get_offset (osmium::item_type type, osmium::object_id_type id)
 
template<class TIter >
void read_relations (TIter begin, TIter end)
 
template<class 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
 

Public 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 Public Attributes

static constexpr size_t initial_buffer_size = 1024 * 1024
 

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::Relationget_relation (size_t offset) const
 
const osmium::Relationget_relation (const RelationMeta &relation_meta) const
 
osmium::OSMObjectget_member (size_t offset) const
 
void add_relation (const osmium::Relation &relation)
 
void sort_member_meta ()
 

Detailed Description

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
class osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >

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.

Template Parameters
TCollectorDerived class of this class.
TNodesAre we interested in member nodes?
TWaysAre we interested in member ways?
TRelationsAre we interested in member relations?

Member Typedef Documentation

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
typedef std::function<void(osmium::memory::Buffer&&)> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::callback_func_type

Constructor & Destructor Documentation

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::Collector ( )
inline

Create an Collector.

Member Function Documentation

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::add_relation ( const osmium::Relation relation)
inlineprotected

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.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
callback_func_type osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::callback ( )
inlineprotected
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::clean_assembled_relations ( )
inlineprotected

This removes all relations that have already been assembled from the m_relations vector.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::flush ( )
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.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
std::vector<const osmium::Relation*> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_incomplete_relations ( ) const
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.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
osmium::OSMObject& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_member ( size_t  offset) const
inlineprotected
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
size_t osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_offset ( osmium::item_type  type,
osmium::object_id_type  id 
)
inline
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
const osmium::Relation& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_relation ( size_t  offset) const
inlineprotected
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
const osmium::Relation& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_relation ( const RelationMeta &  relation_meta) const
inlineprotected

Get the relation from a relation_meta.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
HandlerPass2& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::handler ( const callback_func_type callback = nullptr)
inline

Return reference to second pass handler.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::keep_member ( const osmium::relations::RelationMeta &  ,
const osmium::RelationMember  
) const
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.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::keep_relation ( const osmium::Relation ) const
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.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
std::vector<MemberMeta>& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::member_meta ( const item_type  type)
inlineprotected
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
osmium::memory::Buffer& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::members_buffer ( )
inline
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::moving_in_buffer ( size_t  old_offset,
size_t  new_offset 
)
inline
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::node_not_in_any_relation ( const osmium::Node )
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.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::possibly_purge_removed_members ( )
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.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
template<class TIter >
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::read_relations ( TIter  begin,
TIter  end 
)
inline
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
template<class TSource >
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::read_relations ( TSource &  source)
inline
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::relation_not_in_any_relation ( const osmium::Relation )
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.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
const std::vector<RelationMeta>& osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::relations ( ) const
inlineprotected
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::sort_member_meta ( )
inlineprotected

Sort the vectors with the member infos so that we can do binary search on them.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
uint64_t osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::used_memory ( ) const
inline
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::way_not_in_any_relation ( const osmium::Way )
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.

Member Data Documentation

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
constexpr size_t osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::initial_buffer_size = 1024 * 1024
static
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
callback_func_type osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_callback
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
int osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_count_complete = 0
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
HandlerPass2 osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_handler_pass2
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
std::vector<MemberMeta> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_member_meta[3]

One vector each for nodes, ways, and relations containing all mappings from member ids to their relations.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
osmium::memory::Buffer osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_members_buffer
template<class TCollector, bool TNodes, bool TWays, bool TRelations>
std::vector<RelationMeta> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_relations

Vector with all relations we are interested in.

template<class TCollector, bool TNodes, bool TWays, bool TRelations>
osmium::memory::Buffer osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_relations_buffer

The documentation for this class was generated from the following file: