From 1164f26da17c97beab13911422bcff32e55a75ae Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 23 Oct 2018 17:54:31 +0300 Subject: [PATCH] [routing] Updating table road category to speed. --- generator/camera_node_processor.cpp | 9 +++- generator/camera_node_processor.hpp | 2 +- generator/category_to_speed.cpp | 79 +++++++++++++++++++++++++---- generator/category_to_speed.hpp | 14 +++-- 4 files changed, 86 insertions(+), 18 deletions(-) diff --git a/generator/camera_node_processor.cpp b/generator/camera_node_processor.cpp index 4ea6ca79c4..21d132dfcc 100644 --- a/generator/camera_node_processor.cpp +++ b/generator/camera_node_processor.cpp @@ -114,10 +114,15 @@ void CameraNodeIntermediateDataProcessor::ProcessWay(uint64_t id, WayElement con std::string CameraNodeIntermediateDataProcessor::ValidateMaxSpeedString(std::string const & maxSpeedString) { - double speed = 0.0; + uint16_t speed = 0; measurement_utils::Units units = measurement_utils::Units::Metric; if (RoadCategoryToSpeed(maxSpeedString, speed, units)) - return strings::to_string(static_cast(measurement_utils::ToSpeedKmPH(speed, units))); + { + if (speed == kNoneMaxSpeed) + return string(); // Speed cam with no restriction on speed. + else + return strings::to_string(static_cast(measurement_utils::ToSpeedKmPH(speed, units))); + } // strings::to_int doesn't work here because of bad errno. std::string result; diff --git a/generator/camera_node_processor.hpp b/generator/camera_node_processor.hpp index 6f16326686..e49908e765 100644 --- a/generator/camera_node_processor.hpp +++ b/generator/camera_node_processor.hpp @@ -64,7 +64,7 @@ public: void SaveIndex() { m_speedCameraNodeToWays.WriteAll(); } private: - /// \brief Gets text with speed, returns formated speed string in kmh. + /// \brief Gets text with speed, returns formatted speed string in kmh. /// \param maxSpeedString - text with speed. Possible format: /// "130" - means 130 kmh. /// "130 mph" - means 130 mph. diff --git a/generator/category_to_speed.cpp b/generator/category_to_speed.cpp index 8682aee207..cafbbd412f 100644 --- a/generator/category_to_speed.cpp +++ b/generator/category_to_speed.cpp @@ -4,6 +4,7 @@ namespace { +using namespace generator; using namespace measurement_utils; struct Speed @@ -14,7 +15,11 @@ struct Speed Units m_units = Units::Metric; }; -std::unordered_map const kRoadCategoryToSpeedKMpH = { +std::unordered_map const kRoadCategoryToSpeed = { + {"AR:urban", {40, Units::Metric}}, + {"AR:urban:primary", {60, Units::Metric}}, + {"AR:urban:secondary", {60, Units::Metric}}, + {"AR:rural", {110, Units::Metric}}, {"AT:urban", {50, Units::Metric}}, {"AT:rural", {100, Units::Metric}}, {"AT:trunk", {100, Units::Metric}}, @@ -25,34 +30,66 @@ std::unordered_map const kRoadCategoryToSpeedKMpH = { {"BE:zone30", {30, Units::Metric}}, {"BE:rural", {70, Units::Metric}}, {"BE:school", {30, Units::Metric}}, - {"CZ:motorway", {130, Units::Metric}}, - {"CZ:trunk", {110, Units::Metric}}, - {"CZ:rural", {90, Units::Metric}}, - {"CZ:urban_motorway", {80, Units::Metric}}, - {"CZ:urban_trunk", {80, Units::Metric}}, + {"CH:urban", {50, Units::Metric}}, + {"CH:rural", {80, Units::Metric}}, + {"CH:trunk", {100, Units::Metric}}, + {"CH:motorway", {120, Units::Metric}}, + {"CZ:pedestrian_zone", {20, Units::Metric}}, + {"CZ:living_street", {20, Units::Metric}}, {"CZ:urban", {50, Units::Metric}}, - {"DE:rural", {100, Units::Metric}}, + {"CZ:urban_trunk", {80, Units::Metric}}, + {"CZ:urban_motorway", {80, Units::Metric}}, + {"CZ:rural", {90, Units::Metric}}, + {"CZ:trunk", {110, Units::Metric}}, + {"CZ:motorway", {130, Units::Metric}}, + {"DK:urban", {50, Units::Metric}}, + {"DK:rural", {80, Units::Metric}}, + {"DK:motorway", {130, Units::Metric}}, + {"DE:living_street", {7, Units::Metric}}, {"DE:urban", {50, Units::Metric}}, + {"DE:rural", {100, Units::Metric}}, {"DE:bicycle_road", {30, Units::Metric}}, + {"DE:trunk", {kNoneMaxSpeed, Units::Metric}}, + {"DE:motorway", {kNoneMaxSpeed, Units::Metric}}, + {"FI:urban", {50, Units::Metric}}, + {"FI:rural", {80, Units::Metric}}, + {"FI:trunk", {100, Units::Metric}}, + {"FI:motorway", {120, Units::Metric}}, {"FR:motorway", {130, Units::Metric}}, + {"FR:trunk", {110, Units::Metric}}, {"FR:rural", {80, Units::Metric}}, {"FR:urban", {50, Units::Metric}}, + {"GR:urban", {50, Units::Metric}}, + {"GR:rural", {90, Units::Metric}}, + {"GR:trunk", {90, Units::Metric}}, + {"GR:motorway", {130, Units::Metric}}, {"HU:living_street", {20, Units::Metric}}, {"HU:motorway", {130, Units::Metric}}, {"HU:rural", {90, Units::Metric}}, {"HU:trunk", {110, Units::Metric}}, {"HU:urban", {50, Units::Metric}}, - {"IT:rural", {90, Units::Metric}}, {"IT:motorway", {130, Units::Metric}}, + {"IT:trunk", {110, Units::Metric}}, + {"IT:rural", {90, Units::Metric}}, {"IT:urban", {50, Units::Metric}}, + {"JP:national", {60, Units::Metric}}, + {"JP:motorway", {100, Units::Metric}}, {"JP:nsl", {60, Units::Metric}}, {"JP:express", {100, Units::Metric}}, + {"LT:motorway", {110, Units::Metric}}, + {"LT:trunk", {110, Units::Metric}}, {"LT:rural", {90, Units::Metric}}, {"LT:urban", {50, Units::Metric}}, + {"LT:living_street", {20, Units::Metric}}, {"NO:rural", {80, Units::Metric}}, {"NO:urban", {50, Units::Metric}}, {"ON:urban", {50, Units::Metric}}, {"ON:rural", {80, Units::Metric}}, + {"PL:living_street", {20, Units::Metric}}, + {"PL:urban", {50, Units::Metric}}, + {"PL:rural", {90, Units::Metric}}, + {"PL:trunk", {100, Units::Metric}}, + {"PL:motorway", {140, Units::Metric}}, {"PT:motorway", {120, Units::Metric}}, {"PT:rural", {90, Units::Metric}}, {"PT:trunk", {100, Units::Metric}}, @@ -65,6 +102,22 @@ std::unordered_map const kRoadCategoryToSpeedKMpH = { {"RU:urban", {60, Units::Metric}}, {"RU:rural", {90, Units::Metric}}, {"RU:motorway", {110, Units::Metric}}, + {"SK:urban", {50, Units::Metric}}, + {"SK:rural", {90, Units::Metric}}, + {"SK:trunk", {90, Units::Metric}}, + {"SK:motorway", {90, Units::Metric}}, + {"SL:urban", {50, Units::Metric}}, + {"SL:rural", {90, Units::Metric}}, + {"SL:trunk", {110, Units::Metric}}, + {"SL:motorway", {130, Units::Metric}}, + {"ES:urban", {50, Units::Metric}}, + {"ES:rural", {90, Units::Metric}}, + {"ES:trunk", {100, Units::Metric}}, + {"ES:motorway", {120, Units::Metric}}, + {"SE:urban", {50, Units::Metric}}, + {"SE:rural", {70, Units::Metric}}, + {"SE:trunk", {90, Units::Metric}}, + {"SE:motorway", {110, Units::Metric}}, {"GB:motorway", {70, Units::Imperial}}, // 70 mph = 112.65408 kmph {"GB:nsl_dual", {70, Units::Imperial}}, // 70 mph = 112.65408 kmph @@ -74,6 +127,10 @@ std::unordered_map const kRoadCategoryToSpeedKMpH = { {"UK:nsl_dual", {70, Units::Imperial}}, // 70 mph {"UK:nsl_single", {60, Units::Imperial}}, // 60 mph + {"UA:urban", {50, Units::Metric}}, + {"UA:rural", {90, Units::Metric}}, + {"UA:trunk", {110, Units::Metric}}, + {"UA:motorway", {130, Units::Metric}}, {"UZ:living_street", {30, Units::Metric}}, {"UZ:urban", {70, Units::Metric}}, {"UZ:rural", {100, Units::Metric}}, @@ -83,11 +140,11 @@ std::unordered_map const kRoadCategoryToSpeedKMpH = { namespace generator { -bool RoadCategoryToSpeed(std::string const & category, double & speed, +bool RoadCategoryToSpeed(std::string const & category, uint16_t & speed, measurement_utils::Units & units) { - auto const it = kRoadCategoryToSpeedKMpH.find(category); - if (it == kRoadCategoryToSpeedKMpH.cend()) + auto const it = kRoadCategoryToSpeed.find(category); + if (it == kRoadCategoryToSpeed.cend()) return false; speed = it->second.m_speed; diff --git a/generator/category_to_speed.hpp b/generator/category_to_speed.hpp index c76da89980..b227a26afe 100644 --- a/generator/category_to_speed.hpp +++ b/generator/category_to_speed.hpp @@ -2,17 +2,23 @@ #include "platform/measurement_utils.hpp" +#include +#include #include namespace generator { +uint16_t constexpr kNoneMaxSpeed = std::numeric_limits::max(); + /// \brief Obtains |speed| and |units| by road category based on /// the table in https://wiki.openstreetmap.org/wiki/Speed_limits -/// This method should be updated regularly. Last update: 22.10.18. -/// \note For example by passing string "RU:urban", you'll get -/// speed = 60 and units = Units::Metric. +/// This method should be updated regularly. Last update: 23.10.18. /// \returns true if |speed| and |units| is found for |category| and these fields are filled /// and false otherwise. -bool RoadCategoryToSpeed(std::string const & category, double & speed, +/// \note For example by passing string "RU:urban", you'll get +/// speed = 60 and units = Units::Metric. +/// \note If the method returns true the field |speed| may be filled with |kNoneMaxSpeed| value. +/// It means no speed limits for the |category|. It's currently actual for Germany. +bool RoadCategoryToSpeed(std::string const & category, uint16_t & speed, measurement_utils::Units & units); } // generator