Learn R Programming

sgsR (version 1.5.0)

sample_nc: Nearest centroid (NC) sampling

Description

Sampling using the nearest centroid (NC) approach described in Melville & Stone (2016).

Usage

sample_nc(
  mraster,
  nSamp,
  k = 1,
  iter = 500,
  algorithm = "Lloyd",
  access = NULL,
  buff_inner = NULL,
  buff_outer = NULL,
  plot = FALSE,
  details = FALSE,
  filename = NULL,
  overwrite = FALSE
)

Value

An sf object with nSamp randomly sampled points.

Arguments

mraster

spatRaster. ALS metrics raster.

nSamp

Numeric. Number of desired samples.

k

Numeric. The number of nearest neighbours to take for each k-means center. When k = 1 (default), the output number of samples will match nSamp. Increases to k results in a multiplicative result total number of samples nSamp * k.

iter

Numeric. The maximum number of kmeans iterations allowed.

algorithm

Character. Lloyd (default) or MacQueen kmeans algorithms.

access

sf 'LINESTRING' or 'MULTILINESTRING'. Access network.

buff_inner

Numeric. Inner buffer boundary specifying distance from access where plots cannot be sampled.

buff_outer

Numeric. Outer buffer boundary specifying distance from access where plots can be sampled.

plot

Logical. Plot mraster with allocated samples.

details

Logical. If FALSE (default) output is only stratification raster. If TRUE return a list where $details is additional stratification information and $raster is the output stratification spatRaster.

filename

Character. Path to write output samples.

overwrite

Logical. Choice to overwrite existing filename if it exists.

Author

Tristan R.H. Goodbody

References

G. Melville & C. Stone (2016) Optimising nearest neighbour information—a simple, efficient sampling strategy for forestry plot imputation using remotely sensed data, Australian Forestry, 79:3, 217-228, DOI: 10.1080/00049158.2016.1218265

See Also

Other sample functions: sample_ahels(), sample_balanced(), sample_clhs(), sample_existing(), sample_srs(), sample_strat(), sample_sys_strat(), sample_systematic()

Examples

Run this code
#--- Load raster and access files ---#
r <- system.file("extdata", "mraster.tif", package = "sgsR")
mr <- terra::rast(r)

#--- perform simple random sampling ---#
sample_nc(
  mraster = mr,
  nSamp = 5,
)

Run the code above in your browser using DataLab