Learn R Programming

⚠️There's a newer version (0.17.0) of this package.Take me there.

riverdist

River Network Distance Computation and Applications

The 'riverdist' package is intended as a free and readily-available resource for distance calculation along a river network. This package was written with fisheries research in mind, but could be applied to other fields. The 'riverdist' package builds upon the functionality of the 'sf' package, which provide the utility of reading GIS shapefiles into the R environment. What 'riverdist' adds is the ability to treat a linear feature as a connected network, and to calculate travel routes and travel distances along that network.

Note that the current version of 'riverdist' (>= 0.16.0) is no longer built on 'sp' and 'rgdal' and is not backward-compatible. A legacy version that uses 'sp' / 'rgdal' ('riverdist' 0.15.5) can be installed via

remove.package("riverdist") if needed devtools::install_github("mbtyers/riverdist@legacy")

Commonly-used functions

  • line2network() imports a river shapefile, and calculates topologies to create a connected river network.

  • cleanup() calls a sequence of editing functions on the resulting river network to facilitate performance. The editing functions are also available by themselves.

  • plot() when used with a river network object produces a simple map of the network, with segments labeled and differentiated by color or line type.

  • xy2segvert() converts a set of X-Y coordinates to river network coordinates by "snapping" each point to the nearest river vertex. pointshp2segvert() does the same, with the input being a point shapefile.

  • riverdistance(), riverdirection(), and upstream() return the network distance, the travel direction (upstream or downstream), and the directional (upstream) distance between two river locations, respectively. Options are included for different handling of locations that are flow-connected or flow-separate, as well as net directional distance when locations are flow-separate.

Several automated analyses are built in. In most cases, there is a direction or directional distance equivalent.

  • homerange() returns the minimum observed home range for each individual in a data set.
  • riverdistanceseq() and riverdistanceseqbysurvey() return different forms of matrices of pairwise network distances between observations of each individual in a dataset.
  • riverdistancemat() returns a matrix of network distances between all observations in a dataset.
  • riverdistancetofrom() returns a matrix of network distances between two datasets.
  • mouthdistbysurvey() returns a matrix of distances between each observation and the mouth of the river network, with rows corresponding to unique individual, and columns corresponding to unique survey.

Summaries and plots are also available at the dataset level, in addition to individuals, which is likely to be much more useful to analysis.

  • makeriverdensity() calculates a kernel density object which can be plotted with plot() to create a kernel density map. Depending on the usage of makeriverdensity(), this may be a sequence of maps.
  • kfunc() provides plotting of empirical k-functions for each survey event, giving evidence of clustering or dispersal behavior.
  • plotseq() produces a plot of a distance sequence such as that returned from mouthdistbysurvey() providing plots of overall distance or upriver position for each survey event.
  • matbysurveylist() produces a list of matrices of distances or upstream distances between all survey events, for each individual. This can be plotted using plotmatbysurveylist(), creating a summary plot for all individuals.

Installation

Version 0.16.0 of the 'riverdist' package is available on CRAN.

The development version is currently available on Github, and can be installed in R with the following code:

devtools::install_github("mbtyers/riverdist")

Copy Link

Version

Install

install.packages('riverdist')

Monthly Downloads

749

Version

0.16.3

License

GPL-2

Maintainer

Matt Tyers

Last Published

January 11th, 2024

Functions in riverdist (0.16.3)

abstreams0

Dataset: A-B Streams 0
Kenai3

Dataset: Kenai River 3
homerange-class

The "homerange" Class
mapbyname

Map Segments by Name
highlightseg

Highlight Segments
checkbraided

Check for Braiding in a River Network
calculateconnections

Calculate the Connectivity Matrix for a River Network
makeriverdensity

Calculate Kernel Density Using River Distance
Kenai1

Dataset: Kenai River 1
pointshp2segvert

Convert a Point Shapefile to River Locations
buildsegroutes

Build Segment Routes
matbysurveylist

Generate List of Distance Matrix Between Observations, for All Individuals
buildlookup

Build Lookup Tables for Fast Distance Computation
removeduplicates

Remove Duplicates
checkbraidedTF

Check for Braiding in a River Network
plotmatbysurveylist

Plot Upstream Distance Between Observations of All Individuals
plothomerangeoverlap

Plot Home Range Overlap
mouthdist

Distance From Mouth
detectroute

Detect Route
mouthdistbysurvey

Distance From Mouth for All Observations of Individuals
dissolve

Dissolve
riverdist-package

River Network Distance Computation and Applications
pdist

Pythagorean Distance
riverdistance

River Distance
cleanup

Interactive Cleanup of a River Network
riverdensity

The "riverdensity" Class
riverdistancemat

River Distance Matrix
upstreammat

Upstream Distance Matrix
riverdistancelist

Multiple River Distances
upstreammatbysurvey

Upstream Distance Matrix of All Observations of an Individual
line98

Dataset: Line 98 of Kenai River 1 (Long-Lat)
plotriverdensitypoints

Plot Points Used for Kernel Density
cleanup_verts

Interactive Cleanup of the Vertices of Individual Segments
line2network

Create a River Network Object from a Shapefile
connectsegs

Connect Segments
addcumuldist

Add Cumulative Distance to a River Network
kfunc

Plotting K-functions for a Set of Surveys
fakefish

Dataset: Fakefish
fakefish_density

Dataset: Fakefish Density
isflowconnected

Check Flow-Connectedness
addverts

Add Vertices To Maintain a Minimum Distance Between Vertices
homerangeoverlap

Home Range Overlap
pdisttot

Total Pythagorean Distance
homerange

Home Range
removemicrosegs

Remove Segments that are Smaller than the Connectivity Tolerance
riverdirection

River Direction
plot.riverdensity

Plot Kernel Density Using River Distance
plot.homerange

Plot Home Range
plotseq

Plot Sequence of Observations
riverdistancetofrom

River Distance Matrix between Two Datasets
rivernetwork

The "rivernetwork" Class
splitsegmentat

Split a Segment at a Specified Vertex
xy2segvert

Convert XY Coordinates to River Locations
splitsegments

Split Segments by Endpoint Proximity
whoconnected

Check Which Segments are Connected to a Given Segment.
plot.rivernetwork

Plotting a River Network
riverdistancematbysurvey

River Distance Matrix of All Observations of an Individual
trimtopoints

Trim a River Network to a Set of X-Y Coordinates
removeunconnected

Remove Unconnected Segments
riverdistanceseq

River Distance Between Sequential Observations
riverdirectionmat

River Direction Matrix
riverdirectionmatbysurvey

River Direction Matrix of All Observations of an Individual
riverdirectionseq

River Travel Direction Between Sequential Observations
upstream

Upstream River Distance
routelist

Detect Multiple Routes
riverpoints

Draw Points from River Locations
riverdirectiontofrom

River Direction Matrix between Two Datasets
sequenceverts

Store Vertices in Ascending Sequence
upstreamtofrom

Upstream Distance Matrix between Two Datasets
showends

Identify Vertex Coordinates of Segment Endpoints
topologydots

Check Connectivity of a River Network Object
upstreamseq

Upstream Distance Between Sequential Observations
smallset

Dataset: Smallset
setmouth

Specify the Segment and Vertex of the Mouth of a River Network Object.
zoomtoseg

Zoom to segment
trimriver

Trim a River Network Object to Specified Segments
abstreams

Dataset: A-B Streams
Koyukuk1

Dataset: Koyukuk River 1
Gulk

Dataset: Gulkana River
Koyukuk0

Dataset: Koyukuk River 0
KilleyW

Dataset: Killey River, West Channel
Koyukuk2

Dataset: Koyukuk River 2
Kenai2

Dataset: Kenai River 2