Title: | An 'openrouteservice' API Client |
---|---|
Description: | The client streamlines access to the services provided by <https://api.openrouteservice.org>. It allows you to painlessly query for directions, isochrones, time-distance matrices, geocoding, elevation, points of interest, and more. |
Authors: | Heidelberg Institute for Geoinformation Technology (HeiGIT) gGmbH [cph], Andrzej K. Oleś [aut, cre] |
Maintainer: | Andrzej K. Oleś <[email protected]> |
License: | Apache License 2.0 |
Version: | 0.6.1 |
Built: | 2024-11-19 02:51:30 UTC |
Source: | https://github.com/giscience/openrouteservice-r |
Helper function to set the bounds of a leaflet map widget.
fitBBox(map, bbox)
fitBBox(map, bbox)
map |
a map widget object created from |
bbox |
A vector |
The modified map widget.
Andrzej Oleś [email protected]
Get/set openrouteservice API key.
ors_api_key(key, service = "openrouteservice", username = NULL, keyring = NULL)
ors_api_key(key, service = "openrouteservice", username = NULL, keyring = NULL)
key |
API key value provided as a character scalar |
service |
Service name, a character scalar. |
username |
Username, a character scalar, or |
keyring |
For systems that support multiple keyrings, specify
the name of the keyring to use here. If |
To set the key provide it in the key
argument. To retrieve the current
value call the function with key
unset.
Typically the key is saved in the system credential store. Once the key is defined, it persists in the keyring store of the operating system so it doesn't need to be set again in a new R session.
Internally the function uses \link[keyring]{key_set}
and
\link[keyring]{key_get}
. The use of keyring package can be bypassed by
providing the key in the environment variable ORS_API_KEY. The value from the
environment variable takes precedence over the value stored in the system
credential store. The default environment variable name used to retrieve the
openrouteservice api key can be overridden by specifying it in
options("openrouteservice.api_key_env")
.
API Key value when called without key
.
Andrzej Oleś [email protected]
Get directions for different modes of transport.
ors_directions( coordinates, profile = ors_profile(), format = c("geojson", "json", "gpx"), ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
ors_directions( coordinates, profile = ors_profile(), format = c("geojson", "json", "gpx"), ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
coordinates |
List of |
profile |
Route profile, defaults to |
format |
Response format, defaults to |
... |
Optional parameters as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
Route between two or more locations in the selected format
structured according to output
:
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
for "sf"
, a simple features sf
object.
Andrzej Oleś [email protected]
coordinates <- list(c(8.34234, 48.23424), c(8.34423, 48.26424)) # simple call ors_directions(coordinates, preference="fastest") # customized options ors_directions(coordinates, profile="cycling-mountain", elevation=TRUE) # list of locations as `data.frame` output as simple features `sf` object locations <- data.frame(lng = c(8.34234, 8.327807, 8.34423), lat = c(48.23424, 48.239368, 48.26424)) ors_directions(locations, output = "sf")
coordinates <- list(c(8.34234, 48.23424), c(8.34423, 48.26424)) # simple call ors_directions(coordinates, preference="fastest") # customized options ors_directions(coordinates, profile="cycling-mountain", elevation=TRUE) # list of locations as `data.frame` output as simple features `sf` object locations <- data.frame(lng = c(8.34234, 8.327807, 8.34423), lat = c(48.23424, 48.239368, 48.26424)) ors_directions(locations, output = "sf")
Get elevation data for points or lines
ors_elevation( format_in = c("geojson", "point", "polyline", "encodedpolyline", "encodedpolyline6"), geometry, format_out = format_in, ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
ors_elevation( format_in = c("geojson", "point", "polyline", "encodedpolyline", "encodedpolyline6"), geometry, format_out = format_in, ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
format_in |
input format |
geometry |
|
format_out |
output format |
... |
Optional parameters as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
A GeoJSON based service to query SRTM elevation for Point or LineString 2D geometries and return 3D geometries in various formats.
3D point or line geometry structured according to output
:
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
for "sf"
, a simple features sf
object.
Andrzej Oleś [email protected]
# point coordinates coordinates <- c(13.349762, 38.11295) ors_elevation("point", coordinates) # geojson as input point <- '{ "type": "Point", "coordinates": [13.349762, 38.11295] }' ors_elevation("geojson", point) # line geometry returned as encoded polyline coordinates <- list( c(13.349762, 38.11295), c(12.638397, 37.645772) ) ors_elevation("polyline", coordinates, format_out = "encodedpolyline")
# point coordinates coordinates <- c(13.349762, 38.11295) ors_elevation("point", coordinates) # geojson as input point <- '{ "type": "Point", "coordinates": [13.349762, 38.11295] }' ors_elevation("geojson", point) # line geometry returned as encoded polyline coordinates <- list( c(13.349762, 38.11295), c(12.638397, 37.645772) ) ors_elevation("polyline", coordinates, format_out = "encodedpolyline")
Export the base graph for different modes of transport.
ors_export( bbox, profile = ors_profile(), ..., api_key = ors_api_key(), output = c("parsed", "text") )
ors_export( bbox, profile = ors_profile(), ..., api_key = ors_api_key(), output = c("parsed", "text") )
bbox |
List of |
profile |
Route profile, defaults to |
... |
Optional parameters as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
Lists of graph nodes and edges contained in the provided bounding box and relevant for the given routing profile. The edge property weight
represents travel time in seconds. The response is structured according to output
:
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
Andrzej Oleś [email protected]
## Not run: bbox <- list( c(8.681495, 49.41461), c(8.686507, 49.41943) ) res <- ors_export(bbox) ## End(Not run)
## Not run: bbox <- list( c(8.681495, 49.41461), c(8.686507, 49.41943) ) res <- ors_export(bbox) ## End(Not run)
Resolve input coordinates to addresses and vice versa.
ors_geocode( query, location, ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
ors_geocode( query, location, ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
query |
Name of location, street address or postal code. For a structured geocoding request a named list of parameters. |
location |
Coordinates to be inquired provided in the form |
... |
Optional parameters as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
This endpoint can be used for geocoding (specified query
) and reverse
geocoding requests (specified location
). Either query
or location
has
to be specified for a valid request. If both parameters are specified
location takes precedence.
Geocoding: a JSON formatted list of objects corresponding to the search input. Reverse geocoding: the next enclosing object with an address tag which surrounds the given coordinate.
Andrzej Oleś [email protected]
## locations of Heidelberg around the globe x <- ors_geocode("Heidelberg") ## set the number of results returned x <- ors_geocode("Heidelberg", size = 1) ## search within a particular country ors_geocode("Heidelberg", boundary.country = "DE") ## structured geocoding x <- ors_geocode(list(locality="Heidelberg", county="Heidelberg")) ## reverse geocoding location <- x$features[[1L]]$geometry$coordinates y <- ors_geocode(location = location, layers = "locality", size = 1)
## locations of Heidelberg around the globe x <- ors_geocode("Heidelberg") ## set the number of results returned x <- ors_geocode("Heidelberg", size = 1) ## search within a particular country ors_geocode("Heidelberg", boundary.country = "DE") ## structured geocoding x <- ors_geocode(list(locality="Heidelberg", county="Heidelberg")) ## reverse geocoding location <- x$features[[1L]]$geometry$coordinates y <- ors_geocode(location = location, layers = "locality", size = 1)
Obtain areas of reachability from given locations.
ors_isochrones( locations, profile = ors_profile(), range = 60, ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
ors_isochrones( locations, profile = ors_profile(), range = 60, ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
locations |
List of |
profile |
Route profile, defaults to |
range |
Maximum range value of the analysis in seconds for time and meters for distance. Alternatively a comma separated list of specific single range values. |
... |
Optional parameters as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
The Isochrone Service supports time and distance analyses for one single or multiple locations. You may also specify the isochrone interval or provide multiple exact isochrone range values.
A GeoJSON object containing a FeatureCollection of Polygons
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
for "sf"
, a simple features sf
object.
Andrzej Oleś [email protected]
ors_isochrones(c(8.34234, 48.23424), interval=20) locations <- list(c(8.681495, 49.41461), c(8.686507,49.41943)) ors_isochrones(locations, range=c(300, 200))
ors_isochrones(c(8.34234, 48.23424), interval=20) locations <- list(c(8.681495, 49.41461), c(8.686507,49.41943)) ors_isochrones(locations, range=c(300, 200))
Obtain one-to-many, many-to-one and many-to-many matrices for time and distance.
ors_matrix( locations, profile = ors_profile(), ..., api_key = ors_api_key(), output = c("parsed", "text") )
ors_matrix( locations, profile = ors_profile(), ..., api_key = ors_api_key(), output = c("parsed", "text") )
locations |
List of |
profile |
Route profile, defaults to |
... |
Optional parameters as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
Duration or distance matrix for multiple source and destination
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
Andrzej Oleś [email protected]
coordinates <- list( c(9.970093, 48.477473), c(9.207916, 49.153868), c(37.573242, 55.801281), c(115.663757,38.106467) ) # query for duration and distance in km res <- ors_matrix(coordinates, metrics = c("duration", "distance"), units = "km") # duration in hours res$durations / 3600 # distance in km res$distances
coordinates <- list( c(9.970093, 48.477473), c(9.207916, 49.153868), c(37.573242, 55.801281), c(115.663757,38.106467) ) # query for duration and distance in km res <- ors_matrix(coordinates, metrics = c("duration", "distance"), units = "km") # duration in hours res$durations / 3600 # distance in km res$distances
Optimize a fleet of vehicles on a number of jobs. For more information, see the Vroom project API documentation.
The helper functions jobs()
and vehicles()
create
data.frames which can be used as arguments to ors_optimization()
.
ors_optimization( jobs, vehicles, matrix = NULL, ..., api_key = ors_api_key(), output = c("parsed", "text") ) jobs( id, location, location_index, service, amount, skills, priority, time_windows ) vehicles( id, profile, start, start_index, end, end_index, capacity, skills, time_window )
ors_optimization( jobs, vehicles, matrix = NULL, ..., api_key = ors_api_key(), output = c("parsed", "text") ) jobs( id, location, location_index, service, amount, skills, priority, time_windows ) vehicles( id, profile, start, start_index, end, end_index, capacity, skills, time_window )
jobs |
|
vehicles |
|
matrix |
Optional two-dimensional array describing a custom travel-time matrix |
... |
Optional parameters as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
id |
An integer used as unique identifier |
location |
Coordinates array |
location_index |
Index of relevant row and column in custom matrix |
service |
Job service duration (defaults to 0) |
amount |
An array of integers describing multidimensional quantities |
skills |
An array of integers defining skills |
priority |
An integer in the [0, 10] range describing priority level (defaults to 0) |
time_windows |
An array of time_window objects describing valid slots for job service start |
profile |
routing profile (defaults to car) |
start |
coordinates array |
start_index |
index of relevant row and column in custom matrix |
end |
coordinates array |
end_index |
index of relevant row and column in custom matrix |
capacity |
an array of integers describing multidimensional quantities |
time_window |
a time_window object describing working hours |
Solution computed by the optimization endpoint formatted as described here and structured according to output
:
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
Andrzej Oleś [email protected]
home_base <- c(2.35044, 48.71764) vehicles <- vehicles( id = 1:2, profile = "driving-car", start = home_base, end = home_base, capacity = 4, skills = list(c(1, 14), c(2, 14)), time_window = c(28800, 43200) ) locations <- list( c(1.98935, 48.701), c(2.03655, 48.61128), c(2.39719, 49.07611), c(2.41808, 49.22619), c(2.28325, 48.5958), c(2.89357, 48.90736) ) jobs <- jobs( id = 1:6, service = 300, amount = 1, location = locations, skills = list(1, 1, 2, 2, 14, 14) ) ors_optimization(jobs, vehicles)
home_base <- c(2.35044, 48.71764) vehicles <- vehicles( id = 1:2, profile = "driving-car", start = home_base, end = home_base, capacity = 4, skills = list(c(1, 14), c(2, 14)), time_window = c(28800, 43200) ) locations <- list( c(1.98935, 48.701), c(2.03655, 48.61128), c(2.39719, 49.07611), c(2.41808, 49.22619), c(2.28325, 48.5958), c(2.89357, 48.90736) ) jobs <- jobs( id = 1:6, service = 300, amount = 1, location = locations, skills = list(1, 1, 2, 2, 14, 14) ) ors_optimization(jobs, vehicles)
Search for points of interest around points or in geometries.
ors_pois( request = c("pois", "stats", "list"), geometry, ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
ors_pois( request = c("pois", "stats", "list"), geometry, ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
request |
One of the following: |
geometry |
named list containing either a |
... |
Optional request attributes as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
There are three different request types: pois
, stats
and list
.
pois
returns a GeoJSON FeatureCollection in the bounding box specified in
geometry$bbox
or a GeoJSON geometry provided in geometry$geojson
. stats
does the same but groups by categories, ultimately returning a JSON object
with the absolute numbers of POIs of a certain group.
list
returns a list of category groups and their ids.
A list of points of interest in the area specified in geometry
structured according to output
:
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
for "sf"
, a simple features sf
object. Valid only for argument request = "pois"
.
Andrzej Oleś [email protected]
# POI categories list ors_pois('list') # POIs around a buffered point geometry <- list(geojson = list(type = "Point", coordinates = c(8.8034, 53.0756)), buffer = 100) ors_pois(geometry = geometry) # alternative specification via bounding box ors_pois(geometry = list(bbox = list(c(8.8034, 53.0756), c(8.8034, 53.0756)), buffer = 100)) # POIs of given categories ors_pois(geometry = geometry, limit = 200, sortby = "distance", filters = list( category_ids = c(180, 245) )) # POIs of given category groups ors_pois(geometry = geometry, limit = 200, sortby = "distance", filters = list( category_group_ids = 160 )) # POI Statistics ors_pois("stats", geometry = geometry)
# POI categories list ors_pois('list') # POIs around a buffered point geometry <- list(geojson = list(type = "Point", coordinates = c(8.8034, 53.0756)), buffer = 100) ors_pois(geometry = geometry) # alternative specification via bounding box ors_pois(geometry = list(bbox = list(c(8.8034, 53.0756), c(8.8034, 53.0756)), buffer = 100)) # POIs of given categories ors_pois(geometry = geometry, limit = 200, sortby = "distance", filters = list( category_ids = c(180, 245) )) # POIs of given category groups ors_pois(geometry = geometry, limit = 200, sortby = "distance", filters = list( category_group_ids = 160 )) # POI Statistics ors_pois("stats", geometry = geometry)
List of available modes of transport.
ors_profile( mode = c("car", "hgv", "bike", "roadbike", "mtb", "e-bike", "walking", "hiking", "wheelchair") )
ors_profile( mode = c("car", "hgv", "bike", "roadbike", "mtb", "e-bike", "walking", "hiking", "wheelchair") )
mode |
Profile label. |
Convenience function for specifying the profile in ors_directions()
,
ors_isochrones()
and ors_matrix()
.
Profile name, or named vector of available profiles.
Andrzej Oleś [email protected]
ors_directions()
, ors_isochrones()
, ors_matrix()
# list availbale profiles ors_profile() # retrieve full profile name based on label ors_profile("car")
# list availbale profiles ors_profile() # retrieve full profile name based on label ors_profile("car")
Snap coordinates to road network
ors_snap( locations, profile = ors_profile(), radius, format = c("geojson", "json"), ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
ors_snap( locations, profile = ors_profile(), radius, format = c("geojson", "json"), ..., api_key = ors_api_key(), output = c("parsed", "text", "sf") )
locations |
List of |
profile |
Route profile, defaults to |
radius |
Maximum radius in meters around given coordinates to search for graph edges |
format |
Response format, defaults to |
... |
Optional parameters as described here |
api_key |
Character scalar containing openrouteservice API key |
output |
Output format. By default the response is being parsed to a list-based R object |
Coordinates of snapped location(s) and distance to the original point(s) structured according to output
:
for "text"
, a character vector of length 1 re-encoded to UTF-8.
for "parsed"
, a parsed R object.
for "sf"
, a simple features sf
object.
Andrzej Oleś [email protected]
locations <- list( c(8.669629, 49.413025), c(8.675841, 49.418532), c(8.665144, 49.415594) ) # query for locations snapped onto the OpenStreetMap road network res <- ors_snap(locations, radius = 350)
locations <- list( c(8.669629, 49.413025), c(8.675841, 49.418532), c(8.665144, 49.415594) ) # query for locations snapped onto the OpenStreetMap road network res <- ors_snap(locations, radius = 350)
print.ors_api
uses str to compactly display the structure
of the openrouteservice API response object.
## S3 method for class 'ors_api' print(x, give.attr = FALSE, list.len = 6L, ...)
## S3 method for class 'ors_api' print(x, give.attr = FALSE, list.len = 6L, ...)
x |
object of class |
give.attr |
logical; if |
list.len |
numeric; maximum number of list elements to display within a level. |
... |
further arguments passed to str. |
print.ors_api
prints its argument and returns it invisibly.