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: 431230.4 ymin: 5337736 xmax: 438491.6 ymax: 5343117
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      zq90 pzabove2  zsd                 geometry
#> 133  9.93     77.9 2.50 POINT (432223.2 5340588)
#> 877 14.70     99.7 1.57 POINT (438084.1 5339074)
#> 459 12.30     96.0 2.63 POINT (434996.2 5341864)
#> 375 13.70     82.9 3.60 POINT (433842.4 5338982)
#> 371 22.60     96.7 5.76 POINT (433962.3 5339975)
#> 197 13.20     84.1 3.71 POINT (432284.7 5337760)
#> 782  3.75      7.2 0.79 POINT (437967.8 5343117)
#> 225 10.70     69.0 3.10 POINT (432483.3 5337736)
#> 391  4.47     19.7 1.04 POINT (434256.7 5340745)
#> 410  7.15     79.6 2.10 POINT (434575.2 5341714)

#--- 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: 431141.3 ymin: 5337719 xmax: 438419.7 ymax: 5343206
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      zq90 pzabove2  zsd                 geometry
#> 22   4.97     28.9 1.15 POINT (431206.4 5340509)
#> 35  18.20     93.1 4.61 POINT (431500.9 5341279)
#> 38   6.25     22.7 1.53   POINT (431429 5340683)
#> 45  16.50     91.3 3.78 POINT (431237.2 5339095)
#> 49  15.90     96.9 2.62 POINT (431141.3 5338301)
#> 86  13.90     64.7 4.06   POINT (431874 5341033)
#> 149 11.20     97.0 2.42 POINT (432613.6 5342152)
#> 159 13.80     83.4 3.39 POINT (432373.8 5340166)
#> 202 16.50     77.9 3.93 POINT (433034.6 5342303)
#> 209 10.60     70.9 2.62 POINT (432866.8 5340913)

#--- 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: 431302.3 ymin: 5337749 xmax: 438371.7 ymax: 5343110
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      zq90 pzabove2  zsd                 geometry
#> 207 14.30     67.3 3.38 POINT (432914.8 5341310)
#> 764 11.80     86.9 3.21 POINT (437649.4 5342148)
#> 784  5.20     15.9 1.18 POINT (437919.9 5342720)
#> 622 16.30     89.7 3.38 POINT (435708.1 5337749)
#> 618 16.50     90.4 3.95   POINT (435852 5338941)
#> 865 24.30     83.7 7.17 POINT (438371.7 5341457)
#> 33  14.80     90.7 3.15 POINT (431548.8 5341676)
#> 724  9.61     51.8 2.68 POINT (436988.6 5340012)
#> 108 11.70     75.4 3.07 POINT (432120.5 5341406)
#> 830  8.29     88.8 1.70 POINT (437567.1 5338129)