Learn R Programming

riverdist (version 0.17.0)

line2network: Create a River Network Object from a Shapefile

Description

Uses read_sf in package 'sf' to read a river shapefile, and establishes connectivity of segment endpoints based on spatial proximity.

Usage

line2network(
  sf = NULL,
  path = ".",
  layer = NA,
  tolerance = 100,
  reproject = NULL,
  autofix = TRUE
)

Value

Returns an object of class "rivernetwork" containing all spatial and topological information. See rivernetwork-class.

Arguments

sf

Optional input as an sf object, if shapefile has already been read into the R environment.

path

File path, default is the current working directory.

layer

Name of the shapefile, without the .shp extension.

tolerance

Snapping tolerance of segment endpoints to determine connectivity. Default is 100, therefore care should be exercised when working with larger units of distance, such as km.

reproject

A valid projection, if the shapefile is to be re-projected. Re-projection is done using st_transform in package 'sf'.

autofix

Whether to automatically apply two corrections: removal of duplicate segments, and segments with lengths shorter than the connectivity tolerance. Defaults to `TRUE`.

Author

Matt Tyers, Jemma Stachelek

Examples

Run this code
filepath <- system.file("extdata", package="riverdist")

Gulk_UTM5 <- line2network(path=filepath, layer="Gulk_UTM5")
plot(Gulk_UTM5)

## Reading directly from an sf object

sf <- sf::read_sf(dsn = filepath, layer = "Gulk_UTM5")
Gulk_UTM5 <- line2network(sf=sf)
plot(Gulk_UTM5)

## Re-projecting in Alaska Albers Equal Area projection:

AKalbers <- "+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 
    +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80"
    
Gulk_AKalbers <- line2network(path=filepath, layer="Gulk_UTM5", reproject=AKalbers)
plot(Gulk_AKalbers)

Run the code above in your browser using DataLab