Learn R Programming

stplanr (version 0.1.4)

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 = graphhopper_pat())

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 - this is usually aquired automatically through a helper function

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 https://cran.r-project.org/web/packages/httr/vignettes/api-packages.html 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("Leeds", "Dublin", vehicle = "bike")
# r2 <- route_graphhopper("New York", "Washington", vehicle = "foot")
# library(leaflet)
# 
# leaflet() %>% addTiles() %>% addPolylines(data = r)
# ## End(Not run)

Run the code above in your browser using DataLab