vignettes/articles/ghp/scapesClassification_02_2_ISU.Rmd
scapesClassification_02_2_ISU.Rmd
The island shelf unit (ISU) is composed of two main elements: (i) shelves (i.e., relatively flat areas surrounding islands) and (ii) slopes (i.e., areas that connect island shelves to the seafloor).
Libraries and data are loaded and processed as explained in format input data.
# 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)
# COMPUTE ATTRIBUTE TABLE
atbl <- attTbl(rstack, var_names = c("bathymetry", "local_bpi", "regional_bpi", "slope"))
# COMPUTE NEIGHBORHOOD LIST
nbs <- ngbList(rstack, rNumb = TRUE, attTbl = atbl) # neighbors are identified by their row number in the attribute table
In the following example we will show how the class vector of ISU cells is computed. However, in order to improve the reading experience, the plots’ code is hidden. It can be accessed in the *.RMD
file used to generate the html file.
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 example we will use 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).
ISU cells will be identified in a series of steps. Each classification step will be saved as a class vector, a vector of length equal to the number of rows of the attribute table. The nth element of a class vector corresponds to the raster cell in the nth row of an attribute table (see also ?conditions
and class vectors).
Class vectors can be converted into a raster, plotted and saved using the function cv.2.rast()
. However, here we will present classification outputs as interactive maps using the R packages mapview
and leaflet
. The plots’ code can be accessed in the *.RMD file used to generate the html file.
Anchor cells are raster cells that can be easily assigned to a class because of some distinctive attribute(s). For example, cells ‘adjacent to an island’ by definition are ‘shelf cells’. We can derive this initial set of cells using two functions (Figure 1):
anchor.svo: returns a vector of cell numbers extracted at the locations of a spatial vector object. In this example, ‘land cells’ are defined as raster cells extracted at island locations that are incomplete cases (arg. only_NAs = T
) and at contiguous locations that are also incomplete cases (arg. fill_NAs = T
);
anchor.cell: converts a vector of cell numbers into a class vector. In this example, all cells adjacent to ‘land cells’ are classified as ‘ISU-anchor cells’.
# ISLAND SHAPEFILE PATH
shp <- system.file("extdata", "Azores.shp", package = "scapesClassification")
# EXTRACT LAND POSITIONS
anchorLAND <- anchor.svo(r = rstack, dsn = shp, only_NAs = TRUE, fill_NAs = TRUE)
# IDENTIFY ANCHOR CELLS
anchorCELL <- anchor.cell(attTbl = atbl, r = rstack, anchor = anchorLAND, class = 1,
class2cell = FALSE, # class not attributed to land cells
class2nbs = TRUE) # class attributed to cell adjacent to land cells