Libosmium 2.22.0 Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | 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 >:
[legend]

## 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 ()
bool | is_available (osmium::item_type type, osmium::object_id_type id)
size_t | get_offset (osmium::item_type type, osmium::object_id_type id)
std::pair< bool, size_t > | get_availability_and_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 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 ()
const osmium::Relation & | get_relation (size_t offset) const
const osmium::Relation & | get_relation (const RelationMeta &relation_meta) const
const osmium::Relation & | get_relation (const MemberMeta &member_meta) const
osmium::OSMObject & | get_member (size_t offset) const

## Private Types
enum | { initial_buffer_size = 1024UL * 1024UL }
using | mm_vector_type = std::vector<MemberMeta>
using | mm_iterator = mm_vector_type::iterator
using | callback_func_type = std::function<void(osmium::memory::Buffer&&)>

## Private Member Functions
iterator_range< mm_iterator > | find_member_meta (osmium::item_type type, osmium::object_id_type id)
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 RelationMeta &relation_meta)

## Static Private Member Functions
static iterator_range< mm_iterator >::iterator::difference_type | count_not_removed (const iterator_range< mm_iterator > &range)

## 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.
std::array< mm_vector_type, 3 > | m_member_meta
int | m_count_complete = 0
callback_func_type | m_callback

## Detailed Description

template<typename 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

  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?

Precondition
  The Ids of all objects must be unique in the input data.

## Member Typedef Documentation

## ◆ callback_func_type

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

using osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::callback_func_type = std::function<void(osmium::memory::Buffer&&)>
| private

## ◆ mm_iterator

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

using osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::mm_iterator = mm_vector_type::iterator
| private

## ◆ mm_vector_type

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

using osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::mm_vector_type = std::vector<MemberMeta>
| private

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

## Member Enumeration Documentation

## ◆ anonymous enum

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

anonymous enum
| private

Enumerator
initial_buffer_size |

## Constructor & Destructor Documentation

## ◆ Collector()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::Collector | ( |  | ) |
| inline

Create an Collector.

## Member Function Documentation

## ◆ add_relation()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::add_relation | ( | const osmium::Relation & | relation | ) |
| inline private

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.

## ◆ callback()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

callback_func_type osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::callback | ( |  | ) |
| inline protected

## ◆ clear_member_metas()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::clear_member_metas | ( | const RelationMeta & | relation_meta | ) |
| inline private

## ◆ count_not_removed()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

static iterator_range< mm_iterator >::iterator::difference_type osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::count_not_removed | ( | const iterator_range< mm_iterator > & | range | ) |
| inline static private

## ◆ find_and_add_object()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::find_and_add_object | ( | const osmium::OSMObject & | object | ) |
| inline private

Find this object in the member vectors and add it to all relations that need it.

Returns
  true if the member was added to at least one relation and false otherwise

## ◆ find_member_meta()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

iterator_range< mm_iterator > osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::find_member_meta | ( | osmium::item_type | type,
|  | osmium::object_id_type | id )
| inline private

## ◆ flush()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::flush | ( |  | ) |
| inline protected

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.

## ◆ get_availability_and_offset()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

std::pair< bool, size_t > osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_availability_and_offset | ( | osmium::item_type | type,
|  | osmium::object_id_type | id )
| inline

Checks whether a member is available in the members buffer and returns its offset.

If the member is not available, the boolean returned as the first element in the pair is false. In that case the offset in the second element is undefined.

If the member is available, the boolean returned as the first element in the pair is true and the second element of the pair contains the offset into the members buffer.

Parameters

  type | Item type
  id | Object Id

Returns
  Pair of bool (showing availability) and the offset.

## ◆ get_incomplete_relations()

template<typename 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.

## ◆ get_member()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

osmium::OSMObject & osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_member | ( | size_t | offset | ) | const
| inline protected

## ◆ get_offset()

template<typename 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

Get offset of a member in the members buffer.

Precondition
  The member must be available. If you are not sure, call get_availability_and_offset() instead.

Parameters

  type | Item type
  id | Object Id

Returns
  The offset of the object in the members buffer.

## ◆ get_relation() [1/3]

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

const osmium::Relation & osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_relation | ( | const MemberMeta & | member_meta | ) | const
| inline protected

Get the relation from a member_meta.

## ◆ get_relation() [2/3]

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

const osmium::Relation & osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_relation | ( | const RelationMeta & | relation_meta | ) | const
| inline protected

Get the relation from a relation_meta.

## ◆ get_relation() [3/3]

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

const osmium::Relation & osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::get_relation | ( | size_t | offset | ) | const
| inline protected

## ◆ handler()

template<typename 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.

## ◆ is_available()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::is_available | ( | osmium::item_type | type,
|  | osmium::object_id_type | id )
| inline

Is the given member available in the members buffer?

If you also need the offset of the object, use get_availability_and_offset() instead, it is more efficient that way.

Parameters

  type | Item type
  id | Object Id

Returns
  True if the object is available, false otherwise.

## ◆ keep_member()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::keep_member | ( | const RelationMeta & | ,
|  | const osmium::RelationMember & | ) const
| inline protected

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.

## ◆ keep_relation()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

bool osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::keep_relation | ( | const osmium::Relation & |  | ) | const
| inline protected

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.

## ◆ member_meta()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

std::vector< MemberMeta > & osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::member_meta | ( | const item_type | type | ) |
| inline protected

## ◆ members_buffer()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

osmium::memory::Buffer & osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::members_buffer | ( |  | ) |
| inline

## ◆ moving_in_buffer()

template<typename 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

## ◆ node_not_in_any_relation()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::node_not_in_any_relation | ( | const osmium::Node & |  | ) |
| inline protected

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.

## ◆ possibly_purge_removed_members()

template<typename 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 10000 calls. This could probably be improved upon.

## ◆ read_relations() [1/2]

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>
template<typename TIter >

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::read_relations | ( | TIter | begin,
|  | TIter | end )
| inline

## ◆ read_relations() [2/2]

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>
template<typename TSource >

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::read_relations | ( | TSource & | source | ) |
| inline

## ◆ relation_not_in_any_relation()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::relation_not_in_any_relation | ( | const osmium::Relation & |  | ) |
| inline protected

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.

## ◆ relations()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

const std::vector< RelationMeta > & osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::relations | ( |  | ) | const
| inline protected

## ◆ sort_member_meta()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::sort_member_meta | ( |  | ) |
| inline private

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

## ◆ used_memory()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

uint64_t osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::used_memory | ( |  | ) | const
| inline

## ◆ way_not_in_any_relation()

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

void osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::way_not_in_any_relation | ( | const osmium::Way & |  | ) |
| inline protected

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

## ◆ m_callback

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

callback_func_type osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_callback
| private

## ◆ m_count_complete

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

int osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_count_complete = 0
| private

## ◆ m_handler_pass2

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

HandlerPass2 osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_handler_pass2
| private

## ◆ m_member_meta

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

std::array<mm_vector_type, 3> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_member_meta
| private

## ◆ m_members_buffer

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

osmium::memory::Buffer osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_members_buffer
| private

## ◆ m_relations

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

std::vector<RelationMeta> osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_relations
| private

Vector with all relations we are interested in.

## ◆ m_relations_buffer

template<typename TCollector , bool TNodes, bool TWays, bool TRelations>

osmium::memory::Buffer osmium::relations::Collector< TCollector, TNodes, TWays, TRelations >::m_relations_buffer
| private

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

- include/osmium/relations/collector.hpp