Skip to contents

This function transforms a spatial network object into an 'sfnetwork', scoring it based on road conditions and classifications. The transformation process includes casting the network to LINESTRING, converting it to 'sfnetwork', and adding attributes like 'arterialness' and 'weight' which are calculated based on the given road scores and the importance of the roads in the network.

Usage

prepare_network(
  network,
  key_attribute = "all_fastest_bicycle_go_dutch",
  road_scores = list(`A Road` = 1, `B Road` = 2, `Minor Road` = 1e+05),
  penalty_value = 1,
  transform_crs = 27700
)

Arguments

network

An 'sf' object representing a spatial network.

key_attribute

The attribute name from the network used for normalization and scoring, default is "all_fastest_bicycle_go_dutch".

road_scores

A list specifying scores for different road types. Example: list("A Road" = 1, "B Road" = 1, "Minor Road" = 10000000).

penalty_value

The penalty value for roads with low values, default is 1.

transform_crs

The numeric CRS code for coordinate transformation, default is 27700.

Value

An 'sfnetwork' object with attributes 'arterialness' and 'weight' that account for road conditions and their relative importance.

Examples

library(sf)
library(sfnetworks)
library(dplyr)
library(purrr)
library(zonebuilder)

# Load demo data 
os_edinburgh_demo_3km = sf::st_set_crs(os_edinburgh_demo_3km, 27700)
NPT_demo_3km = sf::st_set_crs(NPT_demo_3km, 27700)
base_network = sf::st_transform(os_edinburgh_demo_3km, crs = 27700)
influence_network = sf::st_transform(NPT_demo_3km, crs = 27700)
target_zone = zonebuilder::zb_zone("Edinburgh", n_circles = 2) |>
               sf::st_transform(crs = "EPSG:27700")

# Prepare the cohesive network
network = cohesive_network_prep(base_network = base_network, 
                                influence_network = influence_network, 
                                target_zone = target_zone, 
                                key_attribute = "road_function", 
                                attribute_values = c("A Road", "B Road", "Minor Road"))
#> Requested number of segments (45185) does not match the number of segments returned by rsgeo (44530).
#> Warning: st_centroid assumes attributes are constant over geometries
#> Joining with `by = join_by(road_function)`
#> [1] "Finished preparing the network data"

# Define road scores
road_scores = list("A Road" = 1, "B Road" = 1, "Minor Road" = 100000)

# Prepare the network
prepared_network = prepare_network(network, 
                                    key_attribute = "all_fastest_bicycle_go_dutch",
                                    road_scores = road_scores,
                                    transform_crs = 27700, penalty_value = 1)

# Print the prepared network
print(prepared_network)
#> # A sfnetwork with 1124 nodes and 1237 edges
#> #
#> # CRS:  EPSG:27700 
#> #
#> # An undirected multigraph with 1 component with spatially explicit edges
#> #
#> # A tibble: 1,237 × 12
#>    from    to road_function all_fastest_bicycle_go_dutch length_x
#>   <int> <int> <chr>                                <int>    <int>
#> 1     1     2 A Road                             1461109        0
#> 2     3     4 Minor Road                             919      321
#> 3     5     6 A Road                                8153       34
#> 4     7     8 A Road                                5646       49
#> 5     9    10 A Road                               10654       26
#> 6    11    12 Minor Road                            8756       33
#> # ℹ 1,231 more rows
#> # ℹ 7 more variables: geom <LINESTRING [m]>, value <dbl>, max_value <dbl>,
#> #   arterialness <dbl>, road_score <dbl>, weight <dbl>, penalty <dbl>
#> #
#> # A tibble: 1,124 × 1
#>                  geom
#>           <POINT [m]>
#> 1 (324910.8 672963.1)
#> 2 (324910.7 672963.3)
#> 3     (327256 672497)
#> # ℹ 1,121 more rows