sample_nc {sgsR}R Documentation

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
)

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 stratified raster to disc.

overwrite

Logical. Specify whether filename should be overwritten on disc.

Value

An sf object with nSamp randomly sampled points.

Note

When details = TRUE, a list is returned where:

  1. samples output nearest centroid samples with kcenter attribute linking to associated kmeans centers.

  2. kmeans is a list output of the kmeans function

  3. centers Un-scaled kmeans center values for each layer in mraster with kcenter attribute to link with the same attribute in samples.

  4. kplot is a ggplot scatterplot object visualizing the kmeans centers and associated nearest neighbor samples.

Author(s)

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

#--- 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,
)


[Package sgsR version 1.4.5 Index]