get_risk | R Documentation |
Calculating Road Safety Risk
get_risk(crash_data, crash_weight, exposure, buffer = 10, crs = 2193)
crash_data |
An sf dataframe containing the geometry of the crash sites. Geometry requires a projected coordinate system. |
crash_weight |
A vector, the latitude coordinate of crash point. |
exposure |
An sf dataframe of the total distance travelled by the commuter within each polygon. The sf dataframe needs to contain 'total_dist' column, it is calculated in get_dist_travel() function. It is important that the sf dataframe includes a unique ID for each polygon that will be used to aggregate and calculate risk in total crashes per meters. Geometry requires a projected coordinate system. |
buffer |
Increasing the exposure polygon size. The default is 10 meters. The unit is dependent on the crash_data and exposure crs provided. |
crs |
Target coordinate reference system: object of class 'crs', or input string for st_crs, It uses sf::st_transform to change the crs. Refer to https://r-spatial.github.io/sf/reference/st_transform.html |
This function returns an sf dataframe with new column called risk, the total crashes in a given polygon divided by the total distance travelled in the said polygon.
## Not run: data(jtw_driving_akl) data(sa2_clipped_geo_akl) data(cas_data_akl_2018_proj) ## 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) ## getting the risk risk_proj <- get_risk(cas_data_akl_2018_proj, cas_data_akl_2018_proj$seriousInjuryCount + cas_data_akl_2018_proj$fatalCount, akl_dist_travel) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.