From d94cea369cb6b81fc038348efea21c8e9fe88e1d Mon Sep 17 00:00:00 2001 From: jcoupey Date: Wed, 13 Nov 2024 16:34:03 +0100 Subject: [PATCH 1/2] Format all coordinates to precision 6 for routing. --- src/routing/ors_wrapper.cpp | 2 +- src/routing/osrm_routed_wrapper.cpp | 2 +- src/routing/valhalla_wrapper.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/routing/ors_wrapper.cpp b/src/routing/ors_wrapper.cpp index f0ef7b400..9e5bcb94c 100644 --- a/src/routing/ors_wrapper.cpp +++ b/src/routing/ors_wrapper.cpp @@ -33,7 +33,7 @@ std::string OrsWrapper::build_query(const std::vector& locations, } body += "\":["; for (auto const& location : locations) { - body += std::format("[{},{}],", location.lon(), location.lat()); + body += std::format("[{:.6f},{:.6f}],", location.lon(), location.lat()); } body.pop_back(); // Remove trailing ','. body += "]"; diff --git a/src/routing/osrm_routed_wrapper.cpp b/src/routing/osrm_routed_wrapper.cpp index 385515287..96a146964 100644 --- a/src/routing/osrm_routed_wrapper.cpp +++ b/src/routing/osrm_routed_wrapper.cpp @@ -38,7 +38,7 @@ OsrmRoutedWrapper::build_query(const std::vector& locations, // Adding locations and radiuses values. for (auto const& location : locations) { - query += std::format("{},{};", location.lon(), location.lat()); + query += std::format("{:.6f},{:.6f};", location.lon(), location.lat()); radiuses += DEFAULT_OSRM_SNAPPING_RADIUS + ";"; } // Remove trailing ';'. diff --git a/src/routing/valhalla_wrapper.cpp b/src/routing/valhalla_wrapper.cpp index 49a712b3f..08fc286e6 100644 --- a/src/routing/valhalla_wrapper.cpp +++ b/src/routing/valhalla_wrapper.cpp @@ -37,8 +37,9 @@ std::string ValhallaWrapper::get_matrix_query( // List locations. std::string all_locations; for (auto const& location : locations) { - all_locations += - std::format(R"({{"lon":{},"lat":{}}},)", location.lon(), location.lat()); + all_locations += std::format(R"({{"lon":{:.6f},"lat":{:.6f}}},)", + location.lon(), + location.lat()); } all_locations.pop_back(); // Remove trailing ','. @@ -61,7 +62,7 @@ ValhallaWrapper::get_route_query(const std::vector& locations) const { "GET /" + _server.path + _route_service + "?json={\"locations\":["; for (auto const& location : locations) { - query += std::format(R"({{"lon":{},"lat":{},"type":"break"}},)", + query += std::format(R"({{"lon":{:.6f},"lat":{:.6f},"type":"break"}},)", location.lon(), location.lat()); } From 69ca2c336a26e68ce196e15dd3ba2972a67c8276 Mon Sep 17 00:00:00 2001 From: jcoupey Date: Wed, 13 Nov 2024 16:35:38 +0100 Subject: [PATCH 2/2] Format all coordinates to precision 6 in error messages. --- src/routing/osrm_routed_wrapper.cpp | 5 +++-- src/routing/wrapper.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/routing/osrm_routed_wrapper.cpp b/src/routing/osrm_routed_wrapper.cpp index 96a146964..fe502f5c9 100644 --- a/src/routing/osrm_routed_wrapper.cpp +++ b/src/routing/osrm_routed_wrapper.cpp @@ -74,8 +74,9 @@ void OsrmRoutedWrapper::check_response(const rapidjson::Document& json_result, const auto error_loc = std::stoul(message.substr(snapping_error_base.size(), message.size() - snapping_error_base.size())); - const auto coordinates = - std::format("[{},{}]", locs[error_loc].lon(), locs[error_loc].lat()); + const auto coordinates = std::format("[{:.6f},{:.6f}]", + locs[error_loc].lon(), + locs[error_loc].lat()); throw RoutingException("Could not find route near location " + coordinates); } diff --git a/src/routing/wrapper.h b/src/routing/wrapper.h index 014621e57..fbe2db616 100644 --- a/src/routing/wrapper.h +++ b/src/routing/wrapper.h @@ -147,7 +147,7 @@ class Wrapper { if (max_unfound_routes_for_a_loc > 0) { std::string error_msg = "Unfound route(s) "; error_msg += error_direction; - error_msg += std::format("location [{},{}]", + error_msg += std::format("location [{:.6f},{:.6f}]", locs[error_loc].lon(), locs[error_loc].lat());