libosrm 1.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cfcb4338e74ba04017eadd08b4ea6f87b1710766
4
+ data.tar.gz: 07a0cfd4dd83545f2e1ab951fd1b7f45fb139990
5
+ SHA512:
6
+ metadata.gz: 4d9889352472136de6cccbc235c3b7337aa5dda83fa4df874e437db0a5d19b8777f6386746b6d0e0fa1201556ee3304c1e1c8777d94ace9d803980ff5aba1272
7
+ data.tar.gz: 6fb73dda9d9b1aabbfa08c6a67a806d7b05204a3c0ed8d4c27543f403f3015de2a4422ad395bfcd4a68f78d28554ac7aceb81afbf48a240873771e2ea2b9d05f
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require_relative "../lib/libosrm/version"
4
+
5
+ def print_usage
6
+ puts "Usage: #{$0} path_to_map.pbf"
7
+ exit 1
8
+ end
9
+
10
+ unless ARGV[0]
11
+ print_usage
12
+ end
13
+
14
+ pbf = ARGV[0]
15
+
16
+ if(pbf == "-h" || pbf == "--help")
17
+ puts "libosrm-prepare is an utility to prepare Openstreetmap map data for ruby-libosrm to use."
18
+ puts
19
+ print_usage
20
+ end
21
+
22
+ unless File.file? pbf
23
+ puts "Given file does not exist."
24
+ puts
25
+ print_usage
26
+ end
27
+
28
+ result = system "#{__dir__}/../libexec/osrm-extract #{pbf} -p #{__dir__}/../osrm/profiles/car.lua"
29
+
30
+ unless result
31
+ puts
32
+ puts "Extracting map data failed."
33
+ exit 1
34
+ end
35
+
36
+ result = system "#{__dir__}/../libexec/osrm-contract #{pbf}"
37
+
38
+ unless result
39
+ puts
40
+ puts "Creating osrm compliant data failed."
41
+ exit 1
42
+ end
@@ -0,0 +1,4 @@
1
+
2
+ libosrm:
3
+ version: "5.12.0"
4
+ download_uri: "https://github.com/Project-OSRM/osrm-backend/archive/v5.12.0.tar.gz"
@@ -0,0 +1,76 @@
1
+ require "mkmf-rice"
2
+
3
+ require "fileutils"
4
+ require "yaml"
5
+
6
+ def do_help
7
+ print <<HELP
8
+ usage: ruby #{$0} [options]
9
+
10
+ --use-system-libraries
11
+ Use system libraries instead of building and using the bundled
12
+ libraries.
13
+ HELP
14
+ exit! 0
15
+ end
16
+
17
+ case
18
+ when arg_config("--help")
19
+ do_help
20
+ end
21
+
22
+ def using_system_libraries?
23
+ arg_config("--use-system-libraries", !!ENV["LIBOSRM_USE_SYSTEM_LIBRARIES"])
24
+ end
25
+
26
+ def symlink_osrm_data recipe
27
+ FileUtils.ln_s "../#{recipe.work_path}/osrm-extract", "libexec/osrm-extract" unless File.exist? "libexec/osrm-extract"
28
+ FileUtils.ln_s "../#{recipe.work_path}/osrm-contract", "libexec/osrm-contract" unless File.exist? "libexec/osrm-contract"
29
+ FileUtils.ln_s "../../#{recipe.work_path}/../profiles/car.lua", "osrm/profiles/car.lua" unless File.exist? "osrm/profiles/car.lua"
30
+ end
31
+
32
+ case
33
+ when using_system_libraries?
34
+ message "Building ruby-libosrm using system libraries.\n"
35
+
36
+ # Using system libraries means we rely on the system libxml2 with
37
+ # regard to the iconv support.
38
+
39
+ dir_config("libosrm").any? or package_config("libosrm")
40
+
41
+ append_cflags("-I/usr/include/osrm")
42
+ have_library "osrm"
43
+ else
44
+ message "Building ruby-libosrm using packaged libraries.\n"
45
+
46
+ #puts Dir.pwd.inspect
47
+
48
+ Dir.chdir "#{__dir__}/../.." do
49
+
50
+ # The gem version constraint in the Rakefile is not respected at install time.
51
+ # Keep this version in sync with the one in the Rakefile !
52
+ require "rubygems"
53
+ gem "mini_portile2", "~> 2.3.0"
54
+ require "mini_portile2"
55
+
56
+ # Current version doesn’t support out of tree builds
57
+ require_relative "mini_portile_fixed_cmake"
58
+
59
+ deps = YAML.load_file "ext/libosrm/dependencies.yaml"
60
+
61
+ recipe = MiniPortileFixedCMake.new("libosrm", deps["libosrm"]["version"])
62
+ recipe.files = [ deps["libosrm"]["download_uri"] ]
63
+ recipe.cook
64
+ recipe.activate
65
+
66
+ symlink_osrm_data recipe
67
+
68
+ append_cflags("-I#{recipe.path}/include -I#{recipe.path}/include/osrm")
69
+ find_library "osrm", nil, "#{recipe.path}/lib"
70
+ end
71
+ end
72
+
73
+ append_cflags("-DHAVE_CXX11")
74
+
75
+ #create_makefile "libosrm/libosrm"
76
+ create_makefile "libosrm/ruby_libosrm"
@@ -0,0 +1,17 @@
1
+ #ifndef LIBOSRM_GLOBALS_H_
2
+ #define LIBOSRM_GLOBALS_H_
3
+
4
+ #include "rice/Data_Type.hpp"
5
+ #include "rice/Constructor.hpp"
6
+ #include "rice/Enum.hpp"
7
+ #include "rice/Struct.hpp"
8
+
9
+ using namespace Rice;
10
+
11
+ static Module rb_mLibOSRM = define_module("LibOSRM");
12
+
13
+ #define ATTR_ACCESSOR_DECL(klass, variable) \
14
+ .define_method(#variable, &klass##_##variable##_get) \
15
+ .define_method(#variable "=", &klass##_##variable##_set)
16
+
17
+ #endif
@@ -0,0 +1,23 @@
1
+
2
+ #include "globals.hpp"
3
+
4
+ using namespace Rice;
5
+
6
+ #include "ruby_engine_config.hpp"
7
+ #include "ruby_osrm_object.hpp"
8
+
9
+ extern "C"
10
+ void Init_ruby_libosrm() {
11
+ try {
12
+ //RUBY_TRY
13
+ //{
14
+ init_engine_config();
15
+ init_osrm_object();
16
+ //}
17
+ //RUBY_CATCH
18
+ } catch(...) {
19
+ std::clog << "Exception found:" << std::endl;
20
+ std::exception_ptr p = std::current_exception();
21
+ std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
22
+ }
23
+ }
@@ -0,0 +1,51 @@
1
+ require "mini_portile2/mini_portile"
2
+
3
+ class MiniPortileFixedCMake < MiniPortile
4
+ def configure_prefix
5
+ "-DCMAKE_INSTALL_PREFIX=#{File.expand_path(port_path)}"
6
+ end
7
+
8
+ def configure_defaults
9
+ if MiniPortile.windows?
10
+ [ '-G "NMake Makefiles"' ]
11
+ else
12
+ []
13
+ end
14
+ end
15
+
16
+ def configure
17
+ return if configured?
18
+
19
+ cache_file = File.join(tmp_path, "configure.options_cache")
20
+ File.open(cache_file, "w") { |f| f.write computed_options.to_s }
21
+
22
+ #execute("configure", %w(cmake) + computed_options + [ "-Bbuild" ] + [ "-H." ])
23
+ execute("configure", %w(cmake) + computed_options + [ ".." ])
24
+ end
25
+
26
+ def configured?
27
+ configure = File.join(work_path, "configure")
28
+ makefile = File.join(work_path, "CMakefile")
29
+ cache_file = File.join(tmp_path, "configure.options_cache")
30
+
31
+ stored_options = File.exist?(cache_file) ? File.read(cache_file) : ""
32
+ current_options = computed_options.to_s
33
+
34
+ (current_options == stored_options) && newer?(makefile, configure)
35
+ end
36
+
37
+ def make_cmd
38
+ return "nmake" if MiniPortile.windows?
39
+ super
40
+ end
41
+
42
+ #def tmp_path
43
+ # "nya"
44
+ #end
45
+
46
+ def work_path
47
+ orig = super
48
+ Dir.mkdir "#{orig}/build" unless Dir.exist? "#{orig}/build"
49
+ "#{orig}/build"
50
+ end
51
+ end
@@ -0,0 +1,188 @@
1
+
2
+ #include "osrm_action.hpp"
3
+
4
+ Array OSRMAction::parse_waypoints(osrm::json::Array waypoints) {
5
+ Array waypoints_result;
6
+ for(auto const& waypointValue : waypoints.values) {
7
+ auto waypoint = waypointValue.get<osrm::json::Object>();
8
+ Hash waypoint_result;
9
+ for(std::pair<std::string, osrm::util::json::Value> e : waypoint.values) {
10
+ if(e.first == "name") {
11
+ waypoint_result[String("name")] = e.second.get<osrm::json::String>().value;
12
+ } else if(e.first == "location") {
13
+ Hash location;
14
+ auto const& values = e.second.get<osrm::json::Array>().values;
15
+ location[Symbol("latitude")] = values[1].get<osrm::json::Number>().value;
16
+ location[Symbol("longitude")] = values[0].get<osrm::json::Number>().value;
17
+ waypoint_result[String("location")] = location;
18
+ } else if(e.first == "hint") {
19
+ waypoint_result[String("hint")] = e.second.get<osrm::json::String>().value;
20
+ } else if(e.first == "distance") {
21
+ waypoint_result[String("distance")] = e.second.get<osrm::json::Number>().value;
22
+ } else if(e.first == "waypoint_index") { // Present in trip action
23
+ waypoint_result[String("waypoint_index")] = e.second.get<osrm::json::Number>().value;
24
+ } else if(e.first == "trips_index") { // Present in trip action
25
+ waypoint_result[String("trips_index")] = e.second.get<osrm::json::Number>().value;
26
+ } else {
27
+ throw Exception(rb_eRuntimeError, "Invalid JSON value when building waypoints from libosrm.so: %s", e.first.c_str());
28
+ }
29
+ }
30
+
31
+ waypoints_result.push(waypoint_result);
32
+ }
33
+
34
+ return waypoints_result;
35
+ }
36
+
37
+ Hash OSRMAction::parse_route(osrm::json::Object route) {
38
+ Hash route_result;
39
+ for(std::pair<std::string, osrm::util::json::Value> e : route.values) {
40
+ if(e.first == "distance") {
41
+ route_result[String("distance")] = e.second.get<osrm::json::Number>().value;
42
+ } else if(e.first == "duration") {
43
+ route_result[String("duration")] = e.second.get<osrm::json::Number>().value;
44
+ } else if(e.first == "weight") {
45
+ route_result[String("weight")] = e.second.get<osrm::json::Number>().value;
46
+ } else if(e.first == "weight_name") {
47
+ route_result[String("weight_name")] = e.second.get<osrm::json::String>().value;
48
+ } else if(e.first == "geometry") {
49
+ route_result[String("geometry")] = e.second.get<osrm::json::String>().value;
50
+ } else if(e.first == "legs") {
51
+ route_result[String("legs")] = parse_route_legs(e.second);
52
+ } else {
53
+ throw Exception(rb_eRuntimeError, "Invalid JSON value when building a route from libosrm.so: %s", e.first.c_str());
54
+ }
55
+ }
56
+
57
+ return route_result;
58
+ }
59
+
60
+ Hash OSRMAction::parse_route_leg_annotations(osrm::util::json::Value value) {
61
+ auto annotations = value.get<osrm::json::Object>();
62
+ Hash result;
63
+ for(std::pair<std::string, osrm::util::json::Value> e : annotations.values) {
64
+ if(e.first == "distance") {
65
+ Array values;
66
+ for(auto const &value : e.second.get<osrm::json::Array>().values) {
67
+ values.push(to_ruby(value));
68
+ }
69
+ result[String("distance")] = values;
70
+ } else if(e.first == "duration") {
71
+ Array values;
72
+ for(auto const &value : e.second.get<osrm::json::Array>().values) {
73
+ values.push(to_ruby(value));
74
+ }
75
+ result[String("duration")] = values;
76
+ } else if(e.first == "datasources") {
77
+ Array values;
78
+ for(auto const &value : e.second.get<osrm::json::Array>().values) {
79
+ values.push(to_ruby(value));
80
+ }
81
+ result[String("datasources")] = values;
82
+ } else if(e.first == "nodes") {
83
+ Array values;
84
+ for(auto const &value : e.second.get<osrm::json::Array>().values) {
85
+ values.push(to_ruby(value));
86
+ }
87
+ result[String("nodes")] = values;
88
+ } else if(e.first == "weight") {
89
+ Array values;
90
+ for(auto const &value : e.second.get<osrm::json::Array>().values) {
91
+ values.push(to_ruby(value));
92
+ }
93
+ result[String("weight")] = values;
94
+ } else if(e.first == "speed") {
95
+ Array values;
96
+ for(auto const &value : e.second.get<osrm::json::Array>().values) {
97
+ values.push(to_ruby(value));
98
+ }
99
+ result[String("speed")] = values;
100
+ } else {
101
+ throw Exception(rb_eRuntimeError, "Invalid JSON value when building a route leg annotations from libosrm.so: %s", e.first.c_str());
102
+ }
103
+ }
104
+
105
+ return result;
106
+ }
107
+
108
+ Array OSRMAction::parse_route_leg_steps(osrm::util::json::Value value) {
109
+ Array steps_array;
110
+
111
+ auto &stepsValues = value.get<osrm::json::Array>();
112
+ for(auto const& stepValue : stepsValues.values) {
113
+ auto step = stepValue.get<osrm::json::Object>();
114
+ Hash step_result;
115
+ for(std::pair<std::string, osrm::util::json::Value> e : step.values) {
116
+ if(e.first == "distance") {
117
+ step_result[String("distance")] = e.second.get<osrm::json::Number>().value;
118
+ } else if(e.first == "duration") {
119
+ step_result[String("duration")] = e.second.get<osrm::json::Number>().value;
120
+ } else if(e.first == "weight") {
121
+ step_result[String("weight")] = e.second.get<osrm::json::Number>().value;
122
+ } else if(e.first == "geometry") {
123
+ step_result[String("geometry")] = e.second.get<osrm::json::String>().value;
124
+ } else if(e.first == "name") {
125
+ step_result[String("name")] = e.second.get<osrm::json::String>().value;
126
+ } else if(e.first == "ref") {
127
+ step_result[String("ref")] = e.second.get<osrm::json::String>().value;
128
+ } else if(e.first == "pronunciation") {
129
+ step_result[String("pronunciation")] = e.second.get<osrm::json::String>().value;
130
+ } else if(e.first == "destinations") {
131
+ step_result[String("destinations")] = e.second.get<osrm::json::String>().value;
132
+ } else if(e.first == "exits") {
133
+ step_result[String("exits")] = e.second.get<osrm::json::String>().value;
134
+ } else if(e.first == "mode") {
135
+ step_result[String("mode")] = e.second.get<osrm::json::String>().value;
136
+ } else if(e.first == "maneuver") {
137
+ auto values = e.second.get<osrm::json::Object>().values;
138
+ Hash maneuver;
139
+ maneuver[String("modifier")] = values.at("modifier").get<osrm::json::String>().value;
140
+ maneuver[String("type")] = values.at("type").get<osrm::json::String>().value;
141
+ step_result[String("maneuver")] = maneuver;
142
+ } else if(e.first == "intersections") {
143
+ //step_result[String("intersections")] = e.second.get<osrm::json::String>().value; // TODO
144
+ } else if(e.first == "rotary_name") {
145
+ step_result[String("rotary_name")] = e.second.get<osrm::json::String>().value;
146
+ } else if(e.first == "rotary_pronunciation") {
147
+ step_result[String("rotary_pronunciation")] = e.second.get<osrm::json::String>().value;
148
+ } else {
149
+ throw Exception(rb_eRuntimeError, "Invalid JSON value when building a route leg steps from libosrm.so: %s", e.first.c_str());
150
+ }
151
+ }
152
+
153
+ steps_array.push(step_result);
154
+ }
155
+
156
+ return steps_array;
157
+ }
158
+
159
+ Array OSRMAction::parse_route_legs(osrm::util::json::Value value) {
160
+ Array legs_array;
161
+
162
+ auto &legsValues = value.get<osrm::json::Array>();
163
+ for(auto const& legValue : legsValues.values) {
164
+ auto leg = legValue.get<osrm::json::Object>();
165
+ Hash leg_result;
166
+ for(std::pair<std::string, osrm::util::json::Value> e : leg.values) {
167
+ if(e.first == "distance") {
168
+ leg_result[String("distance")] = e.second.get<osrm::json::Number>().value;
169
+ } else if(e.first == "duration") {
170
+ leg_result[String("duration")] = e.second.get<osrm::json::Number>().value;
171
+ } else if(e.first == "weight") {
172
+ leg_result[String("weight")] = e.second.get<osrm::json::Number>().value;
173
+ } else if(e.first == "summary") {
174
+ leg_result[String("summary")] = e.second.get<osrm::json::String>().value;
175
+ } else if(e.first == "steps") {
176
+ leg_result[String("steps")] = parse_route_leg_steps(e.second);
177
+ } else if(e.first == "annotation") {
178
+ leg_result[String("annotation")] = parse_route_leg_annotations(e.second);
179
+ } else {
180
+ throw Exception(rb_eRuntimeError, "Invalid JSON value when building a route legs from libosrm.so: %s", e.first.c_str());
181
+ }
182
+ }
183
+
184
+ legs_array.push(leg_result);
185
+ }
186
+
187
+ return legs_array;
188
+ }
@@ -0,0 +1,24 @@
1
+ #ifndef OSRM_ACTION
2
+ #define OSRM_ACTION
3
+
4
+ #include "globals.hpp"
5
+
6
+ #include <osrm/osrm.hpp>
7
+ #include <osrm/json_container.hpp>
8
+
9
+ /**
10
+ * Abstract class implementing some common methods many OSRM actions requires.
11
+ */
12
+ class OSRMAction {
13
+
14
+ public:
15
+ Array parse_waypoints(osrm::json::Array waypoints);
16
+ Hash parse_route(osrm::json::Object route);
17
+
18
+ private:
19
+ Array parse_route_legs(osrm::util::json::Value value);
20
+ Array parse_route_leg_steps(osrm::util::json::Value value);
21
+ Hash parse_route_leg_annotations(osrm::util::json::Value value);
22
+ };
23
+
24
+ #endif
@@ -0,0 +1,79 @@
1
+
2
+ #include "osrm_match_func.hpp"
3
+
4
+ #include <osrm/match_parameters.hpp>
5
+
6
+ Hash parse_match_result(osrm::json::Object match) {
7
+ Hash result;
8
+ for(std::pair<std::string, osrm::util::json::Value> e : match.values) {
9
+ if(e.first == "code") {
10
+ result[String("code")] = e.second.get<osrm::json::String>().value;
11
+ } else if(e.first == "tracepoints") {
12
+ // TODO
13
+ } else if(e.first == "matchings") {
14
+ // TODO
15
+ } else {
16
+ throw Exception(rb_eRuntimeError, "Invalid JSON value when building a match from libosrm.so: %s", e.first.c_str());
17
+ }
18
+ }
19
+
20
+ return result;
21
+ }
22
+
23
+ Object wrap_match(Object self, Array coordinates, Hash opts) {
24
+ // Convert Ruby object to native type
25
+ osrm::MatchParameters params;
26
+
27
+ Array::iterator it = coordinates.begin();
28
+ Array::iterator end = coordinates.end();
29
+ for(; it != end; ++it) {
30
+ Hash latlon = (Hash)*it;
31
+ double lat = from_ruby<double>(latlon[Symbol("latitude")]);
32
+ double lon = from_ruby<double>(latlon[Symbol("longitude")]);
33
+ params.coordinates.push_back({osrm::util::FloatLongitude{lon}, osrm::util::FloatLatitude{lat}});
34
+ }
35
+
36
+ if(!opts.is_nil()) {
37
+ Object geometry_type = opts[Symbol("geometry_type")];
38
+ if(!geometry_type.is_nil()) {
39
+ Symbol g_type = (Symbol) geometry_type;
40
+ const char *type = g_type.c_str();
41
+ if(strcmp(type, "polyline") == 0) {
42
+ params.geometries = osrm::RouteParameters::GeometriesType::Polyline;
43
+ }
44
+ if(strcmp(type, "polyline6") == 0) {
45
+ params.geometries = osrm::RouteParameters::GeometriesType::Polyline6;
46
+ }
47
+ if(strcmp(type, "geojson") == 0) {
48
+ params.geometries = osrm::RouteParameters::GeometriesType::GeoJSON;
49
+ }
50
+ }
51
+
52
+ Object steps = opts[Symbol("steps")];
53
+ if(steps) {
54
+ params.steps = true;
55
+ }
56
+
57
+ Object annotations = opts[Symbol("annotations")];
58
+ if(annotations) {
59
+ params.annotations = true;
60
+ }
61
+ }
62
+
63
+ // Response is in JSON format
64
+ osrm::json::Object result;
65
+
66
+ Data_Object<osrm::OSRM> osrm(self);
67
+
68
+ // Execute routing request, this does the heavy lifting
69
+ const auto status = osrm->Match(params, result);
70
+
71
+ if (status != osrm::Status::Ok) {
72
+ const auto code = result.values["code"].get<osrm::json::String>().value;
73
+ const auto message = result.values["message"].get<osrm::json::String>().value;
74
+
75
+ throw Exception(rb_eRuntimeError, "Failed to route with given input. error code: %s, message: %s", code.c_str(), message.c_str());
76
+ }
77
+
78
+ return parse_match_result(result);
79
+ }