Learn R Programming

mapboxapi (version 0.2)

mb_isochrone: Generate an isochrone using the Mapbox API

Description

Generate an isochrone using the Mapbox API

Usage

mb_isochrone(
  location,
  profile = "driving",
  time = c(5, 10, 15),
  access_token = NULL,
  denoise = 1,
  geometry = "polygon",
  output = "sf",
  rate_limit = 300,
  keep_color_cols = FALSE,
  id_column = NULL
)

Arguments

location

A vector of form c(longitude, latitude), an address that can be geocoded as a character string, or an sf object.

profile

One of "driving", "walking", or "cycling". "driving" is the default.

time

A vector of isochrone contours, specified in minutes. Defaults to c(5, 10, 15). The maximum time supported is 60 minutes.

access_token

A valid Mapbox access token.

denoise

A floating-point value between 0 and 1 used to remove smaller contours. 1 is the default and returns only the largest contour for an input time.

geometry

one of "polygon" (the default), which returns isochrones as polygons, or alternatively "linestring", which returns isochrones as linestrings.

output

one of "sf" (the default), which returns an sf object representing the isochrone(s), or "list", which returns the GeoJSON response from the API as an R list.

rate_limit

The rate limit for the API, expressed in maximum number of calls per minute. For most users this will be 300 though this parameter can be modified based on your Mapbox plan. Used when location is "sf".

keep_color_cols

Whether or not to retain the color columns that the Mapbox API generates by default (applies when the output is an sf object). Defaults to FALSE.

id_column

If the input dataset is an sf object, the column in your dataset you want to use as the isochrone ID. Otherwise, isochrone IDs will be identified by row index or position.

Value

An sf object representing the isochrone(s) around the location(s).

Examples

Run this code
# NOT RUN {
library(mapboxapi)
library(mapdeck)
isochrones <- mb_isochrone("The Kremlin, Moscow Russia",
                           time = c(4, 8, 12),
                           profile = "walking")

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

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab