osrm-backend/src/engine/plugins/nearest.cpp

50 lines
1.3 KiB
C++
Raw Normal View History

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>
namespace osrm
{
namespace engine
{
namespace plugins
{
NearestPlugin::NearestPlugin(datafacade::BaseDataFacade &facade) : BasePlugin{facade} {}
Status NearestPlugin::HandleRequest(const api::NearestParameters &params,
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());
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)
{
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;
}
}
}
}