mb_matrix: Retrieve a matrix of travel times from the Mapbox Directions...

View source: R/navigation.R

mb_matrixR Documentation

Retrieve a matrix of travel times from the Mapbox Directions API

Description

Retrieve a matrix of travel times from the Mapbox Directions API

Usage

mb_matrix(
  origins,
  destinations = NULL,
  profile = "driving",
  fallback_speed = NULL,
  access_token = NULL,
  duration_output = "minutes"
)

Arguments

origins

The input coordinates of your request. Acceptable inputs include a list of coordinate pair vectors in c(x, y) format or an sf object. For sf linestrings or polygons, the distance between centroids will be taken.

destinations

The destination coordinates of your request. If NULL (the default), a many-to-many matrix using origins will be returned.

profile

One of "driving" (the default), "driving-traffic", "walking", or "cycling".

fallback_speed

A value expressed in kilometers per hour used to estimate travel time when a route cannot be found between locations. The returned travel time will be based on the straight-line estimate of travel between the locations at the specified fallback speed.

access_token

A Mapbox access token (required)

duration_output

one of "minutes" (the default) or "seconds"

Value

An R matrix of source-destination travel times.

Examples

## Not run: 

library(mapboxapi)
library(tigris)
library(mapdeck)

philly_tracts <- tracts("PA", "Philadelphia", cb = TRUE, class = "sf")
downtown_philly <- mb_geocode("Philadelphia City Hall, Philadelphia PA")

time_to_downtown <- mb_matrix(philly_tracts, downtown_philly)

philly_tracts$time <- time_to_downtown

mapdeck(style = mapdeck_style("light")) %>%
  add_polygon(
    data = philly_tracts,
    fill_colour = "time",
    fill_opacity = 0.6,
    legend = TRUE
  )

## End(Not run)


mapboxapi documentation built on April 13, 2022, 1:07 a.m.