stplanr (version 0.2.2)

route_graphhopper: Plan a route with the graphhopper routing engine

Description

Provides an R interface to the graphhopper routing engine, an open source route planning service.

Usage

route_graphhopper(from, to, vehicle = "bike", silent = TRUE, pat = NULL,
  base_url = "https://graphhopper.com")

Arguments

from

Text string or coordinates (a numeric vector of length = 2 representing latitude and longitude) representing a point on Earth.

to

Text string or coordinates (a numeric vector of length = 2 representing latitude and longitude) representing a point on Earth. This represents the destination of the trip.

vehicle

A text string representing the vehicle. Can be bike, bike2, car or foot.

silent

Logical (default is FALSE). TRUE hides request sent.

pat

The API key used. By default this is set to NULL and this is usually aquired automatically through a helper, api_pat().

base_url

The base url from which to construct API requests (with default set to main server)

Details

The function returns a SpatialLinesDataFrame object. See https://github.com/graphhopper for more information.

To test graphopper is working for you, try something like this, but with your own API key: To use this function you will need to obtain an API key from https://graphhopper.com/#directions-api. It is assumed that you have set your api key as a system environment for security reasons (so you avoid typing the API key in your code). Do this by adding the following to your .Renviron file (see ?.Renviron or the 'api-packages' vignette at https://cran.r-project.org/package=httr for more on this):

GRAPHHOPPER='FALSE-Key-eccbf612-214e-437d-8b73-06bdf9e6877d'.

(Note: key not real, use your own key.)

obj <- jsonlite::fromJSON(url)

Where url is an example api request from https://github.com/graphhopper/directions-api/blob/master/routing.md.

See Also

route_cyclestreet

Examples

Run this code
# NOT RUN {
r <- route_graphhopper(from = "Leeds, UK", to = "Dublin, Ireland", vehicle = "bike")
r@data
plot(r)
r <- route_graphhopper("New York", "Washington", vehicle = "foot")
plot(r)
# }

Run the code above in your browser using DataLab