openSTARS (version 1.0.0)

calc_sites: Calculate sites for SSN object.

Description

A vector (points) map 'sites' is derived and several attributes are assigned.

Usage

calc_sites(locid_col = NULL, pid_col = NULL, pred_sites = NULL)

Arguments

locid_col

character (optional); column name in the sites attribute table giving a unique site identifier. If not provided, it is created automatically (based on the 'cat' field; default).

pid_col

character (optional); column name in the sites attribute table that distinguishes between repeated measurements at a sampling site, e.g. by date. If not provided, it is created automatically.

pred_sites

character vector (optional); names for prediction sites (created with import_data).

Details

Steps include:

  • Snap points to derived network. 'dist' gives the distance of the original position to the closest streams segment.

  • Assign unique 'pid' and 'locID'.

  • Get 'rid' and 'netID' of the stream segment the site intersects with (from map "edges").

  • Calculate upstream distance for each point ('upDist').

  • Calculate distance ratio ('ratio') between position of site on edge (distance traveled from lower end of the edge to the site) and the total length of the edge.

Often, survey sites do not lay exactly on the stream network (due to GPS imprecision, stream representation as lines, derivation of streams from dem, etc.). To assign an exact position of the sites on the network they are moved to the closest stream segment (snapped) using v.distance.

If locid_col and pid_col are not provided, 'pid' and 'locID' are identical, unique numbers. If they are provided, they are created based on these columns (as numbers, not as text). Note that repeated measurements can be joined to the sites at a later step. Then, 'pid' needs to be updated accordingly (NOT YET IMPLEMENTED).

'upDist' is calculated using v.distance with upload = "to_along" which gives the distance along the stream segment to the next upstream node ('distalong'). 'upDist' is the difference between the 'upDist' of the edge the point lies on and 'distalong'.

If prediction sites have been created outside of this package they can be processed here as well. They must have been imported with import_data before. Alternatively, prediction sites can be created using calc_prediction_sites.

Examples

Run this code
# NOT RUN {
# Initiate GRASS session
if(.Platform$OS.type == "windows"){
  gisbase = "c:/Program Files/GRASS GIS 7.2.0"
  } else {
  gisbase = "/usr/lib/grass72/"
  }
initGRASS(gisBase = gisbase,
    home = tempdir(),
    override = TRUE)

# Load files into GRASS
dem_path <- system.file("extdata", "nc", "elev_ned_30m.tif", package = "openSTARS")
sites_path <- system.file("extdata", "nc", "sites_nc.shp", package = "openSTARS")
setup_grass_environment(dem = dem_path, sites = sites_path)
import_data(dem = dem_path, sites = sites_path)
gmeta()

# Derive streams from DEM
derive_streams(burn = 0, accum_threshold = 700, condition = TRUE, clean = TRUE)

# Check and correct complex junctions (there are no complex juctions in this 
# example date set)
cj <- check_compl_junctions()
if(cj){
  correct_compl_junctions()
}

# Prepare edges
calc_edges()

# Prepare site
calc_sites()

# Plot data
dem <- readRAST('dem', ignore.stderr = TRUE)
edges <- readVECT('edges', ignore.stderr = TRUE)
sites <- readVECT('sites', ignore.stderr = TRUE)
plot(dem, col = terrain.colors(20))
lines(edges, col = 'blue')
points(sites, pch = 4)
 
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab