View source: R/get_dist_travelled.R
get_dist_travel | R Documentation |
Getting the distance travelled by a commuter
get_dist_travel(polygon, routes, weight = NULL)
polygon |
The polygon we are trying to intersect with the routes. It is an sf dataframe where the geometry is either an sfc POLYGON or sfc MULTIPOLYGON. It is important that the sf dataframe includes a unique ID for each polygon that will be used to aggregate and calculate the total distance travelled. |
routes |
The routes travelled by the commuter with the associated weight or number of travellers. This is an sf dataframe where the geometry a sfc LINESTRING. |
weight |
The weight for each line segment or route. This is optional. |
This function returns an sf dataframe of the total distance travelled by the commuter within each polygon.
## Not run: data(jtw_driving_akl) data(sa2_clipped_geo_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")])) ##transforming routes from lat/lon to projected crs jtw_driving_akl_with_routes_proj <- sf::st_transform(jtw_driving_akl_with_routes, crs = 2193) sa2_clipped_proj_akl <- sf::st_transform(sa2_clipped_geo_akl, crs = 2193) ## getting distance travelled per SA2 polygon akl_dist_travel <- get_dist_travel(sa2_clipped_proj_akl, jtw_driving_akl_with_routes_proj, weight = jtw_driving_akl_with_routes_proj$total_driving) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.