Title: | An R Interface to the 'GraphHopper' Directions API |
---|---|
Description: | Provides a quick and easy access to the 'GraphHopper' Directions API. 'GraphHopper' <https://www.graphhopper.com/> itself is a routing engine based on 'OpenStreetMap' data. API responses can be converted to simple feature (sf) objects in a convenient way. |
Authors: | Stefan Kuethe [aut, cre] |
Maintainer: | Stefan Kuethe <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.3 |
Built: | 2025-01-23 04:10:28 UTC |
Source: | https://github.com/crazycapivara/graphhopper-r |
Convert a gh object into an sf object
gh_as_sf(data, ...) ## S3 method for class 'gh_route' gh_as_sf(data, ..., geom_type = c("linestring", "point")) ## S3 method for class 'gh_spt' gh_as_sf(data, ...) ## S3 method for class 'gh_isochrone' gh_as_sf(data, ...)
gh_as_sf(data, ...) ## S3 method for class 'gh_route' gh_as_sf(data, ..., geom_type = c("linestring", "point")) ## S3 method for class 'gh_spt' gh_as_sf(data, ...) ## S3 method for class 'gh_isochrone' gh_as_sf(data, ...)
data |
A |
... |
ignored |
geom_type |
Use |
if (FALSE) { start_point <- c(52.592204, 13.414307) end_point <- c(52.539614, 13.364868) route_sf <- gh_get_route(list(start_point, end_point)) %>% gh_as_sf() }
if (FALSE) { start_point <- c(52.592204, 13.414307) end_point <- c(52.539614, 13.364868) route_sf <- gh_get_route(list(start_point, end_point)) %>% gh_as_sf() }
Get a vector with available columns of the spt endpoint
gh_available_spt_columns()
gh_available_spt_columns()
Extract the bounding box from a gh object
gh_bbox(data) ## S3 method for class 'gh_route' gh_bbox(data) ## S3 method for class 'gh_info' gh_bbox(data)
gh_bbox(data) ## S3 method for class 'gh_route' gh_bbox(data) ## S3 method for class 'gh_info' gh_bbox(data)
data |
A |
Get information about the GraphHopper instance
gh_get_info()
gh_get_info()
if (FALSE) { info <- gh_get_info() message(info$version) message(info$data_date) print(gh_bbox(info)) }
if (FALSE) { info <- gh_get_info() message(info$version) message(info$data_date) print(gh_bbox(info)) }
Get isochrones for a given start point
gh_get_isochrone(start_point, time_limit = 180, distance_limit = -1, ...)
gh_get_isochrone(start_point, time_limit = 180, distance_limit = -1, ...)
start_point |
The start point as (lat, lon) pair. |
time_limit |
The travel time limit in seconds.
Ignored if |
distance_limit |
The distance limit in meters. |
... |
Additonal parameters. See https://docs.graphhopper.com/#operation/getIsochrone. |
if (FALSE) { start_point <- c(52.53961, 13.36487) isochrone_sf <- gh_get_isochrone(start_point, time_limit = 180) %>% gh_as_sf() }
if (FALSE) { start_point <- c(52.53961, 13.36487) isochrone_sf <- gh_get_isochrone(start_point, time_limit = 180) %>% gh_as_sf() }
Get a route for a given set of points
gh_get_route(points, ..., response_only = FALSE)
gh_get_route(points, ..., response_only = FALSE)
points |
A list of 2 or more points as (lat, lon) pairs. |
... |
Optional parameters that are passed to the query. |
response_only |
Whether to return the raw response object instead of just its content. |
https://docs.graphhopper.com/#tag/Routing-API for optional parameters.
if (FALSE) { start_point <- c(52.592204, 13.414307) end_point <- c(52.539614, 13.364868) route_sf <- gh_get_route(list(start_point, end_point)) %>% gh_as_sf() }
if (FALSE) { start_point <- c(52.592204, 13.414307) end_point <- c(52.539614, 13.364868) route_sf <- gh_get_route(list(start_point, end_point)) %>% gh_as_sf() }
Internally it just calls gh_get_route sevaral times. See also gh_get_spt.
gh_get_routes(x, y, ..., callback = NULL)
gh_get_routes(x, y, ..., callback = NULL)
x |
A single start point as (lat, lon) pair |
y |
A matrix or a data frame containing columns with latitudes and longitudes that are used as endpoints. Needs (lat, lon) order. |
... |
Parameters that are passed to gh_get_route. |
callback |
A callback function that is applied to every calculated route. |
if (FALSE) { start_point <- c(52.519772, 13.392334) end_points <- rbind( c(52.564665, 13.42083), c(52.564456, 13.342724), c(52.489261, 13.324871), c(52.48738, 13.454647) ) time_distance_table <- gh_get_routes( start_point, end_points, calc_points = FALSE, callback = gh_time_distance ) %>% dplyr::bind_rows() routes_sf <- gh_get_routes(start_point, end_points, callback = gh_as_sf) %>% do.call(rbind, .) }
if (FALSE) { start_point <- c(52.519772, 13.392334) end_points <- rbind( c(52.564665, 13.42083), c(52.564456, 13.342724), c(52.489261, 13.324871), c(52.48738, 13.454647) ) time_distance_table <- gh_get_routes( start_point, end_points, calc_points = FALSE, callback = gh_time_distance ) %>% dplyr::bind_rows() routes_sf <- gh_get_routes(start_point, end_points, callback = gh_as_sf) %>% do.call(rbind, .) }
Get the shortest path tree for a given start point
gh_get_spt(start_point, time_limit = 600, distance_limit = -1, columns = gh_spt_columns(), reverse_flow = FALSE, profile = "car")
gh_get_spt(start_point, time_limit = 600, distance_limit = -1, columns = gh_spt_columns(), reverse_flow = FALSE, profile = "car")
start_point |
The start point as (lat, lon) pair. |
time_limit |
The travel time limit in seconds.
Ignored if |
distance_limit |
The distance limit in meters. |
columns |
The columns to be returned. See gh_spt_columns and gh_available_spt_columns for available columns. |
reverse_flow |
Use |
profile |
The profile for which the spt should be calculated. |
if (FALSE) { start_point <- c(52.53961, 13.36487) columns <- gh_spt_columns( prev_longitude = TRUE, prev_latitude = TRUE, prev_time = TRUE ) points_sf <- gh_get_spt(start_point, time_limit = 180, columns = columns) %>% gh_as_sf() }
if (FALSE) { start_point <- c(52.53961, 13.36487) columns <- gh_spt_columns( prev_longitude = TRUE, prev_latitude = TRUE, prev_time = TRUE ) points_sf <- gh_get_spt(start_point, time_limit = 180, columns = columns) %>% gh_as_sf() }
Extract the instructions from a gh route object
gh_instructions(data, instructions_only = FALSE)
gh_instructions(data, instructions_only = FALSE)
data |
A |
instructions_only |
Whether to return the instructions without the corresponding points. |
Extract the points from a gh route object
gh_points(data)
gh_points(data)
data |
A |
Set gh API base url
gh_set_api_url(api_url)
gh_set_api_url(api_url)
api_url |
API base url |
Internally it calls Sys.setenv
to store the API url
in an environment variable called GH_API_URL
.
gh_set_api_url("http://localhost:8989")
gh_set_api_url("http://localhost:8989")
Build lines from a gh spt object
gh_spt_as_linestrings_sf(data)
gh_spt_as_linestrings_sf(data)
data |
A |
if (FALSE) { start_point <- c(52.53961, 13.36487) columns <- gh_spt_columns( prev_longitude = TRUE, prev_latitude = TRUE, prev_time = TRUE ) lines_sf <- gh_get_spt(start_point, time_limit = 180, columns = columns) %>% gh_spt_as_linestrings_sf() }
if (FALSE) { start_point <- c(52.53961, 13.36487) columns <- gh_spt_columns( prev_longitude = TRUE, prev_latitude = TRUE, prev_time = TRUE ) lines_sf <- gh_get_spt(start_point, time_limit = 180, columns = columns) %>% gh_spt_as_linestrings_sf() }
Times are returned in milliseconds and distances in meters.
gh_spt_columns(longitude = TRUE, latitude = TRUE, time = TRUE, distance = TRUE, prev_longitude = FALSE, prev_latitude = FALSE, prev_time = FALSE, prev_distance = FALSE, node_id = FALSE, prev_node_id = FALSE, edge_id = FALSE, prev_edge_id = FALSE)
gh_spt_columns(longitude = TRUE, latitude = TRUE, time = TRUE, distance = TRUE, prev_longitude = FALSE, prev_latitude = FALSE, prev_time = FALSE, prev_distance = FALSE, node_id = FALSE, prev_node_id = FALSE, edge_id = FALSE, prev_edge_id = FALSE)
longitude , latitude
|
The longitude, latitude of the node. |
time , distance
|
The travel time, distance to the node. |
prev_longitude , prev_latitude
|
The longitude, latitude of the previous node. |
prev_time , prev_distance
|
The travel time, distance to the previous node. |
node_id , prev_node_id
|
The ID of the node, previous node. |
edge_id , prev_edge_id
|
The ID of the edge, previous edge. |
Extract time and distance from a gh route object
gh_time_distance(data)
gh_time_distance(data)
data |
A |