conditions {scapesClassification}R Documentation

scapesClassification conditions

Description

Check for spelling and syntax errors in conditions (cond argument) and detect the type of conditions being used.

Usage

conditions(names_attTbl, cond, silent = FALSE)

Arguments

names_attTbl

character vector, the column (i.e. variable) names of the attribute table returned by the function attTbl.

cond

character string, the condition string used by the cond.* functions to classify raster cells (see conditions).

silent

logic, when true, the function returns only error messages.

Details

Conditions (alias classification rules)

Class vectors

Rule evaluation: Global evaluation

Rule evaluation: Focal evaluation

Focal evaluation: Definitions

Condition type: Absolute conditions

1) Absolute test cell condition: compares cell values against a threshold value.

2) Absolute neighborhood condition: compares the values of the test cell and of its neighborhood against a threshold value.

Condition type: Relative conditions

1) Relative focal cell condition: compares the test cell value against the focal cell value.

2) Relative neighborhood condition: compares the values of the test cell against the values of the test cell neighborhood.

Value

An error message if the function finds spelling or syntax errors or a string with the types of rules detected in the condition string.

See Also

cond.4.all(), cond.4.nofn(), anchor.seed(), cond.reclass(), conditions()

anchor.seed(), attTbl(), cond.4.all(), cond.4.nofn(), cond.reclass(), classify.all()

Examples

# LOAD LIBRARIES
library(scapesClassification)
library(terra)

################################################################################
# TYPES OF CONDITIONS
################################################################################

# As an example consider an attribute with the following columns
names_attTbl <- c("bathymetry", "slope")

# And the following conditions
cond <- "bathymetry>10"
conditions(names_attTbl, cond)

cond <- "bathymetry[]>bathymetry | abs(slope{}) < 5"
conditions(names_attTbl, cond)

cond <- "bathymetry[]>bathymetry | abs(slope{}) < slope"
conditions(names_attTbl, cond)

################################################################################
# FOCAL EVALUATION DEFINITIONS
################################################################################

# CELL NUMBERS OF A DUMMY RASTER (7X7)
r   <- terra::rast(matrix(1:49, nrow = 7, byrow = TRUE), extent=c(0,7,0,7))
nbs <- ngbList(r)

# CLASS VECTOR WITH ONE TEST AND ONE FOCAL CELL
cv <- as.numeric(rep(NA, 49))
cv[c(32, 25)] <- c(1, 2) # tc (class 1), fc (class 2)
r_cv <- cv.2.rast(r, classVector = cv)

# POLYGONS REPRESENTING NEIGHBORHOODS
fcn <- rbind(c(2,5), c(5,5), c(5,2), c(2,2), c(2,5))
fcn <- terra::vect(fcn, type="polygons")

tcn <- rbind(c(2,4), c(5,4), c(5,1), c(2,1), c(2,4))
tcn <- terra::vect(tcn, type="polygons")

# PLOT - FOCAL EVALUATION DEFINITIONS
m <- c(3.5, 8, 1.2, 8)
plot(r_cv, type = "class", asp = NA, legend = FALSE, axes = FALSE, mar = m,
     col = c("goldenrod3","#1088a0"), colNA= "grey90")
text(r)
mtext(side=3, line=0, adj=0, cex=1, font=2, "FOCAL EVALUATION")
mtext(side=1, line=0, adj=0, cex=0.9,
      "Focal cell neighborhood: 17, 18, 19, 24, 26, 31, 32, 33")
mtext(side=1, line=1, cex=0.9, adj=0,
      "Test cell neighborhood: 24, 25, 26, 31, 33, 38, 39, 40")
mtext(side=1, line=2, cex=0.9, adj=0,
     "Directional neighborhood: 24, 25, 26, 31, 32, 33")
lines(fcn, col="#1088a0", lwd=2)
lines(tcn, col="#cfad8999", lwd=2)
legend("bottomleft", ncol = 1, bg = "white", y.intersp= 1.3,
       legend = c("Focal cell", "Test cell"), fill = c("#1088a0", "goldenrod3"))

[Package scapesClassification version 1.0.0 Index]