Compute a travel-time matrix from census tract representative points to source points
Source:R/travel-time.R
compute_travel_times.RdBuilds a travel-time matrix using the r5r routing engine. Computes travel times from representative points of target census tracts to geolocated source points (e.g., polling locations).
Usage
compute_travel_times(
tracts_sf,
points_sf,
network_path,
tract_id = "id",
point_id = "id",
routing = routing_control(),
verbose = TRUE
)Arguments
- tracts_sf
An
sfobject with polygon geometries. Target census tracts.- points_sf
An
sfobject with point geometries. Source points.- network_path
Character. Path to the directory containing the OSM
.pbffile for building the r5r network.- tract_id
Character. Name of the ID column in
tracts_sf. Default:"id".- point_id
Character. Name of the ID column in
points_sf. Default:"id".- routing
A
routing_control()object with routing parameters (mode, point_method, max_trip_duration, n_threads, gtfs_zip_path, departure_datetime, pop_raster, min_area_for_pop_weight, osm_buffer_km, fill_missing). Default:routing_control().- verbose
Logical. Default: TRUE.
Value
A numeric matrix [n_tracts x n_points]. Travel times in minutes.
Row names = census tract IDs, column names = point IDs. Unreachable
pairs are filled with fill_missing.
Details
Requires the r5r and sf packages. r5r requires exactly Java/JDK 21.
Use download_r5r_data() to obtain the OSM data needed for network_path.
See also
routing_control() for routing parameters,
download_r5r_data() to download OSM and elevation data.
Other spatial:
download_r5r_data()
Examples
if (FALSE) { # \dontrun{
tt <- compute_travel_times(
tracts_sf = tracts, points_sf = stations,
network_path = "path/to/osm_data",
tract_id = "code_tract", point_id = "id"
)
# Transit mode with GTFS
tt <- compute_travel_times(
tracts_sf = tracts, points_sf = stations,
network_path = "path/to/osm_data",
routing = routing_control(
mode = c("WALK", "TRANSIT"),
gtfs_zip_path = "sptrans.zip",
departure_datetime = as.POSIXct("2022-10-02 10:00:00")
)
)
} # }