Description Usage Arguments Details Note Author(s) Examples
A vector (points) map 'sites' is derived and several attributes are assigned.
1 2 3 4 5 6 | calc_sites(
locid_col = NULL,
pid_col = NULL,
predictions = NULL,
maxdist = NULL
)
|
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. |
predictions |
character vector (optional); names for prediction sites
(loaded with |
maxdist |
integer (optional); maximum snapping distance in map units (see details). Sites farther away from edges will be deleted. |
Steps include:
Snap points to derived network (edges). 'dist'
gives the distance of the original position to the closest streams segment.
If this is a too large value consider running derive_streams
again with
smaller value for accum_threshold
and/or min_stream_length
.
Save the new point coordinates in NEAR_X and NEAR_Y.
Assign unique 'pid' and 'locID' (needed by the 'SSN' package).
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 the GRASS function 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 measurements
can be joined to the sites at a later step (including multiple parameters and
multiple measurements) using merge_sites_measurements
.
Then, 'pid' is updated accordingly.
'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'.
The unit for distances (= map units) can be found out using execGRASS("g.proj", flags = "p").
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
.
import_data
, derive_streams
and
calc_edges
must be run before.
Mira Kattwinkel mira.kattwinkel@gmx.net, Eduard Szoecs, eduardszoecs@gmail.com,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # Initiate and setup GRASS
dem_path <- system.file("extdata", "nc", "elev_ned_30m.tif", package = "openSTARS")
if(.Platform$OS.type == "windows"){
grass_program_path = "c:/Program Files/GRASS GIS 7.6"
} else {
grass_program_path = "/usr/lib/grass78/"
}
setup_grass_environment(dem = dem_path,
gisBase = grass_program_path,
remove_GISRC = TRUE,
override = TRUE
)
gmeta()
# 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")
import_data(dem = dem_path, sites = sites_path)
# Derive streams from DEM
derive_streams(burn = 0, accum_threshold = 700, condition = TRUE, clean = TRUE)
# Check and correct complex confluences (there are no complex confluences in this
# example date set; set accum_threshold in derive_streams to a smaller value
# to create complex confluences)
cj <- check_compl_confluences()
if(cj){
correct_compl_confluences()
}
# Prepare edges
calc_edges()
# Prepare site
calc_sites()
# Plot data
library(sp)
dem <- readRAST('dem', ignore.stderr = TRUE, plugin = FALSE)
edges <- readVECT('edges', ignore.stderr = TRUE)
sites <- readVECT('sites', ignore.stderr = TRUE)
sites_o <- readVECT('sites_o', ignore.stderr = TRUE)
plot(dem, col = terrain.colors(20),axes = TRUE)
lines(edges, col = 'blue')
points(sites, pch = 4)
points(sites_o, pch = 1)
legend("topright", pch = c(1, 4), legend = c("original", "corrected"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.