
Stream Distances to Matrix
fwa_stream_distances_to_matrix.RdCalculates the distances along the stream network between stream distances
(river meters).
The distance is Inf if the river meters are on streams that are not
connected.
Arguments
- x
A data frame (including sf objects) with whole numeric column blk and numeric column rm of the river meters. All blk values must be in
streams$blkand all rm values must be non-negative.- streams
A data frame with whole numeric column blk, whole numeric column parent_blk and numeric column parent_rm. The stream network must not be circular.
- id
A string of the name of a column in
xwith unique non-missing values that are converted to character and used as the row and column names of the matrix orNULL.
Details
The stream network is defined by the parent blue line key (parent_blk)
and the river meter on the parent where each stream joins it (parent_rm)
as returned by fwa_add_parent_to_streams().
Parents that are not in streams$blk are treated as root streams.
Examples
streams <- data.frame(
blk = c(1, 2, 3),
parent_blk = c(NA, 1, NA),
parent_rm = c(NA, 400, NA)
)
rms <- data.frame(
site = c("a", "b", "c", "d"),
blk = c(1, 1, 2, 3),
rm = c(100, 500, 50, 10)
)
fwa_stream_distances_to_matrix(rms, streams)
#> [,1] [,2] [,3] [,4]
#> [1,] 0 400 350 Inf
#> [2,] 400 0 150 Inf
#> [3,] 350 150 0 Inf
#> [4,] Inf Inf Inf 0
fwa_stream_distances_to_matrix(rms, streams, id = "site")
#> a b c d
#> a 0 400 350 Inf
#> b 400 0 150 Inf
#> c 350 150 0 Inf
#> d Inf Inf Inf 0