Implements a vector tileserver so you can see what's going on inside

OSRM.
This commit is contained in:
Daniel Patterson
2016-02-16 10:51:04 -08:00
committed by Patrick Niklaus
parent 33403efc8e
commit 5dc7b79bb6
18 changed files with 709 additions and 14 deletions
+2
View File
@@ -9,6 +9,7 @@
#include "engine/plugins/trip.hpp"
#include "engine/plugins/viaroute.hpp"
#include "engine/plugins/match.hpp"
#include "engine/plugins/tile.hpp"
#include "engine/datafacade/datafacade_base.hpp"
#include "engine/datafacade/internal_datafacade.hpp"
@@ -63,6 +64,7 @@ Engine::Engine(EngineConfig &config)
config.max_locations_viaroute));
RegisterPlugin(
new plugins::RoundTripPlugin<DataFacade>(query_data_facade, config.max_locations_trip));
RegisterPlugin(new plugins::TilePlugin<DataFacade>(query_data_facade));
}
void Engine::RegisterPlugin(plugins::BasePlugin *raw_plugin_ptr)
+5
View File
@@ -146,5 +146,10 @@ void RouteParameters::SetCoordinatesFromGeometry(const std::string &geometry_str
{
coordinates = polylineDecode(geometry_string);
}
void RouteParameters::SetX(const int &x_) { x = x_; }
void RouteParameters::SetZ(const int &z_) { z = z_; }
void RouteParameters::SetY(const int &y_) { y = y_; }
}
}
+32 -4
View File
@@ -13,6 +13,10 @@
#include "util/json_container.hpp"
#include "osrm/osrm.hpp"
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <ctime>
#include <algorithm>
@@ -113,10 +117,32 @@ void RequestHandler::handle_request(const http::request &current_request,
current_reply.headers.emplace_back("Access-Control-Allow-Headers",
"X-Requested-With, Content-Type");
// set headers
current_reply.headers.emplace_back("Content-Length",
std::to_string(current_reply.content.size()));
if (route_parameters.jsonp_parameter.empty())
if (route_parameters.service == "tile") {
/*
std::istringstream is(json_result.values["pbf"].get<osrm::util::json::String>().value);
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
//in.push(boost::iostreams::gzip_compressor());
in.push(boost::iostreams::zlib_compressor());
in.push(is);
std::ostringstream os;
boost::iostreams::copy(in,os);
auto s = os.str();
std::copy(s.cbegin(),s.cend(), std::back_inserter(current_reply.content));
*/
std::copy(json_result.values["pbf"].get<osrm::util::json::String>().value.cbegin(),
json_result.values["pbf"].get<osrm::util::json::String>().value.cend(),
std::back_inserter(current_reply.content));
//current_reply.content.append(json_result.values["pbf"].get<osrm::util::json::String>().value
current_reply.headers.emplace_back("Content-Type",
"application/x-protobuf");
}
else if (route_parameters.jsonp_parameter.empty())
{ // json file
util::json::render(current_reply.content, json_result);
current_reply.headers.emplace_back("Content-Type", "application/json; charset=UTF-8");
@@ -130,6 +156,8 @@ void RequestHandler::handle_request(const http::request &current_request,
current_reply.headers.emplace_back("Content-Disposition",
"inline; filename=\"response.js\"");
}
current_reply.headers.emplace_back("Content-Length",
std::to_string(current_reply.content.size()));
if (!route_parameters.jsonp_parameter.empty())
{ // append brace to jsonp response
current_reply.content.push_back(')');
+94
View File
@@ -0,0 +1,94 @@
#include "util/typedefs.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/dynamic_graph.hpp"
#include "util/static_graph.hpp"
#include "util/fingerprint.hpp"
#include "util/graph_loader.hpp"
#include "util/make_unique.hpp"
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/binary_heap.hpp"
#include "engine/datafacade/internal_datafacade.hpp"
#include "util/routed_options.hpp"
#include <boost/filesystem.hpp>
#include <boost/timer/timer.hpp>
#include "osrm/coordinate.hpp"
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <unordered_set>
namespace osrm
{
namespace tools
{
struct BoundingBox {
FixedPointCoordinate southwest;
FixedPointCoordinate northeast;
};
BoundingBox TileToBBOX(int z, int x, int y)
{
// A small box in SF near the marina covering the intersection
// of Powell and Embarcadero
return { { static_cast<int32_t>(37.80781742045232 * COORDINATE_PRECISION) , static_cast<int32_t>(-122.4139380455017 * COORDINATE_PRECISION) },
{ static_cast<int32_t>(37.809410993963944 * COORDINATE_PRECISION), static_cast<int32_t>(-122.41186738014221 * COORDINATE_PRECISION) } };
}
}
}
int main(int argc, char *argv[])
{
std::vector<osrm::extractor::QueryNode> coordinate_list;
osrm::util::LogPolicy::GetInstance().Unmute();
// enable logging
if (argc < 5)
{
osrm::util::SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0] << " <filename.osrm> <z> <x> <y>";
return EXIT_FAILURE;
}
// Set up the datafacade for querying
std::unordered_map<std::string, boost::filesystem::path> server_paths;
server_paths["base"] = std::string(argv[1]);
osrm::util::populate_base_path(server_paths);
osrm::engine::datafacade::InternalDataFacade<osrm::contractor::QueryEdge::EdgeData> datafacade(server_paths);
// Step 1 - convert z,x,y into tile bounds
//
int z = std::stoi(argv[2]);
int x = std::stoi(argv[3]);
int y = std::stoi(argv[4]);
auto bbox = util::coordinate_calculation::mercator::TileToBBOX(z,x,y); // @karenzshea - implement this function!!
// Step 2 - Get all the features from those bounds
//
//
auto edges = datafacade.GetEdgesInBox(bbox.southwest, bbox.northeast);
// Step 3 - Encode those features as Mapbox Vector Tiles
//
//
for (const auto & edge : edges)
{
const auto a = datafacade.GetCoordinateOfNode(edge.u);
const auto b = datafacade.GetCoordinateOfNode(edge.v);
std::cout << "Feature: " << a << " to " << b << std::endl;
}
// Step 4 - Output the result
//
return EXIT_SUCCESS;
}
+1
View File
@@ -1,4 +1,5 @@
#include "util/coordinate_calculation.hpp"
#include "util/rectangle.hpp"
#include "util/string_util.hpp"
#include "util/trigonometry_table.hpp"