k_means {terra} | R Documentation |
k_means
Description
Compute k-means clusters for a SpatRaster. For large SpatRasters (with ncell(x) > maxcell
) this is done in two steps. First a sample of the cells is used to compute the cluster centers. Then each cell is assigned to a cluster by computing the distance to these centers.
Usage
## S4 method for signature 'SpatRaster'
k_means(x, centers=3, ..., maxcell=1000000, filename="", overwrite=FALSE, wopt=list())
Arguments
x |
SpatRaster |
centers |
either the number of clusters, or a set of initial (distinct) cluster centres. If a number, a random set of (distinct) cells in |
... |
additional arguments passed to |
maxcell |
positive integer. The size of the regular sample used if it is smaller than |
filename |
character. Output filename (ignored if |
overwrite |
logical. If |
wopt |
list with additional arguments for writing files as in |
Value
SpatRaster
See Also
Examples
f <- system.file("ex/logo.tif", package = "terra")
r <- rast(f)
km <- k_means(r, centers=5)
km
[Package terra version 1.7-78 Index]