Osmium  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Osmium::Output::PBF Class Reference

#include <pbf.hpp>

Inheritance diagram for Osmium::Output::PBF:
Inheritance graph
[legend]
Collaboration diagram for Osmium::Output::PBF:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PBF (Osmium::OSMFile &file)
bool use_dense_format () const
PBFuse_dense_format (bool flag)
bool use_compression () const
PBFuse_compression (bool flag)
int location_granularity () const
PBFlocation_granularity (int g)
int date_granularity () const
PBFdate_granularity (int g)
bool should_add_metadata () const
PBFshould_add_metadata (bool flag)
void init (Osmium::OSM::Meta &meta)
void node (const shared_ptr< Osmium::OSM::Node const > &node)
void way (const shared_ptr< Osmium::OSM::Way const > &way)
void relation (const shared_ptr< Osmium::OSM::Relation const > &relation)
void final ()

Private Member Functions

size_t zlib_compress (std::string &in)
void store_blob (const std::string &type, const google::protobuf::MessageLite &msg)
void map_string_ids ()
template<class pbf_object_t >
void map_common_string_ids (pbf_object_t *in)
int64_t lonlat2int (double lonlat)
int64_t timestamp2int (time_t timestamp)
template<class pbf_object_t >
void apply_common_info (const shared_ptr< Osmium::OSM::Object const > &in, pbf_object_t *out)
void store_header_block ()
void store_primitive_block ()
void check_block_contents_counter ()
void write_node (const shared_ptr< Osmium::OSM::Node const > &node)
void write_dense_node (const shared_ptr< Osmium::OSM::Node const > &node)
void write_way (const shared_ptr< Osmium::OSM::Way const > &way)
void write_relation (const shared_ptr< Osmium::OSM::Relation const > &relation)

Private Attributes

OSMPBF::Blob pbf_blob
OSMPBF::BlobHeader pbf_blob_header
OSMPBF::HeaderBlock pbf_header_block
OSMPBF::PrimitiveBlock pbf_primitive_block
OSMPBF::PrimitiveGroup * pbf_nodes
OSMPBF::PrimitiveGroup * pbf_ways
OSMPBF::PrimitiveGroup * pbf_relations
int m_location_granularity
int m_date_granularity
bool m_use_dense_format
bool m_use_compression
bool m_should_add_metadata
bool m_add_visible
uint16_t primitive_block_contents
uint32_t primitive_block_size
Osmium::StringTable string_table
char m_compression_buffer [OSMPBF::max_uncompressed_blob_size]
 Buffer used while compressing blobs.
Delta< int64_t > m_delta_id
Delta< int64_t > m_delta_lat
Delta< int64_t > m_delta_lon
Delta< int64_t > m_delta_timestamp
Delta< int64_t > m_delta_changeset
Delta< int64_t > m_delta_uid
Delta< uint32_t > m_delta_user_sid

Static Private Attributes

static const uint32_t max_block_contents = 8000
static const int buffer_fill_percent = 95

Constructor & Destructor Documentation

Create PBF output object from OSMFile.


Member Function Documentation

template<class pbf_object_t >
void Osmium::Output::PBF::apply_common_info ( const shared_ptr< Osmium::OSM::Object const > &  in,
pbf_object_t *  out 
) [inline, private]

helper function used in the write()-calls to apply common information from an osmium-object onto a pbf-object.

pbf_object_t is either OSMPBF::Node, OSMPBF::Way or OSMPBF::Relation.

this little function checks primitive_block_contents counter against its maximum and calls store_primitive_block to flush the block to the disk when it's reached. It's also responsible for increasing this counter.

this function also checks the estimated size of the current block and calls store_primitive_block when the estimated size reaches buffer_fill_percent of the maximum uncompressed blob size.

int Osmium::Output::PBF::date_granularity ( ) const [inline]

getter to access the date_granularity

Set date granularity.

void Osmium::Output::PBF::final ( ) [inline, virtual]

Finalize the writing process, flush any open primitive blocks to the file and close the file.

Implements Osmium::Output::Base.

void Osmium::Output::PBF::init ( Osmium::OSM::Meta meta) [inline, virtual]

Initialize the writing process.

This initializes the header-block, sets the required-features and the writing-program and adds the obligatory StringTable-Index 0.

Implements Osmium::Output::Base.

getter to access the granularity

setter to set the granularity

int64_t Osmium::Output::PBF::lonlat2int ( double  lonlat) [inline, private]

convert a double lat or lon value to an int, respecting the current blocks granularity

template<class pbf_object_t >
void Osmium::Output::PBF::map_common_string_ids ( pbf_object_t *  in) [inline, private]

a helper function used in map_string_ids to map common interim string-ids of the user name and all tags to real string ids.

pbf_object_t is either OSMPBF::Node, OSMPBF::Way or OSMPBF::Relation.

void Osmium::Output::PBF::map_string_ids ( ) [inline, private]

Before a PrimitiveBlock gets serialized, all interim StringTable-ids needs to be mapped to the associated real StringTable ids. This is done in this function.

This function needs to know about the concrete structure of all item types to find all occurrences of string-ids.

void Osmium::Output::PBF::node ( const shared_ptr< Osmium::OSM::Node const > &  node) [inline, virtual]

Add a node to the pbf.

A call to this method won't write the node to the file directly but cache it for later bulk-writing. Calling write_final ensures that everything gets written and every file pointer is closed.

Implements Osmium::Output::Base.

void Osmium::Output::PBF::relation ( const shared_ptr< Osmium::OSM::Relation const > &  relation) [inline, virtual]

Add a relation to the pbf.

A call to this method won't write the way to the file directly but cache it for later bulk-writing. Calling write_final ensures that everything gets written and every file pointer is closed.

Implements Osmium::Output::Base.

Getter to check whether metadata should be added.

Setter to set whether to add metadata.

void Osmium::Output::PBF::store_blob ( const std::string &  type,
const google::protobuf::MessageLite &  msg 
) [inline, private]

Serialize a protobuf-message together into a Blob, optionally apply compression and write it together with a BlobHeader to the file.

Parameters:
typeType-string used in the BlobHeader.
msgProtobuf-message.
void Osmium::Output::PBF::store_header_block ( ) [inline, private]

store the current pbf_header_block into a Blob and clear this struct afterwards.

void Osmium::Output::PBF::store_primitive_block ( ) [inline, private]

store the interim StringTable to the current pbf_primitive_block, map all interim string ids to real StringTable ids and then store the current pbf_primitive_block into a Blob and clear this struct and all related pointers and maps afterwards.

int64_t Osmium::Output::PBF::timestamp2int ( time_t  timestamp) [inline, private]

convert a timestamp to an int, respecting the current blocks granularity

bool Osmium::Output::PBF::use_compression ( ) const [inline]

getter to check whether zlib-compression is used

PBF& Osmium::Output::PBF::use_compression ( bool  flag) [inline]

setter to set whether zlib-compression is used

bool Osmium::Output::PBF::use_dense_format ( ) const [inline]

getter to check whether the densenodes-feature is used

PBF& Osmium::Output::PBF::use_dense_format ( bool  flag) [inline]

setter to set whether the densenodes-feature is used

void Osmium::Output::PBF::way ( const shared_ptr< Osmium::OSM::Way const > &  way) [inline, virtual]

Add a way to the pbf.

A call to this method won't write the way to the file directly but cache it for later bulk-writing. Calling write_final ensures that everything gets written and every file pointer is closed.

Implements Osmium::Output::Base.

void Osmium::Output::PBF::write_dense_node ( const shared_ptr< Osmium::OSM::Node const > &  node) [inline, private]

Add a node to the block using DenseNodes.

Parameters:
nodeThe node to add.
void Osmium::Output::PBF::write_node ( const shared_ptr< Osmium::OSM::Node const > &  node) [inline, private]

Add a node to the block.

Parameters:
nodeThe node to add.
void Osmium::Output::PBF::write_relation ( const shared_ptr< Osmium::OSM::Relation const > &  relation) [inline, private]

Add a relation to the block.

Parameters:
relationThe relation to add.
void Osmium::Output::PBF::write_way ( const shared_ptr< Osmium::OSM::Way const > &  way) [inline, private]

Add a way to the block.

Parameters:
wayThe way to add.
size_t Osmium::Output::PBF::zlib_compress ( std::string &  in) [inline, private]

Take a string and pack its contents.

Parameters:
inString input.
Returns:
Number of bytes after compression.

Member Data Documentation

const int Osmium::Output::PBF::buffer_fill_percent = 95 [static, private]

The output buffer (block) will be filled to about 95% and then written to disk. This leaves more than enough space for the string table (which typically needs about 0.1 to 0.3% of the block size).

Should the visible flag be added on objects?

char Osmium::Output::PBF::m_compression_buffer[OSMPBF::max_uncompressed_blob_size] [private]

Buffer used while compressing blobs.

the granularity used for representing timestamps is also adjustable in multiples of 1 millisecond. The default scaling factor is 1000 milliseconds, which is the current resolution of the OSM database.

These variables are used to calculate the delta-encoding while storing dense-nodes. It holds the last seen values from which the difference is stored into the protobuf.

to flexibly handle multiple resolutions, the granularity, or resolution used for representing locations is adjustable in multiples of 1 nanodegree. The default scaling factor is 100 nanodegrees, corresponding to about ~1cm at the equator. These is the current resolution of the OSM database.

While the .osm.pbf-format is able to carry all meta information, it is also able to omit this information to reduce size.

should the PBF blobs contain zlib compressed data?

the zlib compression is optional, it's possible to store the blobs in raw format. Disabling the compression can improve the writing speed a little but the output will be 2x to 3x bigger.

should nodes be serialized into the dense format?

nodes can be encoded one of two ways, as a Node (m_use_dense_format = false) and a special dense format. In the dense format, all information is stored 'column wise', as an array of ID's, array of latitudes, and array of longitudes. Each column is delta-encoded. This reduces header overheads and allows delta-coding to work very effectively.

const uint32_t Osmium::Output::PBF::max_block_contents = 8000 [static, private]

Maximum number of items in a primitive block.

The uncompressed length of a Blob *should* be less than 16 megabytes and *must* be less than 32 megabytes.

A block may contain any number of entities, as long as the size limits for the surrounding blob are obeyed. However, for simplicity, the current Osmosis (0.38) as well as Osmium implementation always uses at most 8k entities in a block.

OSMPBF::Blob Osmium::Output::PBF::pbf_blob [private]

protobuf-struct of a Blob

OSMPBF::BlobHeader Osmium::Output::PBF::pbf_blob_header [private]

protobuf-struct of a BlobHeader

OSMPBF::HeaderBlock Osmium::Output::PBF::pbf_header_block [private]

protobuf-struct of a HeaderBlock

OSMPBF::PrimitiveGroup* Osmium::Output::PBF::pbf_nodes [private]

pointer to PrimitiveGroups inside the current PrimitiveBlock, used for writing nodes, ways or relations

OSMPBF::PrimitiveBlock Osmium::Output::PBF::pbf_primitive_block [private]

protobuf-struct of a PrimitiveBlock

OSMPBF::PrimitiveGroup* Osmium::Output::PBF::pbf_relations [private]
OSMPBF::PrimitiveGroup* Osmium::Output::PBF::pbf_ways [private]

counter used to quickly check the number of objects stored inside the current PrimitiveBlock. When the counter reaches max_block_contents the PrimitiveBlock is serialized into a Blob and flushed to the file.

this check is performed in check_block_contents_counter() which is called once for each object.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines