vignettes/articles/ghp/scapesClassification_02_1_DATA.Rmd
scapesClassification_02_1_DATA.RmdOur study area is located in the ‘Triangle’ of the Azores (NE Atlantic), around the islands of Faial, Pico and São Jorge (Figure 1). Geomorphic management units (GMUs) will be identified using a SpatRaster(terra package) of 4 layers that includes bathymetry and bathymetric derivatives (Walbridge et al., 2018):
We will start by loading the required libraries and data into the workspace:
# LOAD LIBRARIES
library(scapesClassification)
library(terra)
# LOAD DATA
grd <- list.files(system.file("extdata", package = "scapesClassification"), full.names = T)
grd <- grd[grepl("\\.grd", grd)]
grd <- grd[!grepl("hillshade", grd)]
rstack <- rast(grd)We can plot the raster stack as an interactive map using the R packages mapview and leaflet:
In the working example articles we will show how class vectors are computed. However, in order to improve the reading experience, the plots’ code is hidden. It can be accessed in the *.RMD files used to generate the html files.
The plotting procedure is to (i) convert a class vectors into a raster using the function cv.2.rast() and to (ii) visualize the raster using R or an external software. In our examples we will use the R package terra to create static maps and the R packages mapview and leaflet to create interactive maps (note that mapview do not support terra raster objects yet, therefore, they have to be converted into raster raster objects before plotting).
The classification process in scapesClassification begins with the computation of two elements (see format inputs):
Attribute table: the raster object converted into a data.frame. Attribute tables include only raster cells having no missing values. Function attTbl().
Classification rules are built accessing by name the variables stored in the attribute table (see ?conditions).
# COMPUTE ATTRIBUTE TABLE
atbl <- attTbl(rstack, var_names = c("bathymetry", "local_bpi", "regional_bpi", "slope"))
# VIEW THE TOP 3 ROWS OF `atbl`
# Each row corresponds to a raster cell as indicated in the column `atbl$Cell`
head(atbl, 3)
## Cell bathymetry local_bpi regional_bpi slope
## 1 1 -1718.056 -4 129 1.410384
## 2 2 -1737.816 -3 107 2.021313
## 3 3 -1755.392 -1 87 2.482018List of neighborhoods: raster cell neighborhoods. Neighborhoods are computed only for cells included in the attribute table. Function ngbList().
# COMPUTE NEIGHBORHOOD LIST
nbs <- ngbList(rstack, rNumb = TRUE, attTbl = atbl) # the neighbors are identified by row numbers (see ?ngbList)
# VIEW THE TOP ELEMENT OF `nbs`
nbs[1]
## $`1`
## [1] 2 291 292
# nbs[1] reads as:
# the cell in row $`1` of `atbl` has
# cells in `atbl` rows 2, 291 and 292 as neighbors