get_risk: Calculating Road Safety Risk

View source: R/get_risk.R

get_riskR Documentation

Calculating Road Safety Risk

Description

Calculating Road Safety Risk

Usage

get_risk(crash_data, crash_weight, exposure, buffer = 10, crs = 2193)

Arguments

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

Value

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.

Examples

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

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