All Projects → crazycapivara → graphhopper-r

crazycapivara / graphhopper-r

Licence: other
An R Interface to the graphhopper API

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to graphhopper-r

Ffrouter
Powerful and easy-to-use URL routing library in iOS that supports URL Rewrite(强大、易用、支持 URL Rewrite的 iOS 路由库)
Stars: ✭ 263 (+1543.75%)
Mutual labels:  routing-engine
Lua Resty Route
URL Routing Library for OpenResty Supporting Pluggable Matching Engines
Stars: ✭ 88 (+450%)
Mutual labels:  routing-engine
Routing
Routing component building on the Symfony Routing component
Stars: ✭ 253 (+1481.25%)
Mutual labels:  routing-engine
Graphhopper
Open source routing engine for OpenStreetMap. Use it as Java library or standalone web server.
Stars: ✭ 3,457 (+21506.25%)
Mutual labels:  routing-engine
Openrouteservice
🌍 The open source route planner api with plenty of features.
Stars: ✭ 614 (+3737.5%)
Mutual labels:  routing-engine
Node Osrm
DEPRECATED Part of osrm-backend since 5.7. NodeJS bindings for OSRM
Stars: ✭ 133 (+731.25%)
Mutual labels:  routing-engine
Offroad-routing-engine
Off-road Navigation System
Stars: ✭ 16 (+0%)
Mutual labels:  routing-engine
geostan
Bayesian spatial analysis
Stars: ✭ 40 (+150%)
Mutual labels:  rspatial
Jlroutes
URL routing library for iOS with a simple block-based API
Stars: ✭ 5,528 (+34450%)
Mutual labels:  routing-engine
Router
Router implementation for fasthttp
Stars: ✭ 234 (+1362.5%)
Mutual labels:  routing-engine
Freerouting
Advanced PCB autorouter (finally, no Java installation required)
Stars: ✭ 307 (+1818.75%)
Mutual labels:  routing-engine
Osrm Backend
Open Source Routing Machine - C++ backend
Stars: ✭ 4,716 (+29375%)
Mutual labels:  routing-engine
Routing
The routing core of itinero.
Stars: ✭ 145 (+806.25%)
Mutual labels:  routing-engine
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (+1643.75%)
Mutual labels:  routing-engine
geodaData
Data package for accessing GeoDa datasets using R
Stars: ✭ 15 (-6.25%)
Mutual labels:  rspatial
motis
Intermodal Mobility Information System
Stars: ✭ 45 (+181.25%)
Mutual labels:  routing-engine
Valhalla
Open Source Routing Engine for OpenStreetMap
Stars: ✭ 1,794 (+11112.5%)
Mutual labels:  routing-engine
tmap-book
A book on elegant and informative maps with the tmap package
Stars: ✭ 23 (+43.75%)
Mutual labels:  rspatial
openrouteservice-js
📌 The JavaScript API to consume openrouteservice(s) painlessly!
Stars: ✭ 138 (+762.5%)
Mutual labels:  routing-engine
Openrouteservice Py
🐍 The Python API to consume openrouteservice(s) painlessly!
Stars: ✭ 168 (+950%)
Mutual labels:  routing-engine

graphhopper-R

CRAN status github_status_badge Travis build status Project Status: Active – The project has reached a stable, usable state and is being actively developed. R build status

An R Interface to the GraphHopper Directions API

The purpose of {graphhopper} is to provide a quick and easy access to the GraphHopper Directions API. Responses can be converted into simple feature (sf) objects in a convenient way. The package is not a complete wrapper of the API. Currently it mainly supports the API also included in GraphHopper’s Open Source Routing Engine. New features will be added continuously.

Dive into the documentation here.

Installation

Install the release version from CRAN with:

install.packages("graphhopper")

Install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("crazycapivara/graphhopper-r")

Get started

Run your own GraphHopper instance (with data of Berlin):

docker run --name gh --rm -p 8989:8989 -d graphhopper/graphhopper:2.0

Setup

library(graphhopper)

API_URL <- "http://localhost:8989"
# API_URL <- "https://graphhopper.com/api/1/"
gh_set_api_url(API_URL)

info <- gh_get_info()

info$version
#> [1] "2.0"
info$data_date
#> [1] "2020-12-04T21:42:03Z"
gh_bbox(info)
#> [1] 13.06979 52.33306 13.76352 52.67962

If you use the GraphHopper Web Service instead of a local instance it is recommended that you store your API key in an environment variable called GH_API_KEY. Alternatively, you can pass the key as parameter to the gh_get_* functions.

Route

Get a route in Berlin:

start_point <- c(52.592204, 13.414307)
end_point <- c(52.539614, 13.364868)

(route <- gh_get_route(list(start_point, end_point)) %>%
    gh_as_sf())
#> Simple feature collection with 1 feature and 2 fields
#> geometry type:  LINESTRING
#> dimension:      XY
#> bbox:           xmin: 13.36501 ymin: 52.53949 xmax: 13.41483 ymax: 52.59234
#> CRS:            EPSG:4326
#>     time distance                       geometry
#> 1 697420 7541.438 LINESTRING (13.41422 52.592...

ggplot(data = route) +
  geom_sf() +
  theme(axis.text.x = element_text(angle = 45))

route$time
#> [1] 697420

via_point <- c(52.545461, 13.435249)

route2 <- gh_get_route(list(start_point, via_point, end_point))

gh_time_distance(route2)
#> $time
#> [1] 1168950
#> 
#> $distance
#> [1] 12843.67

ggplot(data = gh_as_sf(route2)) +
  geom_sf() +
  theme(axis.text.x = element_text(angle = 45))

gh_points(route2) %>%
  head()
#>        lon      lat gh_id
#> 1 13.41422 52.59234     0
#> 2 13.41321 52.59212     1
#> 3 13.41483 52.58964     2
#> 4 13.41539 52.59004     3
#> 5 13.41599 52.59032     4
#> 6 13.41942 52.59145     5

gh_instructions(route2)[, c("lon", "lat", "gh_id", "gh_end_id", "text", "distance")] %>%
  head()
#>        lon      lat gh_id gh_end_id                                   text
#> 1 13.41422 52.59234     0         1        Continue onto Buchholzer Straße
#> 2 13.41321 52.59212     1         2       Turn left onto Buchholzer Straße
#> 3 13.41483 52.58964     2         5 Turn sharp left onto Buchholzer Straße
#> 4 13.41942 52.59145     5         8         Turn right onto Grumbkowstraße
#> 5 13.42352 52.58588     8        15    Turn left onto Blankenburger Straße
#> 6 13.43019 52.58851    15        18      Turn right onto Pasewalker Straße
#>   distance
#> 1   72.248
#> 2  296.761
#> 3  373.025
#> 4  678.120
#> 5  556.120
#> 6  619.849

Shortest path tree

start_point <- c(52.53961, 13.36487)

points_sf <- gh_get_spt(start_point, time_limit = 180) %>%
  gh_as_sf() %>%
  dplyr::mutate(time = (time / 1000 / 60))

ggplot() +
  geom_sf(data = points_sf, aes(colour = time), size = 0.5) +
  theme(axis.text.x = element_text(angle = 45))

Also query previous nodes to plot the network:

(columns <- gh_spt_columns(
  prev_longitude = TRUE,
  prev_latitude = TRUE,
  prev_time = TRUE
))
#> [1] "longitude"      "latitude"       "time"           "distance"      
#> [5] "prev_longitude" "prev_latitude"  "prev_time"

lines_sf <- gh_get_spt(end_point, time_limit = 240, columns = columns) %>%
  dplyr::mutate(mean_time = ((time + prev_time) / 2) / 1000 / 60) %>%
  gh_spt_as_linestrings_sf()

ggplot() +
  geom_sf(data = lines_sf, aes(color = mean_time), size = 1) +
  theme(axis.text.x = element_text(angle = 45))

Isochrone

start_point <- c(52.53961, 13.36487)

isochrone_sf <- gh_get_isochrone(start_point, time_limit = 180) %>%
  gh_as_sf()

ggplot() +
  geom_sf(data = isochrone_sf, fill = "yellow") +
  geom_sf(data = points_sf, aes(colour = time), size = 0.5) +
  theme(axis.text.x = element_text(angle = 45))

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].