od_table {valhallr} | R Documentation |
Generate Tidy Origin-Destination Data using Valhalla
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.
This function is a user-friendly wrapper aroundvalhalla::sources_to_targets()
,
which calls the Valhalla API directly. sources_to_targets()
offers finer-
grained control over API options, and so this latter function may be more
useful for advanced users.
Notable features of od_matrix()
:
You can specify human-readable indices with
from_id_col
andto_id_col
. (Valhalla's API only returns zero-indexed integer identifiers.)You can specify a
batch_size
to break computation into several smaller API calls, to prevent your Valhalla instance from running out of memory. This seems especially important for pedestrian routing, where I've sometimes needed to use a batch size as small as 5.
Usage
od_table(
froms,
from_id_col,
tos,
to_id_col,
costing = "auto",
batch_size = 100,
minimum_reachability = 500,
verbose = FALSE,
hostname = "localhost",
port = 8002
)
Arguments
froms |
A tibble containing origin locations in columns named |
from_id_col |
The name of the column in |
tos |
A tibble containing destination locations in columns named |
to_id_col |
The name of the column in |
costing |
The travel costing method: at present "auto", "bicycle", and "pedestrian" are supported. |
batch_size |
The number of origin points to process per API call. |
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. |
verbose |
Boolean. Defaults to FALSE. If TRUE, it will provide updates on on the batching process (if applicable). |
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 named destination.
Examples
## Not run:
library(dplyr)
library(valhallr)
# set up our inputs
origins <- bind_rows(test_data("parliament"), test_data("uottawa"), test_data("cntower"))
destinations <- bind_rows(test_data("cdntirecentre"), test_data("parliament"))
# generate a tidy origin-destination table
od <- od_table (froms = origins,
from_id_col = "name",
tos = destinations,
to_id_col = "name",
costing = "auto",
batch_size = 100,
minimum_reachability = 500)
## End(Not run)