void way(const shared_ptr<const OSM::Way> &way) { Osmium::OSM::TagList::const_iterator tagIt; for(tagIt = way->tags().begin(); tagIt != way->tags().end(); ++tagIt) { std::string sKey(tagIt->key()); std::string sVal(tagIt->value()); if(sKey.compare("natural") == 0) { if(sVal.compare("coastline") == 0) { Osmium::OSM::WayNodeList::const_iterator nodeIt; for(nodeIt = way->nodes().begin(); nodeIt != way->nodes().end(); ++nodeIt) { std::unordered_map<size_t,Node>::iterator findIt; size_t findId = nodeIt->ref(); findIt = m_listNodes.find(findId); if(findIt == m_listNodes.end()) { return; } // way pointing to node not in data set std::cout << std::fixed << std::setprecision(7) << findIt->second.lon << "," << std::fixed << std::setprecision(7) << findIt->second.lat << "," << 0 << "\n"; } } } } }
/** * 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. */ template <class pbf_object_t> void apply_common_info(const shared_ptr<Osmium::OSM::Object const>& in, pbf_object_t* out) { // set the object-id out->set_id(in->id()); // iterate over all tags and set the keys and vals, recording the strings in the // interim StringTable and storing the interim ids Osmium::OSM::TagList::const_iterator end = in->tags().end(); for (Osmium::OSM::TagList::const_iterator it = in->tags().begin(); it != end; ++it) { out->add_keys(string_table.record_string(it->key())); out->add_vals(string_table.record_string(it->value())); } if (should_add_metadata()) { // add an info-section to the pbf object and set the meta-info on it OSMPBF::Info* out_info = out->mutable_info(); if (m_add_visible) { out_info->set_visible(in->visible()); } out_info->set_version(in->version()); out_info->set_timestamp(timestamp2int(in->timestamp())); out_info->set_changeset(in->changeset()); out_info->set_uid(in->uid()); out_info->set_user_sid(string_table.record_string(in->user())); } }
// walk over all relation-versions void relation(const shared_ptr<Osmium::OSM::Relation const>& relation) { if(debug) fprintf(stderr, "hardcut relation %d v%d\n", relation->id(), relation->version()); else pg.relation(relation); // walk over all bboxes for(int i = 0, l = info->extracts.size(); i<l; i++) { // shorthand HardcutExtractInfo *extract = info->extracts[i]; // create a new relation NULL pointer shared_ptr<Osmium::OSM::Relation> newrelation; // walk over all relation members for(Osmium::OSM::RelationMemberList::const_iterator it = relation->members().begin(); it != relation->members().end(); ++it) { // if the relation members is in the node-id-tracker or the way-id-tracker of this bbox if((it->type() == 'n' && extract->node_tracker.get(it->ref())) || (it->type() == 'w' && extract->way_tracker.get(it->ref()))) { // if the new way pointer is NULL if(!newrelation) { // create a new relation with all meta-data and tags but without waynodes if(debug) fprintf(stderr, "creating cutted relation %d v%d for bbox[%d]\n", relation->id(), relation->version(), i); newrelation = shared_ptr<Osmium::OSM::Relation>(new Osmium::OSM::Relation()); newrelation->id(relation->id()); newrelation->version(relation->version()); newrelation->uid(relation->uid()); newrelation->changeset(relation->changeset()); newrelation->timestamp(relation->timestamp()); newrelation->visible(relation->visible()); newrelation->user(relation->user()); for(Osmium::OSM::TagList::const_iterator it = relation->tags().begin(); it != relation->tags().end(); ++it) { newrelation->tags().add(it->key(), it->value()); } } // add the member to the new relation if(debug) fprintf(stderr, "adding member %c id %d to cutted relation %d v%d for bbox[%d]\n", it->type(), it->ref(), relation->id(), relation->version(), i); newrelation->add_member(it->type(), it->ref(), it->role()); } } // if the relation pointer is not NULL if(newrelation.get()) { // write the way to the writer of this bbox if(debug) fprintf(stderr, "relation %d v%d is inside bbox[%d], writing it out\n", relation->id(), relation->version(), i); extract->writer->relation(newrelation); } } // record the last id last_id = relation->id(); }
/** * Add a node to the block using DenseNodes. * * @param node The node to add. */ void write_dense_node(const shared_ptr<Osmium::OSM::Node const>& node) { // add a DenseNodes-Section to the PrimitiveGroup OSMPBF::DenseNodes* dense = pbf_nodes->mutable_dense(); // copy the id, delta encoded dense->add_id(m_delta_id.update(node->id())); // copy the longitude, delta encoded dense->add_lon(m_delta_lon.update(lonlat2int(node->get_lon()))); // copy the latitude, delta encoded dense->add_lat(m_delta_lat.update(lonlat2int(node->get_lat()))); // in the densenodes structure keys and vals are encoded in an intermixed // array, individual nodes are seperated by a value of 0 (0 in the StringTable // is always unused) // so for three nodes the keys_vals array may look like this: 3 5 2 1 0 0 8 5 // the first node has two tags (3=>5 and 2=>1), the second node has does not // have any tags and the third node has a single tag (8=>5) Osmium::OSM::TagList::const_iterator end = node->tags().end(); for (Osmium::OSM::TagList::const_iterator it = node->tags().begin(); it != end; ++it) { dense->add_keys_vals(string_table.record_string(it->key())); dense->add_keys_vals(string_table.record_string(it->value())); } dense->add_keys_vals(0); if (should_add_metadata()) { // add a DenseInfo-Section to the PrimitiveGroup OSMPBF::DenseInfo* denseinfo = dense->mutable_denseinfo(); denseinfo->add_version(node->version()); if (m_add_visible) { denseinfo->add_visible(node->visible()); } // copy the timestamp, delta encoded denseinfo->add_timestamp(m_delta_timestamp.update(timestamp2int(node->timestamp()))); // copy the changeset, delta encoded denseinfo->add_changeset(m_delta_changeset.update(node->changeset())); // copy the user id, delta encoded denseinfo->add_uid(m_delta_uid.update(node->uid())); // record the user-name to the interim stringtable and copy the // interim string-id to the pbf-object denseinfo->add_user_sid(string_table.record_string(node->user())); } }
/** * checks the TagList against a list to decide if they look like the * way could potentially be a polygon. */ static bool looksLikePolygon(const Osmium::OSM::TagList& tags) { // iterate over all tags for(Osmium::OSM::TagList::const_iterator it = tags.begin(); it != tags.end(); ++it) { // iterate over all known polygon-tags for(int i = 0; polygons[i] != 0; i++) { // compare the tag name if(0 == strcmp(polygons[i], it->key())) { // yep, it looks like a polygon return true; } } } // no, this could never be a polygon return false; }
// walk over all way-versions void way(const shared_ptr<Osmium::OSM::Way const>& way) { if(debug) fprintf(stderr, "hardcut way %d v%d\n", way->id(), way->version()); else pg.way(way); // walk over all bboxes for(int i = 0, l = info->extracts.size(); i<l; i++) { // shorthand HardcutExtractInfo *extract = info->extracts[i]; // create a new way NULL pointer shared_ptr<Osmium::OSM::Way> newway; // walk over all waynodes for(osm_sequence_id_t ii = 0, ll = way->node_count(); ii < ll; ii++) { // shorthand osm_object_id_t node_id = way->get_node_id(ii); // if the waynode is in the node-id-tracker of this bbox if(extract->node_tracker.get(node_id)) { // if the new way pointer is NULL if(!newway) { // create a new way with all meta-data and tags but without waynodes if(debug) fprintf(stderr, "creating cutted way %d v%d for bbox[%d]\n", way->id(), way->version(), i); newway = shared_ptr<Osmium::OSM::Way>(new Osmium::OSM::Way()); newway->id(way->id()); newway->version(way->version()); newway->uid(way->uid()); newway->changeset(way->changeset()); newway->timestamp(way->timestamp()); newway->visible(way->visible()); newway->user(way->user()); for(Osmium::OSM::TagList::const_iterator it = way->tags().begin(); it != way->tags().end(); ++it) { newway->tags().add(it->key(), it->value()); } } // add the waynode to the new way if(debug) fprintf(stderr, "adding node-id %d to cutted way %d v%d for bbox[%d]\n", node_id, way->id(), way->version(), i); newway->add_node(node_id); } } // if the way pointer is not NULL if(newway.get()) { // enable way-writing for this bbox if(debug) fprintf(stderr, "way %d v%d is in bbox[%d]\n", way->id(), way->version(), i); // check for short ways if(newway->node_count() < 2) { if(debug) fprintf(stderr, "way %d v%d in bbox[%d] would only be %d nodes long, skipping\n", way->id(), way->version(), i, newway->node_count()); continue; } // write the way to the writer of this bbox if(debug) fprintf(stderr, "way %d v%d is inside bbox[%d], writing it out\n", way->id(), way->version(), i); extract->writer->way(newway); // record its id in the bboxes way-id-tracker extract->way_tracker.set(way->id()); } } // record the last id last_id = way->id(); }