std::map<unsigned long long int, std::pair<RelationPtr, std::map<unsigned long long int, WayPtr> > > Network::getWaysByAdminBoundary(int admin_level) { typedef std::map<unsigned long long int, WayPtr> WayMap; typedef std::pair<unsigned long long int, WayPtr> WayType; typedef std::map<unsigned long long int, RelationPtr> RelationMap; typedef std::pair<RelationPtr, WayMap> RelationWayPair; typedef std::map<unsigned long long int, RelationWayPair> GlobalMap; GlobalMap ret; util::Log::GetInstance().info("extracting administrative boundaries"); RelationMap adminBoundaries = getAdministrativeBoundaries(admin_level); util::Log::GetInstance().info("finished extracting administrative boundaries"); WayMap waysList; BOOST_FOREACH(WayType w, ways) { if( w.second->getNodes()->size() > 1 && w.second->hasTag(Element::TAG_HIGHWAY) && Way::highwayTypes.find(w.second->getTag(Element::TAG_HIGHWAY)) != Way::highwayTypes.end() ) { waysList[w.second->getId()] = w.second; } } util::Log::GetInstance().info("extracting ways by administrative boundaries"); RelationMap::iterator boundaryIterator = adminBoundaries.begin(); while(boundaryIterator != adminBoundaries.end()) { RelationPtr boundary = boundaryIterator->second; ret[boundaryIterator->first] = RelationWayPair(boundary, WayMap()); boundaryIterator++; } WayMap::iterator wayIterator = waysList.begin(); while(wayIterator != waysList.end()) { WayPtr way = wayIterator->second; boost::shared_ptr<const geos::geom::Geometry> wayGeom = way->toGeometry(); boundaryIterator = adminBoundaries.begin(); while(boundaryIterator != adminBoundaries.end()) { RelationPtr boundary = boundaryIterator->second; boost::shared_ptr<const geos::geom::prep::PreparedGeometry> boundaryPrepGeom = boundary->toPreparedGeometry(); if(boundaryPrepGeom->covers(wayGeom.get()) || boundaryPrepGeom->intersects(wayGeom.get())) { //the way is inside or intersected by the boundary, keep it ret[boundaryIterator->first].second[wayIterator->first] = way; //mark the nodes of this way for next step reference counting way->referenceWithNodes(); break; } else //no interaction with current boundary boundaryIterator++; } ++wayIterator; } util::Log::GetInstance().info("finished extracting ways by administrative boundaries"); return ret; }
std::map<unsigned long long int,std::pair<RelationPtr,std::map<unsigned long long int, WayPtr> > > Network::getWalkableWaysByAdminBoundary(int admin_level) { std::map<unsigned long long int, std::pair<RelationPtr, std::map<unsigned long long int, WayPtr> > > ret; util::Log::GetInstance().info("extracting administrative boundaries"); std::map<unsigned long long int, RelationPtr> adminBoundaries = getAdministrativeBoundaries(admin_level); util::Log::GetInstance().info("finished extracting administrative boundaries"); std::map<unsigned long long int, WayPtr> walkableWays = getWalkableWays(); util::Log::GetInstance().info("extracting ways by administrative boundaries"); /* std::map<unsigned long long int,RelationPtr>::iterator boundaryIterator = adminBoundaries.begin(); while(boundaryIterator != adminBoundaries.end()) { RelationPtr boundary = boundaryIterator->second; ret[boundaryIterator->first] = std::pair<RelationPtr,std::map<unsigned long long int,WayPtr> >(boundary, std::map<unsigned long long int,WayPtr>()); boost::shared_ptr<const geos::geom::prep::PreparedGeometry> boundaryPrepGeom = boundary->toPreparedGeometry(); std::map<unsigned long long int,WayPtr>::iterator wayIterator = walkableWays.begin(); while(wayIterator != walkableWays.end()) { WayPtr way = wayIterator->second; boost::shared_ptr<const geos::geom::Geometry> wayGeom = way->toGeometry(); if(boundaryPrepGeom->covers(wayGeom.get())) { //the way is inside this boundary, keep it ret[boundaryIterator->first].second[wayIterator->first]=way; //mark the nodes of this way for next step reference counting way->referenceWithNodes(); //remove way from list to avoid further superfluous geometry computations walkableWays.erase(wayIterator++); } else if(boundaryPrepGeom->intersects(wayGeom.get())) { //the way isn't inside, but intersects, flag it as invalid walkableWays.erase(wayIterator++); //TODO: log the way } else { //no interaction with current boundary wayIterator++; } } boundaryIterator++; } */ std::map<unsigned long long int, RelationPtr>::iterator boundaryIterator = adminBoundaries.begin(); while(boundaryIterator != adminBoundaries.end()) { RelationPtr boundary = boundaryIterator->second; ret[boundaryIterator->first] = std::pair<RelationPtr, std::map<unsigned long long int, WayPtr> >(boundary, std::map<unsigned long long int, WayPtr>()); boundaryIterator++; } std::map<unsigned long long int,WayPtr>::iterator wayIterator = walkableWays.begin(); while(wayIterator != walkableWays.end()) { WayPtr way = wayIterator->second; boost::shared_ptr<const geos::geom::Geometry> wayGeom = way->toGeometry(); boundaryIterator = adminBoundaries.begin(); while(boundaryIterator != adminBoundaries.end()) { RelationPtr boundary = boundaryIterator->second; boost::shared_ptr<const geos::geom::prep::PreparedGeometry> boundaryPrepGeom = boundary->toPreparedGeometry(); if(boundaryPrepGeom->covers(wayGeom.get())) { //the way is inside this boundary, keep it ret[boundaryIterator->first].second[wayIterator->first] = way; //mark the nodes of this way for next step reference counting way->referenceWithNodes(); break; } else if(boundaryPrepGeom->intersects(wayGeom.get())) { //the way isn't inside, but intersects, continue break; //TODO: log the way } else { //no interaction with current boundary boundaryIterator++; } } ++wayIterator; } util::Log::GetInstance().info("finished extracting ways by administrative boundaries"); return ret; }