Learn R Programming

osrm (version 3.5.1)

osrmIsochrone: Get Polygons of Isochrones

Description

Based on osrmTable, this function buids polygons of isochrones.

Usage

osrmIsochrone(
  loc,
  breaks = seq(from = 0, to = 60, length.out = 7),
  exclude = NULL,
  res = 30,
  returnclass = "sf",
  osrm.server = getOption("osrm.server"),
  osrm.profile = getOption("osrm.profile")
)

Value

An sf MULTIPOLYGON of isochrones is returned. The data frame of the output contains four fields: id (id of each polygon), min and max (minimum and maximum breaks of the polygon), center (central values of classes).

Arguments

loc

a numeric vector of longitude and latitude (WGS84), an sf object of the origine point.

breaks

a numeric vector of isochrone values (in minutes).

exclude

pass an optional "exclude" request option to the OSRM API.

res

number of points used to compute isochrones, one side of the square grid, the total number of points will be res*res.

returnclass

class of the returned polygons.

osrm.server

the base URL of the routing server. getOption("osrm.server") by default.

osrm.profile

the routing profile to use, e.g. "car", "bike" or "foot" (when using the routing.openstreetmap.de test server). getOption("osrm.profile") by default.

See Also

osrmTable

Examples

Run this code
if (FALSE) {
# Load data
library(sf)
apotheke.sf <- st_read(system.file("gpkg/apotheke.gpkg", package = "osrm"), 
                       quiet = TRUE)
# Get isochones with lon/lat coordinates
iso <- osrmIsochrone(loc = c(13.43,52.47), breaks = seq(0,14,2),
                     returnclass="sf")
plot(st_geometry(iso), col = c('grey80','grey60','grey50',
                               'grey40','grey30','grey20'))
# Map
if(require("mapsf")){
  breaks <- sort(c(unique(iso$min), max(iso$max)))
  mapsf::mf_map(x = iso, var = "center", type = "choro", 
                breaks = breaks, pal = "Greens",
                border = NA, leg_pos = "topleft",
                leg_frame = TRUE, leg_title = "Isochrones\n(min)")
}

# Get isochones with an sf POINT
iso2 <- osrmIsochrone(loc = apotheke.sf[10,], returnclass="sf",
                      breaks = seq(from = 0, to = 16, by = 2))
# Map
if(require("mapsf")){
  breaks2 <- sort(c(unique(iso2$min), max(iso2$max)))
  mapsf::mf_map(x = iso2, var = "center", type = "choro", 
                breaks = breaks2, pal = "Blues",
                border = NA, leg_pos = "topleft", leg_val_rnd = 0,
                leg_frame = TRUE, leg_title = "Isochrones\n(min)")
}
}

Run the code above in your browser using DataLab