vl_isochrone: Get isochrones and isodistances from a point

View source: R/vl_isochrone.R

vl_isochroneR Documentation

Get isochrones and isodistances from a point

Description

Build and send a Valhalla API query to get isochrones or isodistances from a point.
This function interfaces with the Isochrone & Isodistance service.
Note that you must provide either 'times' or 'distances' to compute the isochrones at given times or distances from the center point.

Usage

vl_isochrone(
  loc,
  times,
  distances,
  costing = "auto",
  costing_options = list(),
  server = getOption("valh.server")
)

Arguments

loc

one point from which to compute isochrones. loc can be:

  • a vector of coordinates (longitude and latitude, WGS 84),

  • a data.frame of longitudes and latitudes (WGS 84),

  • a matrix of longitudes and latitudes (WGS 84),

  • an sfc object of type POINT,

  • an sf object of type POINT.

times

vector of travel times (in minutes) to compute the isochrones. The maximum number of isochrones is 4. The minimal value must be greater than 0.

distances

vector of travel distances (in kilometers) to compute the isochrones. The maximum number of isochrones is 4. The minimal value must be greater than 0.

costing

costing model to use.

costing_options

list of options to use with the costing model (see https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/#costing-options for more details about the options available for each costing model).

server

URL of the Valhalla server.

Value

An sf MULTIPOLYGON object is returned with the following fields: 'metric' (the metric used, either 'time' or 'distance') and 'contour' (the value of the metric).

Examples

## Not run: 
# Inputs are data frames
apotheke.df <- read.csv(system.file("csv/apotheke.csv", package = "valh"))

# Extract the first point and compute isochrones at 3, 6, 9 and 12 kilometers,
# using the "auto" costing model
pt1 <- apotheke.df[1, c("lon", "lat")]
iso1 <- vl_isochrone(loc = pt1, distances = c(3, 6, 9, 12), costing = "auto")

# Inputs are sf points
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "valh"),
  quiet = TRUE
)
# Extract the first point and compute isochrones at 15, 30, 45 and 60 minutes
# using the "bicycle" costing model
pt2 <- apotheke.sf[1, ]
iso2 <- vl_isochrone(loc = pt2, times = c(15, 30, 45, 60), costing = "bicycle")

## End(Not run)

valh documentation built on April 11, 2025, 6:14 p.m.