Description Usage Arguments Details Value See Also Examples
Performs kmeans clustering to stratify x
and randomly samples within
the strata until n
samples are selected. The number of samples selected
in each strata is proportional to the occurrence of those strata across the
classified raster.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
x |
A |
strata |
Number of strata (kmeans clusters). Default is 5. |
layers |
Vector indicating the bands of |
norm |
Logical. If TRUE (default), |
n |
Sample size |
mindist |
Minimum distance between samples (in units of |
maxIter |
Numeric. This number is multiplied to the number of samples to select per strata. If the number of iterations to select samples exceeds maxIter x the number of samples to select then the loop will break and a warning message be returned. Default is 30. |
xy |
Logical indicating if X and Y coordinates of samples should be included in the fields of the returned |
filename_cluster |
Character. Output filename of the clustered |
filename_sample |
Character. Output filename of the sample points including path to directory. File will be automatically saved as an ESRI Shapefile and any extension in |
... |
Further arguments passed to |
x
is stratified using kmeans clustering from unsuperClass
.
By default, clustering is performed on a random subset of x
(10000 cells) and run
with multiple starting configurations in order to find a convergent solution
from the multiple starts. The parameters controlling the number of random
samples used to perform kmeans clustering and the number of starting
configurations can be provided as additional ...
arguments. More
information on the behavior of the kmeans clustering can be found in
unsuperClass
. The default kmeans clustering method
is Hartigan-Wong algorithm. The algorithm might not converge and output
"Quick Transfer" warning. If this is the case, we suggest decreasing
strata
. Also, if mindist
is too large, it might not be
possible to select enough samples per strata. In that case, the warning
"Exceeded maximum number of runs for strata" is displayed. In that case
you can decrease the number of samples n
or increase maxIter
to control the number of maximum iterations allowed until the required number of samples are selected.
A list with the following objects:
sample
A SpatialPoints
object containing sampled points
clusterMap
The clustered x
raster, output of unsuperClass
model
The kmeans model, output of unsuperClass
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Load raster package
library(raster)
# Open and stack ALS metrics
elev_p95 <- raster(system.file("extdata/examples/ALS_metrics_p95.tif",package="foster"))
cover <- raster(system.file("extdata/examples/ALS_metrics_cov_mean.tif",package="foster"))
Y_vars <- stack(elev_p95,cover)
names(Y_vars) <- c("p95","cover")
# Sample 5 cells in 3 strata (kmeans clusters). Sampled points should be at least 30 m apart.
set.seed(1234) #for example reproducibility
sample_strata <- getSample(Y_vars,
n = 5,
strata = 3,
mindist = 30)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.