2016-02-17 16:49:44 -05:00
|
|
|
#include "engine/plugins/nearest.hpp"
|
2016-02-22 18:44:35 -05:00
|
|
|
#include "engine/api/nearest_api.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "engine/api/nearest_parameters.hpp"
|
2016-02-17 16:49:44 -05:00
|
|
|
#include "engine/phantom_node.hpp"
|
|
|
|
#include "util/integer_range.hpp"
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
2016-09-15 06:11:45 -04:00
|
|
|
#include <boost/numeric/conversion/cast.hpp>
|
2016-02-17 16:49:44 -05:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
|
|
|
namespace plugins
|
|
|
|
{
|
|
|
|
|
2016-09-12 05:47:22 -04:00
|
|
|
NearestPlugin::NearestPlugin(datafacade::BaseDataFacade &facade, const int max_results_)
|
|
|
|
: BasePlugin{facade}, max_results{max_results_}
|
|
|
|
{
|
|
|
|
}
|
2016-02-17 16:49:44 -05:00
|
|
|
|
|
|
|
Status NearestPlugin::HandleRequest(const api::NearestParameters ¶ms,
|
2016-02-22 18:44:35 -05:00
|
|
|
util::json::Object &json_result)
|
2016-02-17 16:49:44 -05:00
|
|
|
{
|
|
|
|
BOOST_ASSERT(params.IsValid());
|
|
|
|
|
2016-09-15 06:11:45 -04:00
|
|
|
if (max_results > 0 &&
|
|
|
|
(boost::numeric_cast<std::int64_t>(params.number_of_results) > max_results))
|
2016-09-12 05:47:22 -04:00
|
|
|
{
|
|
|
|
return Error("TooBig",
|
|
|
|
"Number of results " + std::to_string(params.number_of_results) +
|
|
|
|
" is higher than current maximum (" + std::to_string(max_results) + ")",
|
|
|
|
json_result);
|
|
|
|
}
|
|
|
|
|
2016-02-17 16:49:44 -05:00
|
|
|
if (!CheckAllCoordinates(params.coordinates))
|
2016-02-22 18:44:35 -05:00
|
|
|
return Error("InvalidOptions", "Coordinates are invalid", json_result);
|
2016-02-17 16:49:44 -05:00
|
|
|
|
2016-02-22 18:44:35 -05:00
|
|
|
if (params.coordinates.size() != 1)
|
|
|
|
{
|
2016-03-18 09:03:55 -04:00
|
|
|
return Error("InvalidOptions", "Only one input coordinate is supported", json_result);
|
2016-02-22 18:44:35 -05:00
|
|
|
}
|
2016-02-17 16:49:44 -05:00
|
|
|
|
2016-02-22 18:44:35 -05:00
|
|
|
auto phantom_nodes = GetPhantomNodes(params, params.number_of_results);
|
2016-02-17 16:49:44 -05:00
|
|
|
|
2016-02-22 18:44:35 -05:00
|
|
|
if (phantom_nodes.front().size() == 0)
|
2016-02-17 16:49:44 -05:00
|
|
|
{
|
2016-02-22 18:44:35 -05:00
|
|
|
return Error("NoSegment", "Could not find a matching segments for coordinate", json_result);
|
2016-02-17 16:49:44 -05:00
|
|
|
}
|
2016-02-22 18:44:35 -05:00
|
|
|
BOOST_ASSERT(phantom_nodes.front().size() > 0);
|
|
|
|
|
|
|
|
api::NearestAPI nearest_api(facade, params);
|
|
|
|
nearest_api.MakeResponse(phantom_nodes, json_result);
|
2016-02-17 16:49:44 -05:00
|
|
|
|
|
|
|
return Status::Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|