Skip to contents

The function shortest_path_cppRouting can be used to calculate the shortest path (either in minutes or meters) between two or more nodes in the Norwegian road network. The function also works with vectors with multiple from and to node ID’s. Before the function can be used, the road network must be converted to a cppRouting object that is called graph_cppRouting_minutes or graph_cppRouting_meters (or other with other names supplied to the graph_cppRouting_object argument). This can be done with the function vegnett_to_R().

Usage

shortest_path_cppRouting(
  from_node_ID,
  to_node_ID,
  unit = "minutes",
  dist = "all",
  graph_cppRouting_object = graph_cppRouting_minutes
)

Arguments

from_node_ID

Numeric vector with one or more from node ID’s.

to_node_ID

Numeric vector with one or more to node ID’s.

unit

Character vector with minutes to calculate the shortest path in minutes or meters for the shortest path in meters.

dist

Character vector that specifies if all the shortest paths between all the supplied from and to nodes are returned (all), or if only the minimum (min) or maximum (max) value for each from node ID is returned.

graph_cppRouting_object

The road network structured as a cppRouting graph object. This can be created with the function vegnett_to_R().

Value

Object (data.frame) with how many minutes or meters the shortest path is between the supplied from and to node ID’s.

Examples

shortest_path_cppRouting(from = 25,
                         to = 33,
                         unit = "minutes",
                         graph_cppRouting_object = graph_cppRouting_minutes_sampledata)
#>   from_nodeID to_nodeID  minutes
#> 1          25        33 0.607468

shortest_path_cppRouting(from = 25,
                         to = 33,
                         unit = "meters",
                         graph_cppRouting_object = graph_cppRouting_meters_sampledata)
#>   from_nodeID to_nodeID   meters
#> 1          25        33 346.7283

shortest_path_cppRouting(from = 25,
                         to = c(32, 33),
                         unit = "minutes",
                         dist = "min",
                         graph_cppRouting_object = graph_cppRouting_minutes_sampledata)
#> # A tibble: 1 x 3
#> # Groups:   from_nodeID [1]
#>   from_nodeID to_nodeID minutes
#>         <int>     <int>   <dbl>
#> 1          25        32   0.575