Skip to content
Documentation

Matrix

Available on the following API tiers:

Transitland v2Beta

Compute travel times and distances between every source and every target. Useful for ranking candidates by travel time before planning a full route.

GETPOSThttps://transit.land/api/v2/routing/valhalla/sources_to_targets

Calculate a time-distance matrix from multiple source locations to multiple target locations. Useful for solving optimization problems.

Request

The request object, url-encoded. Identical to the POST body. Encode spaces as %20 rather than +, or send the JSON without spaces; a + is not decoded as a space here and the request will be rejected as unparseable.

expansion_max_distance
integer
Maximum path distance in meters for an expansion. Currently this is implemented for the timedistancematrix algorithm. Source-target pairs whose cheapest path distance exceeds this limit will be returned as unreachable (with null time and distance).
Default0
matrix_locations
integer
Early-exit after finding this many targets. Only valid for TDMatrix algorithm.
shape_format
string
Not all formats are supported by all endpoints, e.g. no_shape is not valid for isochrone.
Defaultpolyline6
Enumpolyline6polyline5geojsonno_shape

Examplepolyline6

sources
array: object
Required
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
display_lon
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
integer
How close in degrees a given street's angle must be in order for it to be considered as in the same direction of the heading parameter. The default value is service configuration dependent (60 by default).
lat
number
Required
lon
number
Required
minimum_reachability
integer
Minimum number of reachable edges for a snap candidate. The default and max values are service configuration dependent (50 and 100 by default, respectively).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
integer
If set, edges whose layer does not match this value are discarded from candidate search. Note that this is a "soft" filter, meaning if no other candidates are found, Valhalla will fall back to including edges that did not match this filter.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
integer
Candidate search radius in meters: all viable edge candidates within the radius are correlated. If none are found, the best one outside the radius is correlated. The default is service dependent, and defaults to 0 (only the closest edge is considered as candidate). The max value is service configuration dependent (200 by default).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
integer
The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none. The default value is service configuration dependent (1000 by default).
street_side_tolerance
integer
If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel. The default value is service configuration dependent (5 by default).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
display_lon
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
integer
How close in degrees a given street's angle must be in order for it to be considered as in the same direction of the heading parameter. The default value is service configuration dependent (60 by default).
lat
number
Required
lon
number
Required
minimum_reachability
integer
Minimum number of reachable edges for a snap candidate. The default and max values are service configuration dependent (50 and 100 by default, respectively).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
integer
If set, edges whose layer does not match this value are discarded from candidate search. Note that this is a "soft" filter, meaning if no other candidates are found, Valhalla will fall back to including edges that did not match this filter.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
integer
Candidate search radius in meters: all viable edge candidates within the radius are correlated. If none are found, the best one outside the radius is correlated. The default is service dependent, and defaults to 0 (only the closest edge is considered as candidate). The max value is service configuration dependent (200 by default).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
integer
The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none. The default value is service configuration dependent (1000 by default).
street_side_tolerance
integer
If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel. The default value is service configuration dependent (5 by default).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
targets
array: object
Required
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
display_lon
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
integer
How close in degrees a given street's angle must be in order for it to be considered as in the same direction of the heading parameter. The default value is service configuration dependent (60 by default).
lat
number
Required
lon
number
Required
minimum_reachability
integer
Minimum number of reachable edges for a snap candidate. The default and max values are service configuration dependent (50 and 100 by default, respectively).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
integer
If set, edges whose layer does not match this value are discarded from candidate search. Note that this is a "soft" filter, meaning if no other candidates are found, Valhalla will fall back to including edges that did not match this filter.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
integer
Candidate search radius in meters: all viable edge candidates within the radius are correlated. If none are found, the best one outside the radius is correlated. The default is service dependent, and defaults to 0 (only the closest edge is considered as candidate). The max value is service configuration dependent (200 by default).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
integer
The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none. The default value is service configuration dependent (1000 by default).
street_side_tolerance
integer
If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel. The default value is service configuration dependent (5 by default).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
display_lon
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
integer
How close in degrees a given street's angle must be in order for it to be considered as in the same direction of the heading parameter. The default value is service configuration dependent (60 by default).
lat
number
Required
lon
number
Required
minimum_reachability
integer
Minimum number of reachable edges for a snap candidate. The default and max values are service configuration dependent (50 and 100 by default, respectively).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
integer
If set, edges whose layer does not match this value are discarded from candidate search. Note that this is a "soft" filter, meaning if no other candidates are found, Valhalla will fall back to including edges that did not match this filter.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
integer
Candidate search radius in meters: all viable edge candidates within the radius are correlated. If none are found, the best one outside the radius is correlated. The default is service dependent, and defaults to 0 (only the closest edge is considered as candidate). The max value is service configuration dependent (200 by default).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
integer
The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none. The default value is service configuration dependent (1000 by default).
street_side_tolerance
integer
If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel. The default value is service configuration dependent (5 by default).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
verbose
boolean
Include detailed per-cell metadata in the response.
Defaulttrue
costing
string
Not available here: multimodal — transit routing is served by the Transitland Routing API at /otp/plan, not by this engine.
Required
Enumautobicyclepedestriantruckbustaximotor_scootermotorcyclebikeshareauto_pedestrian

Exampleauto

costing_options
object
Costing options keyed by costing model name.
auto
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
bicycle
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
bikeshare
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
bus
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
motor_scooter
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
motorcycle
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
pedestrian
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
taxi
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
truck
object
Options shared by all costing models. Parsed in src/sif/dynamiccost.cc.
date_time
object
type
integer
0=current, 1=depart_at, 2=arrive_by, 3=invariant
Enum0123
value
string
ISO 8601 local datetime string in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06. Required for types 1, 2, 3.
exclude_locations
array: object
A set of locations to exclude or avoid within a route.
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
display_lon
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
integer
How close in degrees a given street's angle must be in order for it to be considered as in the same direction of the heading parameter. The default value is service configuration dependent (60 by default).
lat
number
Required
lon
number
Required
minimum_reachability
integer
Minimum number of reachable edges for a snap candidate. The default and max values are service configuration dependent (50 and 100 by default, respectively).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
integer
If set, edges whose layer does not match this value are discarded from candidate search. Note that this is a "soft" filter, meaning if no other candidates are found, Valhalla will fall back to including edges that did not match this filter.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
integer
Candidate search radius in meters: all viable edge candidates within the radius are correlated. If none are found, the best one outside the radius is correlated. The default is service dependent, and defaults to 0 (only the closest edge is considered as candidate). The max value is service configuration dependent (200 by default).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
integer
The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none. The default value is service configuration dependent (1000 by default).
street_side_tolerance
integer
If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel. The default value is service configuration dependent (5 by default).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
date_time
string
Per-location ISO 8601 datetime override, in the format YYYY-MM-DDTHH:MM, e.g. 2016-07-03T08:06.
display_lat
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
display_lon
number
Latitude of the map location in degrees. If provided the lat and lon parameters will be treated as the routing location and the display_lat and display_lon will be used to determine the side of street. Both display_lat and display_lon must be provided and valid to achieve the desired effect.
heading
integer
Preferred approach heading in degrees.
heading_tolerance
integer
How close in degrees a given street's angle must be in order for it to be considered as in the same direction of the heading parameter. The default value is service configuration dependent (60 by default).
lat
number
Required
lon
number
Required
minimum_reachability
integer
Minimum number of reachable edges for a snap candidate. The default and max values are service configuration dependent (50 and 100 by default, respectively).
Default50
name
string
Label echoed in the response.
node_snap_tolerance
number
Snap-to-node distance tolerance in meters. The default value is service dependent (5 by default).
preferred_layer
integer
If set, edges whose layer does not match this value are discarded from candidate search. Note that this is a "soft" filter, meaning if no other candidates are found, Valhalla will fall back to including edges that did not match this filter.
preferred_side
string
Preferred side of road to snap to.
Defaulteither
Enumsameoppositeeither

Exampleopposite

radius
integer
Candidate search radius in meters: all viable edge candidates within the radius are correlated. If none are found, the best one outside the radius is correlated. The default is service dependent, and defaults to 0 (only the closest edge is considered as candidate). The max value is service configuration dependent (200 by default).
rank_candidates
boolean
Rank snap candidates by distance to input.
Defaulttrue
search_cutoff
integer
Hard cutoff for candidate search in meters. Default is service configuration dependent (35000 by default).
search_filter
object
Optional filters to exclude candidate edges based on their attribution.
street
string
Street address hint for snapping.
street_side_cutoff
string
Enummotorwaytrunkprimarysecondarytertiaryunclassifiedresidentialservice_other

Exampleprimary

street_side_max_distance
integer
The max distance in meters that the input coordinates or display ll can be from the edge centerline for them to be used for determining the side of street. Beyond this distance the side of street is set to none. The default value is service configuration dependent (1000 by default).
street_side_tolerance
integer
If your input coordinate is less than this tolerance away from the edge centerline then we set your side of street to none otherwise your side of street will be left or right depending on direction of travel. The default value is service configuration dependent (5 by default).
type
string
First and last location are always forced to break.
Defaultbreak
Enumbreakthroughviabreak_through

Examplebreak

waiting
number
Waiting time in seconds at this stop (break/break_through only, not origin/destination).
exclude_polygons
array or object
Array of coordinate rings [[lon,lat],…] or a GeoJSON FeatureCollection. Roads intersecting these rings will be avoided during path finding. Takes one of the 2 forms listed below.
option 1
array: array
Array of closed coordinate rings. All edges intersecting any ring are excluded.
option 2
object
GeoJSON FeatureCollection. Each Feature may carry a properties.levels array to restrict exclusion to specific building/indoor levels in pedestrian routing.
format
string
Not all formats are supported by all endpoints, e.g. geotiff is isochrone-only.
Defaultjson
Enumjsongpxosrmpbfgeotiffmvt

Examplejson

id
string
Arbitrary request identifier echoed in the response.
language
string
BCP47 locale for narrative output. See locales/ for supported values.
Defaulten-US
linear_cost_factors
array: object
Customized cost factors that influence path finding, specified as an array of JSON objects. Objects can be either a GeoJSON linestring feature and a "factor" property or a plain object with a "shape" key, whose value needs to be an encoded polyline (with 6 digit precision), and a "factor" key whose value needs to be float. Valhalla will perform an edge walk (see the map matching documentation for more info) to match the geometry onto edges and use those factors in costing. Edges with factors larger than 1 will be increasingly avoided, while edges with factors smaller than 1 increasingly favored.
option 1
object
option 2
object
option 1
object
option 2
object
units
string
Defaultkm
Enumkmmilesmi

Example request

curl --get "https://transit.land/api/v2/routing/valhalla/sources_to_targets" \
  -H "apikey: YOUR_API_KEY" \
  --data-urlencode 'json={"costing":"auto","sources":[{"lat":37.7793,"lon":-122.4193},{"lat":37.7817,"lon":-122.4108}],"targets":[{"lat":37.7817,"lon":-122.4108},{"lat":37.7844,"lon":-122.4079}]}'

Response

algorithm
string
Which matrix algorithm answered the request.

Examplecostmatrix

sources
array: object
The requested sources, snapped to the network.
lat
number
Latitude of the snapped location.
lon
number
Longitude of the snapped location.
lat
number
Latitude of the snapped location.
lon
number
Longitude of the snapped location.
sources_to_targets
array or object
The matrix itself. Its shape follows the request's verbose flag, which defaults to true: verbose gives one row per source holding a cell per target, while verbose: false gives two parallel arrays-of-arrays instead. Takes one of the 2 forms listed below.
option 1
array: array
Verbose form. One row per source, each holding one cell per target.
option 2
object
Compact form, returned when verbose is false.
targets
array: object
The requested targets, snapped to the network.
lat
number
Latitude of the snapped location.
lon
number
Longitude of the snapped location.
lat
number
Latitude of the snapped location.
lon
number
Longitude of the snapped location.
units
string
Units the distances are expressed in.
Enumkilometersmiles

Example response

Show response
{
  "algorithm": "costmatrix",
  "sources": [
    {
      "lat": 37.779214,
      "lon": -122.419983
    },
    {
      "lat": 37.782246,
      "lon": -122.410884
    }
  ],
  "sources_to_targets": [
    [
      {
        "begin_heading": 350.9,
        "begin_lat": 37.779214,
        "begin_lon": -122.419983,
        "cost": 247.47,
        "distance": 1.053,
        "end_heading": 83,
        "end_lat": 37.782246,
        "end_lon": -122.410884,
        "from_index": 0,
        "time": 130,
        "to_index": 0
      },
      {
        "begin_heading": 350.9,
        "begin_lat": 37.779214,
        "begin_lon": -122.419983,
        "cost": 405.357,
        "distance": 1.546,
        "end_heading": 134.8,
        "end_lat": 37.784135,
        "end_lon": -122.408233,
        "from_index": 0,
        "time": 196,
        "to_index": 1
      }
    ],
    [
      {
        "begin_heading": 83,
        "begin_lat": 37.782246,
        "begin_lon": -122.410884,
        "cost": 300,
        "distance": 1.221,
        "end_heading": 83,
        "end_lat": 37.782246,
        "end_lon": -122.410884,
        "from_index": 1,
        "time": 160,
        "to_index": 0
      },
      {
        "begin_heading": 83,
        "begin_lat": 37.782246,
        "begin_lon": -122.410884,
        "cost": 177.063,
        "distance": 0.495,
        "end_heading": 314.8,
        "end_lat": 37.784135,
        "end_lon": -122.408233,
        "from_index": 1,
        "time": 70,
        "to_index": 1
      }
    ]
  ],
  "targets": [
    {
      "lat": 37.782246,
      "lon": -122.410884
    },
    {
      "lat": 37.784135,
      "lon": -122.408233
    }
  ],
  "units": "kilometers"
}

See the Routing Platform overview for API access, travel modes, and the machine-readable schema.

Reference: Valhalla matrix API reference