From 4bc33f14a148feb4056db1a2839303b07c67a6b3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 23 Mar 2018 12:26:04 +0100 Subject: Add `TomTom::Matrix` A new component to the `TomTom` module that asks TomTom's Matrix API endpoint (https://developer.tomtom.com/online-routing/online-routing-documentation/matrix-routing) to compute `WayCost`s. The matrix API will give us all costs between each pair of coordinates. This will enable us to provide costs for any combination of points in a journey pattern. Given a list of `WayCost`s, it will send all points from those costs to the matrix API and return a list of all non-zero `WayCost`s between all pairs of coordinates. `points_from_way_costs()` extracts unique coordinates from the `WayCost`s. `points_as_params()` builds a list of points in the format expected by the matrix API. The response from the matrix API is formatted as a two-dimensional array consisting of rows and columns that pair each "origin" point with each "destination" point. We loop through this matrix and construct new `WayCost` objects for each pair of coordinates. At the moment, I haven't figured out how I want to save `WayCost` IDs when creating the new pairs. Leaving that for later. Refs #6222 --- lib/tom_tom.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/tom_tom.rb') diff --git a/lib/tom_tom.rb b/lib/tom_tom.rb index a1a2bda43..fcebcc7ac 100644 --- a/lib/tom_tom.rb +++ b/lib/tom_tom.rb @@ -19,4 +19,8 @@ module TomTom def self.batch(way_costs) TomTom::Batch.new(@connection).batch(way_costs) end + + def self.matrix(way_costs) + TomTom::Matrix.new(@connection).matrix(way_costs) + end end -- cgit v1.2.3