Skip to contents

Sub-sample an existing sample. Four sampling methods are available: clhs, balanced, srs and strat.

Usage

sample_existing(
  existing,
  nSamp,
  raster = NULL,
  type = "clhs",
  access = NULL,
  buff_inner = NULL,
  buff_outer = NULL,
  details = FALSE,
  filename = NULL,
  overwrite = FALSE,
  ...
)

Arguments

existing

sf 'POINT'. Existing plot network.

nSamp

Numeric. Number of desired samples.

raster

SpatRaster. Raster to guide the location of the samples. If type = "clhs" this raster can also be used to define the population distributions to be used for sampling.

type

Character. A string indicating the type of sampling method to use. Possible values are "clhs", "balanced", "srs" and "strat".

access

sf. Road access network - must be lines.

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.

details

Logical. If FALSE (default) output is sf object of systematic samples. If TRUE returns a list of sf objects where tessellation is the tessellation grid for sampling, and samples are the systematic samples.

filename

Character. Path to write output samples.

overwrite

Logical. Choice to overwrite existing filename if it exists.

...

Additional arguments for the sampling method selected.

Value

An sf object of samples or a list object if details = TRUE

Note

When type = "clhs" or type = "balanced" all attributes in existing will be used for sampling. Remove attributes not indented for sampling' prior to using this algorithm.

Author

Tristan R.H. Goodbody

Examples

r <- system.file("extdata", "mraster.tif", package = "sgsR")
mr <- terra::rast(r)

#--- generate an existing sample adn extract metrics ---#
e <- sample_systematic(raster = mr, cellsize = 200)
e <- extract_metrics(existing = e, mraster = mr)

#--- perform clhs (default) sub-sampling ---#
sample_existing(
  existing = e,
  nSamp = 50
)
#> Sub-sampling based on ALL 'existing' metric distributions. Ensure only attributes of interest are included.
#> Simple feature collection with 50 features and 3 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431113.4 ymin: 5337781 xmax: 438145 ymax: 5343015
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      zq90 pzabove2  zsd                 geometry
#> 703 19.30     71.4 3.97 POINT (436096.5 5341519)
#> 595 11.70     54.5 3.21 POINT (437798.3 5338469)
#> 847 15.20     76.4 4.49 POINT (436860.6 5342758)
#> 253 21.00     77.5 5.71   POINT (431871 5341994)
#> 824 25.80     95.0 6.66 POINT (437374.4 5341602)
#> 737 23.60     86.3 6.18 POINT (437592.8 5340177)
#> 518  5.03     27.0 2.37 POINT (434266.3 5341744)
#> 880 16.90     94.4 3.08 POINT (437438.5 5343015)
#> 766 15.60     93.7 3.87   POINT (438145 5339869)
#> 374 18.50     45.8 5.26 POINT (435415.9 5339002)

#--- perform balanced sub-sampling ---#
sample_existing(
  existing = e,
  nSamp = 50,
  type = "balanced"
)
#> Simple feature collection with 50 features and 3 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431537.1 ymin: 5337865 xmax: 438549.6 ymax: 5343137
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      zq90 pzabove2  zsd                 geometry
#> 8   17.20     96.8 3.54 POINT (431543.7 5337903)
#> 32  13.30     94.7 2.90 POINT (432391.3 5337865)
#> 38  17.00     91.9 4.54 POINT (432404.2 5338147)
#> 58  14.70     97.5 2.83 POINT (432564.7 5338565)
#> 61  13.40     87.4 3.35 POINT (432969.3 5338122)
#> 75  12.60     62.4 3.55   POINT (433117 5338257)
#> 121  6.97     76.4 1.72 POINT (431537.1 5340876)
#> 182 14.80     91.4 3.74 POINT (433585.7 5339226)
#> 198 18.60     84.7 5.12 POINT (432249.9 5340986)
#> 228 19.50     92.0 4.26 POINT (432667.3 5340825)

#--- perform simple random sub-sampling ---#
sample_existing(
  existing = e,
  nSamp = 50,
  type = "srs"
)
#> Simple feature collection with 50 features and 3 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431126.3 ymin: 5337769 xmax: 438517.4 ymax: 5343002
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>     zq90 pzabove2  zsd                 geometry
#> 1  20.50     74.8 6.28 POINT (435813.9 5341532)
#> 2  17.60     78.0 5.20 POINT (432860.1 5338834)
#> 3  17.20     88.1 4.41 POINT (431845.4 5341429)
#> 4  18.80     90.9 5.01 POINT (433624.2 5340074)
#> 5  10.50     25.7 2.81 POINT (432609.5 5342668)
#> 6  20.60     93.8 5.99 POINT (434054.4 5340196)
#> 7   8.51     84.9 1.84 POINT (437926.6 5341294)
#> 8  16.60     87.9 3.98 POINT (433682.1 5338231)
#> 9  14.80     91.4 3.82   POINT (437625 5337769)
#> 10 15.80     76.4 3.92 POINT (431819.7 5340864)