import_data: Import data into 'GRASS.'

Description Usage Arguments Details Value Note Author(s) Examples

Description

This function loads a DEM (digital elevation model) and sites data (both required) into the 'GRASS' session. Optionally, prediction sites and streams data can be loaded and the streams may be corrected by snapping to prevent lose ends. Likewise, potential predictor maps (raster or vector format) can be loaded.

Usage

1
2
3
import_data(dem, band = 1, sites, streams = NULL, snap_streams = FALSE,
  pred_sites = NULL, predictor_raster = NULL, predictor_r_names = NULL,
  predictor_vector = NULL, predictor_v_names = NULL)

Arguments

dem

character; path to DEM (digital elevation model) raster file.

band

integer (optional); defines which band is used

sites

character string or object; path to sites vector file (ESRI shape) or sp or sf data object.

streams

character string or object (optional); path to network vector file (ESRI shape) or sp or sf data object. If available this can be burnt into the DEM in derive_streams

snap_streams

boolean (optional); snap line ends. If TRUE line ends of the streams are snapped to the next feature if they are unconnected with threshold of 10 m using 'GRASS' function v.clean.

pred_sites

character string vector or object(s) (optional); path(s) to prediction sites vector files (ESRI shape) or sp or sf data object.

predictor_raster

character vector (optional); paths to raster data to import as predictors.

predictor_r_names

character string vector (optional); names for potential predictor variables in raster format; if not provided perdictor_raster is used.

predictor_vector

character string vector of object(s) (optional); path(s) to vector data (ESRI shape) or sp or sf object names to import as predictors.

predictor_v_names

character vector (optional); names for potential predictor variables in vector format ; if not provided perdictor_vector is used.

Details

All vector data (sites, streams and potential predictors) is imported into the current location using v.import. Hence, if the projections does not match to the one of the DEM (which was used to specify the location in setup_grass_environment) the maps are imported on the fly.

Value

Nothing, the data is loaded into the 'GRASS' session (mapset PERMANENT). The DEM is stored as raster 'dem', sites as vector 'sites_o', prediction sites as vector using the original file names with an appended '_o' (without extension), streams as vector 'streams_o' in the 'GRASS' location. Additionally, predictor raster map(s) can be read in and are stored in 'GRASS' using either the original file names (without extension) or using the names provides in predictor_r_names. The latter option may be useful if ArcGIS grid data (typically stored as 'grid_name/w001001.adf') are used. Likewise, predictor vector maps can be read in from Esri Shape file (given as the full file path) or as sf or sp objects. Potential predictor data can also be read in later, e.g. using GRASS commands v.import or r.in.gdal (see examples below).

Note

A GRASS session must be initiated before, see initGRASS.

If sites, pred_sites and / or streams are sp objects it is important that they have a datum defined otherwise the import will not work. Hence, it is e.g. better to use proj4string = CRS("+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +datum=potsdam +units=m +no_defs") instead of proj4string = CRS("+proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel +towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7 +units=m +no_defs")) when defining sp objects.

Author(s)

Eduard Szoecs, [email protected], Mira Kattwinkel [email protected]

Examples

 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
# Initiate GRASS session
if(.Platform$OS.type == "windows"){
  gisbase = "c:/Program Files/GRASS GIS 7.4.0"
  } else {
  gisbase = "/usr/lib/grass74/"
  }
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")
preds_path <- system.file("extdata", "nc", "landuse.shp", package = "openSTARS")
setup_grass_environment(dem = dem_path)
import_data(dem = dem_path, sites = sites_path, predictor_vector = preds_path)

# Plot data
dem <- readRAST("dem", ignore.stderr = TRUE)
sites_orig <-  readVECT("sites_o", ignore.stderr = TRUE)
lu <- readVECT("landuse", ignore.stderr = TRUE)
plot(dem, col = terrain.colors(20))
plot(dem, col = grey.colors(20))
col <- adjustcolor(c("red", "green", "blue", "yellow"), alpha.f = 0.3)
plot(lu, add = TRUE, col = col[as.numeric(as.factor(lu$landuse))])
legend("top", col = col, pch = 15, 
  legend = as.factor(sort(unique(lu$landuse))), title = "landuse", ncol = 4)
points(sites_orig, pch = 4)

# import additional vector data
fp <-  system.file("extdata", "nc", "pointsources.shp", package = "openSTARS")
execGRASS("v.import", flags = c("overwrite", "quiet"),
parameters = list(
  input = fp,
  output =  "psources",
  extent = "region"),  # to import into current regien
  intern = TRUE, ignore.stderr = TRUE)
  
ps <- readVECT("psources")
points(ps, bg = "red", pch = 21, col = "grey", cex = 1.5)

MiKatt/openSTARS documentation built on May 7, 2019, 4:55 p.m.