Calculates river network distances as +/-, defined as upriver/downriver.

Specifying net=TRUE will compute net upriver distance (3 river km down a tributary and then 15 river km up the mainstem will mean 12 rkm net. Otherwise the function will return 18 rkm upriver travel.)

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

upstream(startseg, endseg, startvert, endvert, rivers, flowconnected = FALSE,
  net = FALSE, stopiferror = TRUE, algorithm = NULL)

Arguments

startseg

Segment number of the start of the route

endseg

Segment number of the end of the route

startvert

Vertex number of the start of the route

endvert

Vertex number of the end of the route

rivers

The river network object to use

flowconnected

If TRUE, only returns distance if the two input segments are flow-connected. Defaults to FALSE.

net

Whether to calculate net distance (net=TRUE) or total distance (net=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, the function will return NA in the appropriate entry. Defaults to TRUE. See detectroute.

algorithm

Which route detection algorithm to use ("Dijkstra", "sequential", or "segroutes"). If left as NULL (the default), the function will automatically make a selection. See detectroute for more details.

Value

Upstream distance (numeric). Returns NA if flowconnected has value TRUE and the two segments are not flow-connected.

Note

Building routes from the river mouth to each river network segment and/or distance lookup tables will greatly reduce computation time (see buildsegroutes).

See also

setmouth

Examples

data(Gulk) # Mouth must be specified Gulk$mouth$mouth.seg <- 1 Gulk$mouth$mouth.vert <- 1 plot(x=Gulk)
riverpoints(seg=c(6,4), vert=c(140,140), pch=16, col=2, rivers=Gulk)
upstream(startseg=6, endseg=4, startvert=140, endvert=40, rivers=Gulk, net=TRUE)
#> [1] -35553.56
upstream(startseg=6, endseg=4, startvert=140, endvert=40, rivers=Gulk, net=FALSE)
#> [1] -41878.12
upstream(startseg=6, endseg=4, startvert=140, endvert=40, rivers=Gulk, flowconnected=TRUE)
#> [1] NA