Osmium
0.1
|
#include <pbf.hpp>
Public Member Functions | |
PBF (Osmium::OSMFile &file) | |
bool | use_dense_format () const |
PBF & | use_dense_format (bool flag) |
bool | use_compression () const |
PBF & | use_compression (bool flag) |
int | location_granularity () const |
PBF & | location_granularity (int g) |
int | date_granularity () const |
PBF & | date_granularity (int g) |
bool | should_add_metadata () const |
PBF & | should_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 |
Osmium::Output::PBF::PBF | ( | Osmium::OSMFile & | file | ) | [inline] |
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.
void Osmium::Output::PBF::check_block_contents_counter | ( | ) | [inline, private] |
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
PBF& Osmium::Output::PBF::date_granularity | ( | int | g | ) | [inline] |
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.
int Osmium::Output::PBF::location_granularity | ( | ) | const [inline] |
getter to access the granularity
PBF& Osmium::Output::PBF::location_granularity | ( | int | g | ) | [inline] |
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
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.
bool Osmium::Output::PBF::should_add_metadata | ( | ) | const [inline] |
Getter to check whether metadata should be added.
PBF& Osmium::Output::PBF::should_add_metadata | ( | bool | flag | ) | [inline] |
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.
type | Type-string used in the BlobHeader. |
msg | Protobuf-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.
node | The 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.
node | The 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.
relation | The 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.
way | The way to add. |
size_t Osmium::Output::PBF::zlib_compress | ( | std::string & | in | ) | [inline, private] |
Take a string and pack its contents.
in | String input. |
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).
bool Osmium::Output::PBF::m_add_visible [private] |
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.
int Osmium::Output::PBF::m_date_granularity [private] |
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.
Delta<int64_t> Osmium::Output::PBF::m_delta_changeset [private] |
Delta<int64_t> Osmium::Output::PBF::m_delta_id [private] |
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.
Delta<int64_t> Osmium::Output::PBF::m_delta_lat [private] |
Delta<int64_t> Osmium::Output::PBF::m_delta_lon [private] |
Delta<int64_t> Osmium::Output::PBF::m_delta_timestamp [private] |
Delta<int64_t> Osmium::Output::PBF::m_delta_uid [private] |
Delta<uint32_t> Osmium::Output::PBF::m_delta_user_sid [private] |
int Osmium::Output::PBF::m_location_granularity [private] |
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.
bool Osmium::Output::PBF::m_should_add_metadata [private] |
While the .osm.pbf-format is able to carry all meta information, it is also able to omit this information to reduce size.
bool Osmium::Output::PBF::m_use_compression [private] |
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.
bool Osmium::Output::PBF::m_use_dense_format [private] |
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] |
uint16_t Osmium::Output::PBF::primitive_block_contents [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.
uint32_t Osmium::Output::PBF::primitive_block_size [private] |