Libosmium
2.20.0
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 () |
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. More... | |
std::array< mm_vector_type, 3 > | m_member_meta |
int | m_count_complete = 0 |
callback_func_type | m_callback |
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 |
|
private |
|
private |
One vector each for nodes, ways, and relations containing all mappings from member ids to their 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 |
|
inlineprivate |
|
inlinestaticprivate |
|
inlineprivate |
Find this object in the member vectors and add it to all relations that need it.
|
inlineprivate |
|
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 |
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.
type | Item type |
id | Object Id |
|
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 |
Get offset of a member in the members buffer.
type | Item type |
id | Object Id |
|
inlineprotected |
Get the relation from a member_meta.
|
inlineprotected |
Get the relation from a relation_meta.
|
inlineprotected |
|
inline |
Return reference to second pass handler.
|
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.
type | Item type |
id | Object Id |
|
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 10000 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.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Vector with all relations we are interested in.
|
private |