line2network: Create a River Network Object from a Shapefile

View source: R/riverdist_1.R

line2networkR Documentation

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
)

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'.

Value

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

Note

Since distance can only be calculated using projected coordinates, line2network() will generate an error if a non-projected input shapefile is detected. To resolve this, the shapefile can be re-projected in a GIS environment, or using reproject=, shown in the second example below.

Author(s)

Matt Tyers, Jemma Stachelek

Examples

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)


riverdist documentation built on Aug. 22, 2023, 5:06 p.m.