Class: LibOSRM::OSRM
- Inherits:
-
Object
- Object
- LibOSRM::OSRM
- Defined in:
- lib/libosrm/osrm.rb
Overview
OSRM routing interface.
Provides methods to calculate various data using Openstreetmap data with OSRM.
For example, to get distance by roads, you could use
osrm = OSRM.new "map.osrm"
distance = osrm.distance_by_roads { latitude: 60.1681473, longitude: 24.9417190 }, { latitude: 60.1694561, longitude: 24.9385663 }
Please see README for general instructions of how to use this gem.
Instance Method Summary collapse
-
#coordinates_to_tile_numbers(latitude, longitude, zoom) ⇒ Object
Converts coordinates to tile numbers as expected by #tile.
-
#distance_by_roads(coordinates) ⇒ Object
Calculates distance by roads from given coordinates.
-
#initialize(osrm_file) ⇒ Object
constructor
Initializes OSRM object for routing actions.
-
#match(coordinates, opts = nil) ⇒ Hash
Tries to match given coordinates to road network in most plausible way.
-
#nearest(latitude, longitude, amount = 1) ⇒ Hash
OSRM nearest action.
-
#route(coordinates, opts = nil) ⇒ Hash
OSRM routing action.
-
#table(coordinates, opts = nil) ⇒ Hash
OSRM table action.
-
#tile(x, y, zoom) ⇒ Hash
Calculates a vector tile image that can be used to examine the routing graph.
-
#tile_with_coordinates(latitude, longitude, zoom) ⇒ Object
Invokes #tile, but first converts given coordinates to tile numbers.
-
#trip(coordinates) ⇒ Hash
Tries to calculate shortest possible route between given coordinates (and then back to original point; i.e. the first coordinate pair in the input), in order to solve the travelling salesman problem.
Constructor Details
#initialize(osrm_file) ⇒ Object
This method is implemented in native code.
Initializes OSRM object for routing actions.
|
# File 'lib/libosrm/osrm.rb', line 33
|
Instance Method Details
#coordinates_to_tile_numbers(latitude, longitude, zoom) ⇒ Object
Converts coordinates to tile numbers as expected by #tile.
154 155 156 157 158 159 160 161 |
# File 'lib/libosrm/osrm.rb', line 154 def coordinates_to_tile_numbers latitude, longitude, zoom lat_rad = latitude / 180 * Math::PI n = 2.0 ** zoom x = ((longitude + 180.0) / 360.0 * n).to_i y = ((1.0 - Math::log(Math::tan(lat_rad) + (1 / Math::cos(lat_rad))) / Math::PI) / 2.0 * n).to_i {:x => x, :y =>y} end |
#distance_by_roads(coordinates) ⇒ Object
|
# File 'lib/libosrm/osrm.rb', line 39
|
#match(coordinates, opts = nil) ⇒ Hash
This action most likely does not work as expected.
This method is implemented in native code.
This method is a wrapper for OSRM’s API. Please see the HTTP API for documentation of response values.
Any differences should be documented in corresponding methods; please report should you find any.
Tries to match given coordinates to road network in most plausible way.
|
# File 'lib/libosrm/osrm.rb', line 112
|
#nearest(latitude, longitude, amount = 1) ⇒ Hash
This method is implemented in native code.
This method is a wrapper for OSRM’s API. Please see the HTTP API for documentation of response values.
Any differences should be documented in corresponding methods; please report should you find any.
OSRM nearest action. Returns nearest street network points.
|
# File 'lib/libosrm/osrm.rb', line 89
|
#route(coordinates, opts = nil) ⇒ Hash
This method is implemented in native code.
This method is a wrapper for OSRM’s API. Please see the HTTP API for documentation of response values.
Any differences should be documented in corresponding methods; please report should you find any.
If you only want to know distance by roads for the trip, use #distance_by_roads instead.
OSRM routing action. Takes two or more coordinate pairs and calculates distance by roads between them. A successful response contains an array of resulting routing data, between each point in the request.
|
# File 'lib/libosrm/osrm.rb', line 57
|
#table(coordinates, opts = nil) ⇒ Hash
This method is implemented in native code.
This method is a wrapper for OSRM’s API. Please see the HTTP API for documentation of response values.
Any differences should be documented in corresponding methods; please report should you find any.
OSRM table action. Takes a list of coordinate pairs and calculates distances between each pair to all other pairs. The calculations can be customized by sources and destinations parameters. By default full table is calculated.
|
# File 'lib/libosrm/osrm.rb', line 75
|
#tile(x, y, zoom) ⇒ Hash
This method is implemented in native code.
This method is a wrapper for OSRM’s API. Please see the HTTP API for documentation of response values.
Any differences should be documented in corresponding methods; please report should you find any.
You should most likely use #tile_with_coordinates instead.
Calculates a vector tile image that can be used to examine the routing graph. See the official documentation for more comprehensive documentation about this feature.
|
# File 'lib/libosrm/osrm.rb', line 124
|
#tile_with_coordinates(latitude, longitude, zoom) ⇒ Object
Invokes #tile, but first converts given coordinates to tile numbers.
144 145 146 147 |
# File 'lib/libosrm/osrm.rb', line 144 def tile_with_coordinates latitude, longitude, zoom xy = coordinates_to_tile_numbers latitude, longitude, zoom tile xy[:x], xy[:y], zoom end |
#trip(coordinates) ⇒ Hash
This method is implemented in native code.
This method is a wrapper for OSRM’s API. Please see the HTTP API for documentation of response values.
Any differences should be documented in corresponding methods; please report should you find any.
Tries to calculate shortest possible route between given coordinates (and then back to original point; i.e. the first coordinate pair in the input), in order to solve the travelling salesman problem.
|
# File 'lib/libosrm/osrm.rb', line 101
|