get_routes | R Documentation |
It is important that the router is initialised before using this function refer to https://www.rforge.net/doc/packages/ghroute/router.html for more details.
get_routes(matrix, crs = NULL)
matrix |
A 4 column matrix with the order start_latitude,start_longitude, end_latitude, end_longitude. Values in the matrix need to be numeric. |
crs |
Target coordinate reference system: object of class 'crs', or input string for st_crs. |
Below is an example of initialising the router, osm.file is a pbf file. The New Zealand pbf file can be located from here https://download.geofabrik.de/australia-oceania/new-zealand.html
router(osm.file, path = "graphhopper-cache", profiles = "car", open = TRUE, make.default = TRUE)
This function returns an sf dataframe with an sf geometry containing the simulated route as an sf linestring. It also includes the distance travelled in meters (m) and travel time in seconds.
## Not run: data(jtw_driving_akl) ## initialising the router for New Zealand ghroute::router(osm.file = "osm/new-zealand-latest.osm.pbf") ##getting the routes jtw_akl_routes <- get_routes(as.matrix(jtw_driving_akl[c("start_lat", "start_lon", "end_lat", "end_lon")])) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.