/home/martin/workspace/OpenStreetNav/src/wayreduction/WayNodeFilter.cpp
Go to the documentation of this file.
00001 /*
00002  * WayNodeFiltering.cpp
00003  *
00004  *  Created on: Jan 13, 2012
00005  *      Author: martin
00006  */
00007 
00008 #include "WayNodeFilter.h"
00009 #include <algorithm>
00010 
00011 namespace wayred
00012 {
00013 
00014 WayNodeFilter::WayNodeFilter()
00015 {
00016 }
00017 
00018 WayNodeFilter::~WayNodeFilter()
00019 {
00020 }
00021 
00022 std::vector<osm::Way> WayNodeFilter::reduce_ways(const std::map<osm::Way, std::multimap<osm::Node, osm::Way, osm::LtByID> , osm::LtByID> & old_ways)
00023 {
00024     std::vector<osm::Way> ret;
00025     for (auto it = old_ways.begin(); it != old_ways.end(); ++it)
00026     {
00027         ret.push_back(process_way(it->first, it->second));
00028     }
00029     return ret;
00030 }
00031 
00032 osm::Way WayNodeFilter::process_way(const osm::Way& w, const std::multimap<osm::Node, osm::Way, osm::LtByID> & ndmap)
00033 {
00034     osm::Way ret(w.id);
00035     for (unsigned int i = 0; i < w.nodes.size(); ++i)
00036     {
00037         if (i == 0 || has_important_ways(w.nodes[i], ndmap) || i == w.nodes.size() - 1)
00038             ret.nodes.push_back(w.nodes[i]);
00039     }
00040     return ret;
00041 }
00042 
00043 void WayNodeFilter::add_important(const std::string& key, const std::string& val)
00044 {
00045     important.insert(std::make_pair(key, val));
00046 }
00047 
00048 bool WayNodeFilter::has_important_ways(const osm::Node& n, const std::multimap<osm::Node, osm::Way, osm::LtByID> & ndmap)
00049 {
00050     std::vector<std::pair<std::string, std::string> > vect(important.size());
00051     for (auto it = ndmap.lower_bound(n); it != ndmap.upper_bound(n); ++it)
00052     {
00053         auto it2 = std::set_intersection(it->second.tags.begin(), it->second.tags.end(), important.begin(), important.end(), vect.begin());
00054         if (it2 != vect.begin())
00055             return true;
00056     }
00057     return false;
00058 }
00059 
00060 } /* namespace wayred */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines