Beispiel #1
0
            /**
             * Add a node to the block.
             *
             * @param node The node to add.
             */
            void write_node(const shared_ptr<Osmium::OSM::Node const>& node) {
                OSMPBF::Node* pbf_node = pbf_nodes->add_nodes();

                // copy the common meta-info from the osmium-object to the pbf-object
                apply_common_info(node, pbf_node);

                // modify lat & lon to integers, respecting the block's granularity and copy
                // the ints to the pbf-object
                pbf_node->set_lon(lonlat2int(node->get_lon()));
                pbf_node->set_lat(lonlat2int(node->get_lat()));
            }
Beispiel #2
0
            /**
             * Add a way to the block.
             *
             * @param way The way to add.
             */
            void write_way(const shared_ptr<Osmium::OSM::Way const>& way) {
                // add a way to the group
                OSMPBF::Way* pbf_way = pbf_ways->add_ways();

                // copy the common meta-info from the osmium-object to the pbf-object
                apply_common_info(way, pbf_way);

                // last way-node-id used for delta-encoding
                Delta<int64_t> delta_id;

                // iterate over all way-nodes
                for (int i=0, l = way->node_count(); i<l; i++) {
                    // copy the way-node-id, delta encoded
                    pbf_way->add_refs(delta_id.update(way->get_node_id(i)));
                }
            }
Beispiel #3
0
            /**
             * Add a relation to the block.
             *
             * @param relation The relation to add.
             */
            void write_relation(const shared_ptr<Osmium::OSM::Relation const>& relation) {
                // add a relation to the group
                OSMPBF::Relation* pbf_relation = pbf_relations->add_relations();

                // copy the common meta-info from the osmium-object to the pbf-object
                apply_common_info(relation, pbf_relation);

                Delta<int64_t> delta_id;

                // iterate over all relation-members
                for (int i=0, l=relation->members().size(); i<l; i++) {
                    // save a pointer to the osmium-object representing the relation-member
                    const Osmium::OSM::RelationMember* mem = relation->get_member(i);

                    // record the relation-member role to the interim stringtable and copy the
                    // interim string-id to the pbf-object
                    pbf_relation->add_roles_sid(string_table.record_string(mem->role()));

                    // copy the relation-member-id, delta encoded
                    pbf_relation->add_memids(delta_id.update(mem->ref()));

                    // copy the relation-member-type, mapped to the OSMPBF enum
                    switch (mem->type()) {
                        case 'n':
                            pbf_relation->add_types(OSMPBF::Relation::NODE);
                            break;
                        case 'w':
                            pbf_relation->add_types(OSMPBF::Relation::WAY);
                            break;
                        case 'r':
                            pbf_relation->add_types(OSMPBF::Relation::RELATION);
                            break;
                        default:
                            throw std::runtime_error("Unknown relation member type: " + mem->type());
                    }
                }

                // count up blob size by the size of the Relation
                primitive_block_size += pbf_relation->ByteSize();
            }