Called internally within riverdistance. Detects the sequential route from one river network segment to another.

detectroute(start, end, rivers, verbose = FALSE, stopiferror = TRUE,
  algorithm = NULL)

Arguments

start

Segment number of the start of the route

end

Segment number of the end of the route

rivers

The river network object to use

verbose

Whether or not to print all routes being considered (used for error checking). Defaults to FALSE.

stopiferror

Whether or not to exit with an error if a route cannot be found. If this is set to FALSE and a route cannot be found, detectroute() will return NA. Defaults to TRUE.

algorithm

Which route detection algorithm to use. If set to NULL (the default), the function will automatically make a selection. Choices are:

  • Setting algorithm="sequential" will be quite slow, and may give inaccurate results in the event of braiding. This algorithm returns the first complete route detected, which may not be the shortest. This algorithm is not recommended in almost all cases, but is retained as an option for certain checks. It will not be used unless specified.

  • Setting algorithm="Dijkstra" will be much faster, and will return the shortest route in the event of braiding. If braiding is present or unknown, this will be the algorithm automatically chosen.

  • Setting algorithm="segroutes" will be the fastest of all, but will only return results in a non-braided network. This will be the algorithm automatically selected if segment routes are present - see buildsegroutes.

Value

A vector of segment numbers corresponding to the ordered route.

Examples

data(Gulk) plot(x=Gulk, cex=1)
detectroute(start=6, end=14, rivers=Gulk)
#> [1] 6 3 4 10 11 14
tstart <- Sys.time() detectroute(start=120, end=111, rivers=abstreams, algorithm="sequential")
#> [1] 120 103 106 109 112 116 124 132 134 133 135 142 153 152 144 136 127 115 114 #> [20] 107 108 111
tend <- Sys.time() tend - tstart
#> Time difference of 0.7406039 secs
data(abstreams) tstart <- Sys.time() detectroute(start=120, end=111, rivers=abstreams, algorithm="Dijkstra")
#> [1] 120 103 106 109 112 116 124 132 134 133 135 142 153 152 144 136 127 115 114 #> [20] 107 108 111
tend <- Sys.time() tend - tstart
#> Time difference of 0.003764868 secs
tstart <- Sys.time() detectroute(start=120, end=111, rivers=abstreams, algorithm="segroutes")
#> [1] 120 103 106 109 112 116 124 132 134 133 135 142 153 152 144 136 127 115 114 #> [20] 107 108 111
tend <- Sys.time() tend - tstart
#> Time difference of 0.001726627 secs