Weight (or re-weight) an sf or SC (silicate)-formatted OSM street network according to a named profile, selected from (foot, horse, wheelchair, bicycle, moped, motorcycle, motorcar, goods, hgv, psv).

weight_streetnet(x, wt_profile = "bicycle", wt_profile_file = NULL,
  turn_penalty = FALSE, type_col = "highway", id_col = "osm_id",
  keep_cols = NULL, left_side = FALSE)

# S3 method for default
weight_streetnet(x, wt_profile = "bicycle",
  wt_profile_file = NULL, turn_penalty = FALSE, type_col = "highway",
  id_col = "osm_id", keep_cols = NULL, left_side = FALSE)

# S3 method for sf
weight_streetnet(x, wt_profile = "bicycle",
  wt_profile_file = NULL, turn_penalty = FALSE, type_col = "highway",
  id_col = "osm_id", keep_cols = NULL, left_side = FALSE)

# S3 method for sc
weight_streetnet(x, wt_profile = "bicycle",
  wt_profile_file = NULL, turn_penalty = FALSE, type_col = "highway",
  id_col = "osm_id", keep_cols = NULL, left_side = FALSE)

Arguments

x

A street network represented either as sf LINESTRING objects, typically extracted with dodgr_streetnet, or as an SC (silicate) object typically extracted with the dodgr_streetnet_sc.

wt_profile

Name of weighting profile, or data.frame specifying custom values (see Details)

wt_profile_file

Name of locally-stored, .json-formatted version of dodgr::weighting_profiles, created with write_dodgr_wt_profile, and modified as desired.

turn_penalty

Including time penalty on edges for turning across oncoming traffic at intersections (see Note).

type_col

Specify column of the sf data.frame object which designates different types of highways to be used for weighting (default works with osmdata objects).

id_col

For sf-formatted data only: Specify column of the codesf data.frame object which provides unique identifiers for each highway (default works with osmdata objects).

keep_cols

Vectors of columns from x to be kept in the resultant dodgr network; vector can be either names or indices of desired columns.

left_side

Does traffic travel on the left side of the road (TRUE) or the right side (FALSE)? - only has effect on turn angle calculations for edge times.

Value

A data.frame of edges representing the street network, with distances in metres and times in seconds, along with a column of graph component numbers. Times for sf-formatted street networks are only approximate, and do not take into account traffic lights, turn angles, or elevation changes. Times for sc-formatted street networks take into account all of these factors, with elevation changes automatically taken into account for networks generated with the osmdata function osm_elevation().

Note

Names for the wt_profile parameter are taken from weighting_profiles, which is a list including a data.frame also called weighting_profiles of weights for different modes of transport. Values for wt_profile are taken from current modes included there, which are "bicycle", "foot", "goods", "hgv", "horse", "moped", "motorcar", "motorcycle", "psv", and "wheelchair". Railway routing can be implemented with the separate function weight_railway. Alternatively, the entire weighting_profile structures can be written to a local .json-formatted file with write_dodgr_wt_profile, the values edited as desired, and the name of this file passed as the wt_profile_file parameter. Construction of custom weighting profiles is illustrated in the following example.

Calculating edge times to account for turn angles (that is, with turn_penalty = TRUE) involves calculating the temporal delay involving in turning across oncoming traffic. Resultant graphs are fundamentally different from the default for distance-based routing. The result of weight_streetnet(..., turn_penalty = TRUE) should thus only be used to submit to the dodgr_times function, and not for any other dodgr functions nor forms of network analysis.

See also

Examples

# hampi is included with package as an 'osmdata' sf-formatted street network net <- weight_streetnet (hampi) class(net) # data.frame
#> [1] "data.frame" "dodgr_streetnet"
dim(net) # 6096 11; 6096 streets
#> [1] 5973 15
# os_roads_bristol is also included as an sf data.frame, but in a different # format requiring identification of columns and specification of custom # weighting scheme. colnm <- "formOfWay" wts <- data.frame (name = "custom", way = unique (os_roads_bristol [[colnm]]), value = c (0.1, 0.2, 0.8, 1)) net <- weight_streetnet (os_roads_bristol, wt_profile = wts, type_col = colnm, id_col = "identifier") dim (net) # 406 11; 406 streets
#> [1] 812 16
# An example for a generic (non-OSM) highway, represented as the # `routes_fast` object of the \pkg{stplanr} package, which is a # SpatialLinesDataFrame.
# NOT RUN { library (stplanr) # merge all of the 'routes_fast' lines into a single network r <- overline (routes_fast, attrib = "length", buff_dist = 1) r <- sf::st_as_sf (r) # We need to specify both a `type` and `id` column for the # \link{weight_streetnet} function. r$type <- 1 r$id <- seq (nrow (r)) graph <- weight_streetnet (r, type_col = "type", id_col = "id", wt_profile = 1) # }