Skip to content
Snippets Groups Projects
Commit 0aa1cee1 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Improved the way to propagate the restrictions when splitting a way.

parent 120c8c76
No related branches found
No related tags found
1 merge request!2Solved a bug when creating a new geometry object: the sale factor is...
......@@ -52,7 +52,7 @@ class COSMWay
void merge(COSMWay *way);
COSMWay(const osmium::Way &way,COSMMap *parent);
bool is_not_connected(void);
bool load_turn_lane_tag(const osmium::Way &way,const std::string &tag,std::vector<lane_restructions_t> &restrictions);
bool load_turn_lane_tag(const osmium::Way &way,const std::string &tag,std::vector<lane_restructions_t> &restrictions,unsigned int max_lanes);
void load_lane_restrictions(const osmium::Way &way);
public:
COSMWay(const COSMWay &object);
......@@ -75,6 +75,7 @@ class COSMWay
unsigned int get_num_backward_lanes(void) const;
bool is_one_way(void) const;
double get_lane_width(void) const;
const COSMRoadSegment &get_road_segment(void) const;
const COSMMap &get_parent(void) const;
friend std::ostream& operator<<(std::ostream& out, COSMWay &way);
~COSMWay();
......
......@@ -21,11 +21,19 @@ COSMWay::COSMWay(const osmium::Way &way,COSMMap *parent)
this->num_forward_lanes=1;
else
this->num_forward_lanes=std::stoi(std::string(value));
value=way.get_value_by_key("oneway");
if(value!=NULL)
if(this->num_forward_lanes>1)
{
if(std::string(value).compare("no")==0)
this->num_backward_lanes=1;
value=way.get_value_by_key("oneway");
if(value!=NULL)
{
if(std::string(value).compare("no")==0)
{
this->num_forward_lanes--;
this->num_backward_lanes=1;
}
else
this->num_backward_lanes=0;
}
else
this->num_backward_lanes=0;
}
......@@ -79,7 +87,7 @@ COSMWay::COSMWay(const COSMWay &object)
this->restrictions=object.restrictions;
}
bool COSMWay::load_turn_lane_tag(const osmium::Way &way,const std::string &tag,std::vector<lane_restructions_t> &restrictions)
bool COSMWay::load_turn_lane_tag(const osmium::Way &way,const std::string &tag,std::vector<lane_restructions_t> &restrictions,unsigned int max_lanes)
{
const char *value;
std::size_t prev_pos=0,pos;
......@@ -97,8 +105,11 @@ bool COSMWay::load_turn_lane_tag(const osmium::Way &way,const std::string &tag,s
prev_pos=pos+1;
}
way_restrictions.push_back(restriction_text.substr(prev_pos));
restrictions.resize(way_restrictions.size(),(lane_restructions_t)0);
for(unsigned int i=0;i<way_restrictions.size();i++)
if(max_lanes<way_restrictions.size())
restrictions.resize(max_lanes,(lane_restructions_t)0);
else
restrictions.resize(way_restrictions.size(),(lane_restructions_t)0);
for(unsigned int i=0;i<way_restrictions.size() && i<max_lanes;i++)
{
lane_restrictions.clear();
prev_pos=0;
......@@ -135,38 +146,14 @@ void COSMWay::load_lane_restrictions(const osmium::Way &way)
this->forward_lanes.resize(this->num_forward_lanes,(lane_restructions_t)0);
this->backward_lanes.resize(this->num_backward_lanes,(lane_restructions_t)0);
if(this->load_turn_lane_tag(way,"turn:lanes",restrictions))
{
if(restrictions.size()<this->num_forward_lanes)
throw CException(_HERE_,"Invalid number of lane restrictions for way");
else
{
this->num_forward_lanes=restrictions.size();
this->forward_lanes=restrictions;
}
}
if(this->load_turn_lane_tag(way,"turn:lanes",restrictions,this->num_forward_lanes))
this->forward_lanes=restrictions;
else
{
if(this->load_turn_lane_tag(way,"turn:lanes:forward",restrictions))
{
if(restrictions.size()<this->num_forward_lanes)
throw CException(_HERE_,"Invalid number of lane restrictions for way");
else
{
this->num_forward_lanes=restrictions.size();
this->forward_lanes=restrictions;
}
}
if(this->load_turn_lane_tag(way,"turn:lanes:backward",restrictions))
{
if(restrictions.size()<this->num_backward_lanes)
throw CException(_HERE_,"Invalid number of lane restrictions for way");
else
{
this->num_backward_lanes=restrictions.size();
this->backward_lanes=restrictions;
}
}
if(this->load_turn_lane_tag(way,"turn:lanes:forward",restrictions,this->num_forward_lanes))
this->forward_lanes=restrictions;
if(this->load_turn_lane_tag(way,"turn:lanes:backward",restrictions,this->num_backward_lanes))
this->backward_lanes=restrictions;
}
}
......@@ -302,43 +289,54 @@ void COSMWay::update_restriction(COSMWay *old_way,COSMWay *new_way)
{
std::vector<COSMRestriction *>::const_iterator it;
COSMRestriction *new_restriction=NULL;
bool no_u_turn=true;
for(it=this->restrictions.begin();it!=this->restrictions.end();)
{
if((*it)->get_action()==RESTRICTION_NO && (*it)->get_type()==RESTRICTION_U_TURN)
if(!this->has_node((*it)->get_via_node().get_id()))
it=this->restrictions.erase(it);
else
it++;
}
for(it=this->restrictions.begin();it!=this->restrictions.end();it++)
{
if(this->id==old_way->get_id())
{
if((*it)->get_from_way().get_id()==old_way->get_id() && this->id==new_way->get_id())
if(!((*it)->get_action()==RESTRICTION_NO && (*it)->get_type()==RESTRICTION_U_TURN))
{
new_restriction=new COSMRestriction(**it);
new_restriction->id=-1;
new_restriction->update_way(old_way,new_way);
if((*it)->get_to_way().get_id()==old_way->get_id())
(*it)->update_to_way(old_way,new_way);
}
it++;
else
no_u_turn=false;
}
else
else if(this->id==new_way->get_id())
{
if(this->id==old_way->get_id())
if((*it)->get_action()==RESTRICTION_NO && (*it)->get_type()==RESTRICTION_U_TURN)
{
if((*it)->get_to_way().get_id()==old_way->get_id())
it=this->restrictions.erase(it);
else
it++;
(*it)->update_from_way(old_way,new_way);
(*it)->update_to_way(old_way,new_way);
no_u_turn=false;
}
else if(this->id==new_way->get_id())
else
{
if((*it)->get_from_way().get_id()==old_way->get_id())
it=this->restrictions.erase(it);
else
it++;
(*it)->update_from_way(old_way,new_way);
}
}
}
/*
if(!no_u_turn)
{
new_restriction= new COSMRestriction(this,,this,RESTRICTION_NO,RESTRICTION_U_TURN,this->parent);
}
if(new_restriction!=NULL)
{
this->parent->add_restriction(new_restriction);
new_way->add_restriction(new_restriction);
new_restriction->via->add_restriction(new_restriction);
}
*/
}
void COSMWay::clear_restrictions(void)
......@@ -394,7 +392,10 @@ void COSMWay::merge(COSMWay *way)
for(unsigned int i=0;i<way->restrictions.size();i++)
this->add_restriction(way->restrictions[i]);
for(unsigned int i=0;i<this->restrictions.size();i++)
this->restrictions[i]->update_way(way,this);
{
this->restrictions[i]->update_to_way(way,this);
this->restrictions[i]->update_from_way(way,this);
}
}
bool COSMWay::is_not_connected(void)
......@@ -649,6 +650,11 @@ double COSMWay::get_lane_width(void) const
return this->lane_width;
}
const COSMRoadSegment &COSMWay::get_road_segment(void) const
{
return *this->road_segment;
}
const COSMMap &COSMWay::get_parent(void) const
{
return *this->parent;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment