getSample: Stratified random sampling

Description Usage Arguments Details Value See Also


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.


getSample(x, strata = 5, layers = names(x), norm = TRUE, n,
  mindist = 0, maxIter = 30, xy = T, filename_cluster = "",
  filename_samples = "", ...)



A Raster* object used to generate random sample


Number of strata. Default is 5.


Vector indicating the bands of x used in stratification (as integer or names). By default, all layers of x are used.


Logical. If TRUE (default), x is normalized before k-means clustering. This is useful if layers have different scales.


Sample size


Minimum distance between samples (in units of x). Default is 0.


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.


Logical indicating if X and Y coordinates of samples should be included in the fields of the returned SpatialPoints object.


Character. Output filename of the clustered x raster including path to directory and eventually extension


Character. Output filename of the sample points including path to directory. File will be automatically saved as an ESRI Shapefile and any extension in filename_samples will be overwritten


Further arguments passed to unsuperClass, writeRaster or writeOGR to control the kmeans algorithm or writing parameters


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 under the ... argument. 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:


A SpatialPoints object containing sample points


The clustered x raster, output of unsuperClass

See Also


mqueinnec/foster documentation built on June 3, 2019, 4:22 a.m.