sources_to_targets: Source-to-Targets Origin/Destination Matrices with Valhalla

Description Usage Arguments Value Examples

View source: R/valhalla.R

Description

This function creates a tidy (i.e. long) table of origin-destination trip data using the Valhalla routing engine. For a set of o origins and d destinations, it returns a tibble with (o x d) rows with the travel distance and time between each pair. It can handle several different travel modes and routing options. Please note that this function requires access to a running instance of Valhalla.

This function provides fine-grained control over Valhalla's API options.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sources_to_targets(
  froms,
  tos,
  costing = "auto",
  from_search_filter = list(max_road_class = "motorway", min_road_class =
    "residential"),
  to_search_filter = list(max_road_class = "motorway", min_road_class = "residential"),
  minimum_reachability = 50,
  costing_options = list(),
  hostname = "localhost",
  port = 8002
)

Arguments

froms

A tibble containing origin locations in columns named lat and lon.

tos

A tibble containing destination locations in columns named lat and lon.

costing

The travel costing method: at present "auto", "bicycle", and "pedestrian" are supported.

from_search_filter

A named list of options provided to Valhalla API. Defaults set a maximum road class ("motorway", the highest) and minimum road class ("residential", which is one above the lowest, "service_other"). See API documentation for details.

to_search_filter

A named list of options provided to Valhalla API. Defaults set a maximum road class ("motorway", the highest) and minimum road class ("residential", which is one above the lowest, "service_other"). See API documentation for details.

minimum_reachability

The minimum number of nodes a candidate network needs to have before it is included. Try increasing this value (e.g. to 500) if Valhalla is getting stuck in small disconnected road networks.

costing_options

A named list of options provided to the Valhalla API that affect route costing, e.g. willingness to travel on highways or through alleys. See API documentation for details.

hostname

Hostname or IP address of your Valhalla instance. Defaults to "localhost".

port

The port your Valhalla instance is monitoring. Defaults to 8002.

Value

A tibble showing the trip distances and times from each origin to each destination.

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
# NOTE: Assumes an instance of Valhalla is running on localhost:8002.
library(dplyr)
library(valhallr)
froms <- bind_rows(test_data("parliament"), test_data("uottawa"))
tos <- bind_rows(test_data("cdntirecentre"), test_data("parliament"))
st <- sources_to_targets(froms, tos)

## End(Not run)

valhallr documentation built on March 9, 2021, 9:09 a.m.