Unlimited learning, half price | 50% off
Get 50% off unlimited learning

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. segvert2xy() is its near-opposite, and extracts X-Y coordinates corresponding to vectors of segment and vertex.

  • 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. Differences in kernel density for specific surveys as compared to overall density can be plotted with densityanomaly().
  • 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.17.0

License

GPL-2

Maintainer

Matt Tyers

Last Published

October 15th, 2024

Functions in riverdist (0.17.0)

dissolve

Dissolve
cleanup_verts

Interactive Cleanup of the Vertices of Individual Segments
homerange

Home Range
kfunc

Plotting K-functions for a Set of Surveys
homerange-class

The "homerange" Class
line2network

Create a River Network Object from a Shapefile
highlightseg

Highlight Segments
connectsegs

Connect Segments
mouthdist

Distance From Mouth
mouthdistbysurvey

Distance From Mouth for All Observations of Individuals
fakefish_density

Dataset: Fakefish Density
pdisttot

Total Pythagorean Distance
plothomerangeoverlap

Plot Home Range Overlap
checkbraided

Check for Braiding in a River Network
pdist

Pythagorean Distance
plot.rivernetwork

Plotting a River Network
line98

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

Remove Duplicates
fakefish

Dataset: Fakefish
makeriverdensity

Calculate Kernel Density Using River Distance
plotmatbysurveylist

Plot Upstream Distance Between Observations of All Individuals
riverdistance

River Distance
removeunconnected

Remove Unconnected Segments
removemicrosegs

Remove Segments that are Smaller than the Connectivity Tolerance
riverdensity

The "riverdensity" Class
plotriverdensitypoints

Plot Points Used for Kernel Density
densityanomaly

Plot Difference from Mean Kernel Density Using River Distance
mapbyname

Map Segments by Name
riverdirectiontofrom

River Direction Matrix between Two Datasets
riverdist-package

River Network Distance Computation and Applications
detectroute

Detect Route
plotseq

Plot Sequence of Observations
matbysurveylist

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

Home Range Overlap
riverdistancelist

Multiple River Distances
rivernetwork

The "rivernetwork" Class
pointshp2segvert

Convert a Point Shapefile to River Locations
riverdirectionmatbysurvey

River Direction Matrix of All Observations of an Individual
setmouth

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

Store Vertices in Ascending Sequence
riverdirectionseq

River Travel Direction Between Sequential Observations
riverdirection

River Direction
riverpoints

Draw Points from River Locations
riverdirectionmat

River Direction Matrix
trimtopoints

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

Check Flow-Connectedness
plot.homerange

Plot Home Range
riverdistancetofrom

River Distance Matrix between Two Datasets
upstreamtofrom

Upstream Distance Matrix between Two Datasets
upstreamseq

Upstream Distance Between Sequential Observations
riverdistanceseq

River Distance Between Sequential Observations
whoconnected

Check Which Segments are Connected to a Given Segment.
smallset

Dataset: Smallset
splitsegmentat

Split a Segment at a Specified Vertex
showends

Identify Vertex Coordinates of Segment Endpoints
trimriver

Trim a River Network Object to Specified Segments
topologydots

Check Connectivity of a River Network Object
plot.riverdensity

Plot Kernel Density Using River Distance
riverdistancemat

River Distance Matrix
riverdistancematbysurvey

River Distance Matrix of All Observations of an Individual
upstream

Upstream River Distance
xy2segvert

Convert XY Coordinates to River Locations
segvert2xy

Convert River Locations to XY coordinates
upstreammat

Upstream Distance Matrix
routelist

Detect Multiple Routes
zoomtoseg

Zoom to segment
upstreammatbysurvey

Upstream Distance Matrix of All Observations of an Individual
splitsegments

Split Segments by Endpoint Proximity
KilleyW

Dataset: Killey River, West Channel
calculateconnections

Calculate the Connectivity Matrix for a River Network
buildlookup

Build Lookup Tables for Fast Distance Computation
checkbraidedTF

Check for Braiding in a River Network
addcumuldist

Add Cumulative Distance to a River Network
addverts

Add Vertices To Maintain a Minimum Distance Between Vertices
abstreams

Dataset: A-B Streams
Koyukuk2

Dataset: Koyukuk River 2
Kenai3

Dataset: Kenai River 3
Kenai1

Dataset: Kenai River 1
Gulk

Dataset: Gulkana River
Koyukuk1

Dataset: Koyukuk River 1
Koyukuk0

Dataset: Koyukuk River 0
abstreams0

Dataset: A-B Streams 0
Kenai2

Dataset: Kenai River 2
cleanup

Interactive Cleanup of a River Network
buildsegroutes

Build Segment Routes