Adds the travel routes from the mouth (lowest point) of a river network to each segment, and (optionally) distance lookup tables. This greatly reduces the time needed to detect routes, making distance calculation much more efficient, particularly in the case of multiple distance calculations.

buildsegroutes(rivers, lookup = NULL, verbose = FALSE)

Arguments

rivers

The river network object to use

lookup

Whether to build lookup tables as well. This may take some time, but will result in even faster distance computation in analyses (see buildlookup). Because of the object size returned, this may not be advisable in a large river network (more than a few hundred segments). Accepts TRUE or FALSE, and defaults to NULL. If the default value is accepted, lookup tables will be built if the river network has 400 segments or fewer.

verbose

Whether or not to print the segment number the function is currently building a route for (used for error checking). Defaults to FALSE.

Value

A rivernetwork object, with a new list element, $segroutes, which gives the route from the mouth to each rivernetwork segment. Optionally, it may add $distlookup, distance lookup tables for even faster distance computation. (See rivernetwork.)

Note

In the event of braiding (multiple channels), it is likely that there will be differences in the routes detected. If this is the case, building routes will likely result in a shorter and more efficient route. Regardless, extreme caution is always advised in the event of braiding.

The mouth segment and vertex must be specified (see setmouth).

This function is called within cleanup, which is recommended in most cases.

Examples

data(abstreams) plot(x=abstreams)
abstreams1 <- abstreams abstreams1$segroutes <- NULL #taking out the $segroutes component # before tstart <- Sys.time() detectroute(start=120, end=111, rivers=abstreams1)
#> [1] 120 103 106 109 112 116 124 132 134 133 135 142 153 152 144 136 127 115 114 #> [20] 107 108 111
Sys.time() - tstart
#> Time difference of 0.01074767 secs
# after tstart <- Sys.time() detectroute(start=120, end=111, rivers=abstreams)
#> [1] 120 103 106 109 112 116 124 132 134 133 135 142 153 152 144 136 127 115 114 #> [20] 107 108 111
Sys.time() - tstart
#> Time difference of 0.004034281 secs