View source: R/SOptim_UnsupervisedClassification.R
clusteringRaster | R Documentation |
Runs a clustering/unsupervised learning/classification algorithm on a multi-layer SpatRaster
object.
It also allows calculating internal clustering performance criteria based on function
intCriteria
using a stratified random sample of output pixels.
clusteringRaster(
inRst,
k,
writeRasterData = TRUE,
outRst,
getSpatRaster = TRUE,
method = "kmeans",
calcIntCriteria = FALSE,
crit = c("Silhouette"),
intCritSampSize = 20000,
verbose = TRUE,
...
)
inRst |
An input |
k |
An integer vector defining the number of clusters. If more than one value is given then
|
writeRasterData |
Write clustered raster data to file (i.e., to outRst)? (default:TRUE) |
outRst |
Name of the output raster. For each value in |
getSpatRaster |
Get an output |
method |
A string defining the method used for clustering. Available options are:
|
calcIntCriteria |
Calculate internal clustering criteria? (default: FALSE). |
crit |
A character vector containing the names of the indices to compute. Check available indices
at |
intCritSampSize |
Number of sample pixels to use for internal criteria calculation (default: 20000). Increasing this number will make estimations better however at the expense of more memory. |
verbose |
Print progress messages? (default: TRUE). |
... |
Further parameters passed to each of clustering functions |
If getSpatRaster=TRUE
then a SpatRaster
object with all clustering solutions will be returned.
If getSpatRaster=TRUE
and calcIntCriteria=TRUE
then an additional matrix named intClustCrit
with
one row by k value will be returned with the requested clustering indices. If getSpatRaster=FALSE
then only the matrix
with clustering indices will be returned.
See intCriteria
, getCriteriaNames
for more details on
clustering criteria.
Check out clustering functions at: kmeans
, cclust
, and,
clara
.
library(terra)
r1 <- rast(nrows=10, ncols=10, vals=rnorm(100))
r2 <- rast(nrows=10, ncols=10, vals=rnorm(100))
r3 <- rast(nrows=10, ncols=10, vals=rnorm(100))
rstStack <- c(r1, r2, r3)
clusteringRaster(rstStack, k = 2:10, writeRasterData = FALSE, getSpatRaster = TRUE,
method="kmeans", calcIntCriteria = FALSE, crit = c("Silhouette"),
intCritSampSize = 20000, verbose = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.