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 |
iter |
Numeric. The maximum number of kmeans iterations allowed. |
algorithm |
Character. |
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 |
details |
Logical. If |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
Value
An sf object with nSamp
randomly sampled points.
Note
When details = TRUE
, a list is returned where:
-
samples
output nearest centroid samples withkcenter
attribute linking to associated kmeans centers. -
kmeans
is a list output of thekmeans
function -
centers
Un-scaled kmeans center values for each layer inmraster
withkcenter
attribute to link with the same attribute insamples
. -
kplot
is aggplot
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,
)