-
Notifications
You must be signed in to change notification settings - Fork 0
node osrm api
Service | Description |
---|---|
route |
shortest path between given coordinates |
nearest |
returns the nearest street segment for a given coordinate |
table |
computes distance tables for given coordinates |
match |
matches given coordinates to the road network |
trip |
Compute the shortest round trip between given coordinates |
tile |
Return vector tiles containing debugging info |
The following options are supported for all methods, except osrm.tile
.
Option | Values | Description |
---|---|---|
coordinates |
array of coordinate elements: [{coordinate}, ...]
|
The coordinates this request will use. |
bearings |
array of bearing elements: [{bearing}, ...]
|
Limits the search to segments with given bearing in degrees towards true north in clockwise direction. |
radiuses |
array of radius elements: [{radius}, ...]
|
Limits the search to given radius in meters. |
hints |
array of hint elements: [{hint}, ...]
|
Hint to derive position in street network. |
Where the elements follow the following format:
Element | Values |
---|---|
coordinate |
array with [{lon},{lat}] values, in decimal degrees |
bearing |
null or array with [{value},{range}] integer 0 .. 360,integer 0 .. 180
|
radius |
null or double >= 0 or unlimited (default) |
hint | Base64 string
|
All array need to have the same length as the provided coordinates
array or undefined
.
Query on Berlin with three coordinates:
var osrm = new OSRM('berlin.osrm');
osrm.route({
coordinates: [[13.388860,52.517037], [13.397634,52.529407], [13.428555,52.523219]],
overview: false
}, (err, result) => {});
new OSRM()
Creates a new OSRM object and tried to load the data from shared memory.
new OSRM('input_data.osrm')
Creats a new OSRM object from a file.
new OSRM(options)
Creates a new OSRM object where options
can have one of the following keys:
Option | Values | Description |
---|---|---|
shared_memory |
true (default), false
|
Use shared memory loaded with osmr-datastore
|
path |
undefined (default), string
|
Path to file to use instead of shared memory. Requires shared_memory = false
|
Snaps a coordinate to the street network and returns the nearest n matches.
OSRM.nearest(options, callback)
Where coordinates
only supports a single {longitude},{latitude}
entry.
In addition to the general options the following options are supported for this service:
Option | Values | Description |
---|---|---|
number |
integer >= 1 (default 1 ) |
Number of nearest segments that should be returned. |
-
waypoints
array ofWaypoint
objects sorted by distance to the input coordinate. Each object has at least the following additional properties:-
distance
: Distance in meters to the supplied input coordinate.
-
Querying nearest three snapped locations of 13.388860,52.517037
with a bearing between 20° - 340°
.
var osrm = new OSRM('berlin.osrm');
osrm.nearest({ coordinates: [[13.388860,52.517037]], number: 3, bearings: [[0,20]]}, (err, result) => {});
Returns the fastest route between two or more coordinates while visiting the waypoints in order.
OSRM.route(options, callback)
In addition to the general options the following options are supported for this service:
Option | Values | Description |
---|---|---|
alternatives |
true , false (default) |
Search for alternative routes and return as well.* |
steps |
true , false (default) |
Return route steps for each route leg |
geometries |
polyline (default), geojson
|
Returned route geometry format (influences overview and per step) |
overview |
simplified (default), full , false
|
Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all. |
continue_straight |
null (default), true , false
|
Forces the route to keep going straight at waypoints and don't do a uturn even if it would be faster. Default value depends on the profile. |
* Please note that even if an alternative route is requested, a result cannot be guaranteed.
-
waypoints
: Array ofWaypoint
objects representing all waypoints in order: -
routes
: An array ofRoute
objects, ordered by descending recommendation rank.
Computes duration tables for the given locations. Allows for both symmetric and asymmetric tables.
OSRM.table(options, callback)
In addition to the general options the following options are supported for this service:
Option | Values | Description |
---|---|---|
sources |
array of index elements: [{index} ...]
|
Use location with given index as source. Default is to use all. |
destinations |
array of index elements: [{index} ...]
|
Use location with given index as destination. Default is to use all. |
Unlike other array encoded options, the length of sources
and destinations
can be smaller or equal
to number of input coordinates.
Element | Values |
---|---|
index | 0 <= integer < #coordinates |
-
durations
array of arrays that stores the matrix in row-major order.durations[i][j]
gives the travel time from the i-th waypoint to the j-th waypoint. Values are given in seconds. -
sources
array ofWaypoint
objects describing all sources in order -
destinations
array ofWaypoint
objects describing all destinations in order
Returns a 3x3
matrix:
var osrm = new OSRM('berlin.osrm');
osrm.table({coordinates: [[13.388860,52.517037], [13.397634,52.529407], [13.428555,52.523219]]}, (err, result) => {});
Returns a 1x3
matrix:
var osrm = new OSRM('berlin.osrm');
osrm.table({coordinates: [[13.388860,52.517037], [13.397634,52.529407], [13.428555,52.523219]], sources:[0]}, (err, result) => {});
Map matching matches given GPS points to the road network in the most plausible way. Please note the request might result multiple sub-traces. Large jumps in the timestamps (>60s) or improbable transitions lead to trace splits if a complete matching could not be found. The algorithm might not be able to match all points. Outliers are removed if they can not be matched successfully.
OSRM.match(options, callback)
In addition to the general options the following options are supported for this service:
Option | Values | Description |
---|---|---|
steps |
true , false (default) |
Return route steps for each route |
geometries |
polyline (default), geojson
|
Returned route geometry format (influences overview and per step) |
overview |
simplified (default), full , false
|
Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all. |
timestamps |
array of timestamp elements: `[{timestamp}, ...] |
Timestamp of the input location. |
radiuses |
array of radius elements: [{radius}, ...]
|
Standard deviation of GPS precision used for map matching. If applicable use GPS accuracy. |
Element | Values |
---|---|
timestamp |
integer UNIX-like timestamp |
radius |
double >= 0 (default 5m) |
-
tracepoints
: Array ofẀaypoint
objects representing all points of the trace in order. If the trace point was ommited by map matching because it is an outlier, the entry will benull
. EachWaypoint
object has the following additional properties:-
matchings_index
: Index to theRoute
object inmatchings
the sub-trace was matched to. -
waypoint_index
: Index of the waypoint inside the matched route.
-
-
matchings
: An array ofRoute
objects that assemble the trace. EachRoute
object has the following additional properties:-
confidence
: Confidence of the matching.float
value between 0 and 1. 1 is very confident that the matching is correct.
-
The trip plugin solves the Traveling Salesman Problem using a greedy heuristic (farthest-insertion algorithm). The returned path does not have to be the shortest path, as TSP is NP-hard it is only an approximation. Note that if the input coordinates can not be joined by a single trip (e.g. the coordinates are on several disconnected islands) multiple trips for each connected component are returned.
osrm.trip(options, callback)
In addition to the general options the following options are supported for this service:
Option | Values | Description |
---|---|---|
steps |
true , false (default) |
Return route instructions for each trip |
geometries |
polyline (default), geojson
|
Returned route geometry format (influences overview and per step) |
overview |
simplified (default), full , false
|
Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all. |
-
waypoints
: Array ofWaypoint
objects representing all waypoints in input order. EachWaypoint
object has the following additional properties:-
trips_index
: Index totrips
of the sub-trip the point was matched to. -
waypoint_index
: Index of the point in the trip.
-
-
trips
: An array ofRoute
objects that assemble the trace.
Represents a route through (potentially multiple) waypoints.
-
distance
: The distance traveled by the route, infloat
meters. -
duration
: The estimated travel time, infloat
number of seconds. -
geometry
: The whole geometry of the route value depending onoverview
parameter, format depending on thegeometries
parameter. SeeRouteStep
'sgeometry
field for a parameter documentation.overview Description simplified Geometry is simplified according to the highest zoom level it can still be displayed on full. full Geometry is not simplified. false Geometry is not added. -
legs
: The legs between the given waypoints, an array ofRouteLeg
objects.
Three input coordinates, geometry=geojson
, steps=false
:
{
distance: 90.,
duration: 300.,
geometry: {type: LineString, coordinates: [[120., 10.], [120.1, 10.], [120.2, 10.], [120.3, 10.]]},
legs: [
{
distance: 30.,
duration: 100,
steps: []
},
{
distance: 60.,
duration: 200,
steps: []
}
]
}
Represents a route between two waypoints.
-
distance
: The distance traveled by this route leg, infloat
meters. -
duration
: The estimated travel time, infloat
number of seconds. -
summary
: Summary of the route taken asstring
. Depends on thesteps
parameter:steps true Names of the two major roads used. Can be empty if route is too short. false empty string
-
steps
: Depends on thesteps
parameter.steps true array of RouteStep
objects describing the turn-by-turn instructionsfalse empty array
With steps=false
:
{
distance: 30.,
duration: 100,
steps: []
}
A step consists of a maneuver such as a turn or merge, followed by a distance of travel along a single way to the subsequent step.
-
distance
: The distance of travel from the maneuver to the subsequent step, infloat
meters. -
duration
: The estimated travel time, infloat
number of seconds. -
geometry
: The unsimplified geometry of the route segment, depending on thegeometries
parameter.geometries polyline polyline with precision 5 in [latitude,longitude] encoding geojson GeoJSON LineString
or GeoJSONPoint
if it is only one coordinate (not wrapped by a GeoJSON feature) -
name
: The name of the way along which travel proceeds. -
mode
: A string signifying the mode of transportation. -
maneuver
: AStepManeuver
object representing the maneuver.
-
location
: A[longitude, latitude]
pair describing the location of the turn. -
bearing_before
: The clockwise angle from true north to the direction of travel immediately before the maneuver. -
bearing_after
: The clockwise angle from true north to the direction of travel immediately after the maneuver. -
type
A string indicating the type of maneuvertype
Description turn a basic turn into direction of the modifier
new name no turn is taken, but the road name changes depart indicates the departure of the leg arrive indicates the destination of the leg merge merge onto a street (e.g. getting on the highway from a ramp ramp take a ramp to exit a highway fork take the left/right side at a fork depending on modifier
end of road road ends in a T intersection turn in direction of modifier
continue Turn in direction of modifier
to stay on the same roadroundabout traverse roundabout, has additional field exit
with NR if the roundabout is left.rotary a larger version of a roundabout, can offer rotary_name
in addition to theexit
parameter.notification not an actual turn but a change in the driving conditions. For example the travel mode. Please note that even though there are
new name
andnotification
instructions, themode
andname
can change between all instructions. They only offer a fallback in case nothing else is to report. -
modifier
An optionalstring
indicating the direction change of the maneuver.modifier
Description uturn indicates reversal of direction sharp right a sharp right turn right a normal turn to the right slight right a slight turn to the right straight no relevant change in direction slight left a slight turn to the left left a normal turn to the left sharp left a sharp turn to the left The meaning depends on the
type
field.type
Description turn
modifier
indicates the change in direction accomplished through the turndepart
/arrive
modifier
indicates the position of departure point and arrival point in relation to the current direction of travel -
exit
An optionalinteger
indicating number of the exit to take. The field exists for the followingtype
field:type
Description roundabout
Number of the roundabout exit to take. If exit is undefined
the destination is on the roundabout.turn
orend of road
Indicates the number of intersections passed until the turn. Example instruction: at the fourth intersection, turn left
New maneuver type
and modifier
and new properties (potentially depending on type
) may be introduced in the future without an API version change.
Object used to describe waypoint on a route.
-
name
Name of the street the coordinate snapped to -
location
Array that contains the[longitude, latitude]
pair of the snapped coordinate -
hint
Unique internal identifier of the segment (ephemeral, not constant over data updates) This can be used on subsequent request to significantly speed up the query and to connect multiple services. E.g. you can use thehint
value obtained by thenearest
query ashint
values forroute
inputs.
This generates Mapbox Vector Tiles that can be viewed with a vector-tile capable slippy-map viewer. The tiles contain road geometries and metadata that can be used to examine the routing graph. The tiles are generated directly from the data in-memory, so are in sync with actual routing results, and let you examine which roads are actually routable, and what weights they have applied.
osrm.tile([x, y, z], callback)
The x
, y
, and z
values are the same as described at https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames, and are supported by vector tile viewers like Mapbox GL JS.
The result will be Buffer
that contains a PBF encoded vector tile.