get_routes: Getting the routes of multiple pairs of geographic coordinate...

View source: R/get_routes.R

get_routesR Documentation

Getting the routes of multiple pairs of geographic coordinate systems (lat/lon) coordinates.

Description

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.

Usage

get_routes(matrix, crs = NULL)

Arguments

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.

Details

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)

Value

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.

Examples

## 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)

kathycong/motroadsafety documentation built on June 23, 2022, 8:56 a.m.