diff --git a/include/osm/osm_common.h b/include/osm/osm_common.h index dcbf3643aa5a9de4e3ce1feab4a479c2bc60e59a..50593656c7cdd2a046d0296fa9b1dd1609533419 100644 --- a/include/osm/osm_common.h +++ b/include/osm/osm_common.h @@ -1,7 +1,6 @@ #ifndef _OSM_COMMON_H #define _OSM_COMMON_H -#define DEFAULT_LANE_WIDTH 4.0 #define DEFAULT_MIN_TURN_RADIUS 5.0 #define DEFAULT_MIN_ROAD_LENGTH 0.5 @@ -14,6 +13,7 @@ typedef struct{ std::vector<std::string> keys; double min_turn_radius; double min_road_length; + double default_lane_width; bool use_default_lane_width; bool force_two_ways; }TOSMPathData; diff --git a/include/osm/osm_map.h b/include/osm/osm_map.h index c019d18c6c2b3aff1fa356b6fc6ebda210f4480c..b4251215029efcbb866aa89fa8bef0cc2b5acf57 100644 --- a/include/osm/osm_map.h +++ b/include/osm/osm_map.h @@ -54,6 +54,7 @@ class COSMMap : public osmium::handler::Handler bool add_path_type(TOSMPathData &path_data); double get_min_turn_radius(std::string &path_type); double get_min_road_length(std::string &path_type); + double get_default_lane_width(std::string &path_type); bool use_default_lane_width(std::string &path_type); bool force_two_ways(std::string &path_type); void node(const osmium::Node& node); diff --git a/include/osm/osm_way.h b/include/osm/osm_way.h index 54d928ff1938db20fb70d78c59d4f5910a1b04fe..f3f2745ff4bc53da9d4267a0fc679b3547a7754a 100644 --- a/include/osm/osm_way.h +++ b/include/osm/osm_way.h @@ -65,6 +65,7 @@ class COSMWay std::string get_type(void); double get_min_turn_radius(void); double get_min_road_length(void); + double get_default_lane_width(void); bool use_default_lane_width(void); bool force_two_ways(void); unsigned int get_num_nodes(void); diff --git a/src/examples/osm_import_test.cpp b/src/examples/osm_import_test.cpp index b7ba71a5ae3588e23cdc4ecb001f2dd4fe0e5648..d88250e651355d75c8d39e148eb5e52f7618dea2 100644 --- a/src/examples/osm_import_test.cpp +++ b/src/examples/osm_import_test.cpp @@ -20,6 +20,7 @@ int main(int argc, char *argv[]) osm_paths[0].name="roads"; osm_paths[0].min_turn_radius=DEFAULT_MIN_TURN_RADIUS; osm_paths[0].min_road_length=DEFAULT_MIN_ROAD_LENGTH; + osm_paths[0].default_lane_width=4.0; osm_paths[0].use_default_lane_width=true; osm_paths[0].force_two_ways=false; osm_paths[0].highways.push_back("motorway"); @@ -41,6 +42,7 @@ int main(int argc, char *argv[]) osm_paths[1].min_turn_radius=DEFAULT_MIN_TURN_RADIUS; osm_paths[1].min_road_length=DEFAULT_MIN_ROAD_LENGTH; osm_paths[1].use_default_lane_width=true; + osm_paths[1].default_lane_width=0.1; osm_paths[1].force_two_ways=true; osm_paths[1].highways.push_back("pedestrian"); map.load_osm(osm_file,osm_paths); diff --git a/src/osm/osm_map.cpp b/src/osm/osm_map.cpp index ed0872db34b25372bf8fe47e65d29a830642db1b..be755bd4b3c1dfb4d0386f860b9433abeaaee311 100644 --- a/src/osm/osm_map.cpp +++ b/src/osm/osm_map.cpp @@ -289,6 +289,7 @@ bool COSMMap::add_path_type(TOSMPathData &path_data) new_path_type.data.min_turn_radius=path_data.min_turn_radius; new_path_type.data.min_road_length=path_data.min_road_length; new_path_type.data.use_default_lane_width=path_data.use_default_lane_width; + new_path_type.data.default_lane_width=path_data.default_lane_width; new_path_type.data.force_two_ways=path_data.force_two_ways; for(unsigned int i=0;i<path_data.highways.size();i++) { @@ -348,6 +349,15 @@ double COSMMap::get_min_road_length(std::string &path_type) throw CException(_HERE_,"The given path type does not exist"); } +double COSMMap::get_default_lane_width(std::string &path_type) +{ + for(unsigned int i=0;i<this->path_types.size();i++) + if(this->path_types[i].data.name==path_type) + return this->path_types[i].data.default_lane_width; + + throw CException(_HERE_,"The given path type does not exist"); +} + bool COSMMap::use_default_lane_width(std::string &path_type) { for(unsigned int i=0;i<this->path_types.size();i++) diff --git a/src/osm/osm_way.cpp b/src/osm/osm_way.cpp index 91cceca41d256ad2924db37b330c6fcd7a95ee1d..603e4086c92b951db6c1b4d9aa3f16172561fa62 100644 --- a/src/osm/osm_way.cpp +++ b/src/osm/osm_way.cpp @@ -93,12 +93,12 @@ COSMWay::COSMWay(const osmium::Way &way,COSMMap *parent,std::string &type) } // get the road width if(parent->use_default_lane_width(type)) - this->lane_width=DEFAULT_LANE_WIDTH; + this->lane_width=parent->get_default_lane_width(type); else { value=way.get_value_by_key("width"); if(value==NULL) - this->lane_width=DEFAULT_LANE_WIDTH; + this->lane_width=parent->get_default_lane_width(type); else this->lane_width=std::stof(std::string(value))/(this->num_forward_lanes+this->num_backward_lanes); } @@ -542,6 +542,11 @@ double COSMWay::get_min_road_length(void) return this->parent->get_min_road_length(this->type); } +double COSMWay::get_default_lane_width(void) +{ + return this->parent->get_default_lane_width(this->type); +} + bool COSMWay::use_default_lane_width(void) { return this->parent->use_default_lane_width(this->type); @@ -804,7 +809,7 @@ lane_restrictions_t COSMWay::get_lane_restriction(unsigned int index) double COSMWay::get_lane_width(void) { if(this->lane_width==-1.0) - return DEFAULT_LANE_WIDTH; + return this->get_default_lane_width(); else return this->lane_width; }