View source: R/calc_attributes_sites_approx.R
calc_attributes_sites_approx | R Documentation |
For each site (observations or predictions) attributes (potential predictor variables) are derived based on the values calculated for the edge the site lies on. This function calculates approximate values for site catchments as described in Peterson & Ver Hoef, 2014: STARS: An ArcGIS Toolset Used to Calculate the Spatial Information Needed to Fit Spatial Statistical Models to Stream Network Data. J. Stat. Softw., 56 (2).
calc_attributes_sites_approx( sites_map = "sites", input_attr_name = NULL, output_attr_name = NULL, stat = NULL, round_dig = 2, calc_basin_area = TRUE, overwrite = FALSE )
sites_map |
character; name of the sites (observation or prediction) attributes shall be calculated for. "sites" (default) refers to the observation sites. |
input_attr_name |
character vector; input column name(s) in the attribute table of the vector map "edges". |
output_attr_name |
character vector (optional); output column name(s)
appended to the site attribute data table. If not provided it is set to
|
stat |
name or character vector giving the statistics to be calculated. See details below. |
round_dig |
integer; number of digits to round results to. |
calc_basin_area |
boolean; shall the catchment area be calculated? (Useful to set to FALSE if the function has been called before.) |
overwrite |
boolean; shall existing columns be overwritten; defaults to FALSE |
The approximate total catchment area (H2OAreaA) is always calculated
if calc_basin_area
is TRUE. If stat
is one of
"min", "max", "mean" or "percent" the function assigns the value of the edge the site lies on.
Otherwise, the value is calculated as the sum of all edges upstream of the previous
confluence and the proportional value of the edge the site lies on (based on
the distance ratio 'ratio'); this is useful e.g. for counts of dams or waste water
treatment plants or total catchment area.
input_attr_name
must give the column names of the edges attribute table
for that the statistics should be calculated.
Nothing. The function appends new columns to the sites_map
attribute table
'H2OAreaA': Total watershed area of the watershed upstream of each site.
attr_name: Additional optional attributes calculated based on input_attr_name
.
import_data
, derive_streams
,
calc_edges
, calc_sites
or
calc_prediction_sites
and calc_attributes_edges
must be run before.
Mira Kattwinkel, mira.kattwinkel@gmx.net
# 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 sites_path <- system.file("extdata", "nc", "sites_nc.shp", package = "openSTARS") preds_v_path <- system.file("extdata", "nc", "geology.shp", package = "openSTARS") import_data(dem = dem_path, sites = sites_path, predictor_vector = preds_v_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() # Derive slope from the DEM as an example raster map to calculate attributes from execGRASS("r.slope.aspect", flags = c("overwrite","quiet"), parameters = list( elevation = "dem", slope = "slope" )) calc_attributes_edges(input_raster = "slope", stat_rast = "max", attr_name_rast = "maxSlo", input_vector = "geology", stat_vect = "percent", attr_name_vect = "GEO_NAME") calc_sites() # approximate potential predictor variables for each site based on edge values calc_attributes_sites_approx( input_attr_name = c('maxSlo', 'CZamp', 'CZbgp', 'CZfgp', 'CZgp', 'CZigp', 'CZlgp', 'CZvep', 'Kmp'), stat = c("max", rep("percent", 8))) # plot share of a certain geology in the sampling point's catchment as # point size library(sp) edges <- readVECT('edges', ignore.stderr = TRUE) sites <- readVECT('sites', ignore.stderr = TRUE) geo <- readVECT("geology", ignore.stderr = TRUE) plot(geo, col = adjustcolor(1:8, alpha.f = 0.5)[as.factor(geo$GEO_NAME)]) plot(edges, col = "blue", add = TRUE) plot(sites, col = 1, add = TRUE, pch = 19, cex = (sites$CZbgp + 0.15) * 2) legend("left", col = adjustcolor(1:8, alpha.f = 0.5), bty = "n", legend = unique(geo$GEO_NAME), pch = 15, title = "geology") legend("right", col = 1, pch = 19, legend = seq(0, 1, 0.2), bty = "n", title = "share CZbg\nin catchment", pt.cex = (seq(0, 1, 0.2) + 0.15) * 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.