arcgisrouting brings the ArcGIS Routing REST API to R. Plan routes, measure travel time and distance, build service areas, route fleets of vehicles, and snap GPS tracks to roads, all returning sf objects ready for analysis and mapping.
It is part of the R-ArcGIS Bridge.
[!IMPORTANT]
Using
arcgisroutingrequires an ArcGIS Online account, an ArcGIS Location Platform account, or an ArcGIS Enterprise server. Routing operations consume ArcGIS credits. For pricing, see the ArcGIS Routing pricing details.
Installation
Install the development version from GitHub:
# install.packages("pak")
pak::pak("r-arcgis/arcgisrouting")Authentication
Every request is authorized with an ArcGIS token. Authenticate once per session with arcgisutils and the package will pick the token up automatically.
See the R-ArcGIS Bridge authentication guide for client credentials, API keys, and other workflows.
Quick start
Find the best route between an ordered set of stops:
library(sf)
library(arcgisutils)
library(arcgisrouting)
set_arc_token(auth_user())
stops <- st_sf(
name = c("Ferry Building", "Coit Tower", "Painted Ladies"),
geometry = st_sfc(
st_point(c(-122.3933, 37.7955)),
st_point(c(-122.4058, 37.8024)),
st_point(c(-122.4329, 37.7762)),
crs = 4326
)
)
route <- find_routes(stops)
route$routesWhat you can do
| Capability | Direct Requests | Asynchronous Geoprocessing Job |
|---|---|---|
| Routing and directions | find_routes() |
find_routes_job() |
| Service areas | find_service_areas() |
find_service_areas_job() |
| Closest facility | find_closest_facilities() |
find_closest_facilities_job() |
| Origin-destination cost matrix | od_cost_matrix() |
od_cost_matrix_job() |
| Vehicle routing problem | route_vehicles() |
route_vehicles_job() |
| Last mile delivery | last_mile_delivery() |
|
| Location-allocation | location_allocation_job() |
|
| Snap GPS points to roads | snap_to_roads() |
The direct request functions return immediately and are best for interactive work and modest inputs. The asynchronous geoprocessing job functions queue a job on the server, which is ideal for large problems.
Working with a job looks like this:
job <- find_routes_job(stops)
job$start() # submit the job to the server
job$await() # poll until the job completes
job$messages() # retrieve the geoprocessing job messages
job$results # read the results once the job has finishedDiscover the travel modes available to your organization with get_travel_modes().
Endpoint coverage
ArcGIS Online and Enterprise
This package is built and tested against ArcGIS Online. It may not yet work with ArcGIS Enterprise. If you run into trouble using arcgisrouting with Enterprise, please open an issue or, if you would rather reach us privately, email r_bridge@esri.com.
