Skip to contents

Randomly sample within a stratification raster extent.

Usage

sample_srs(
  raster,
  nSamp,
  mindist = NULL,
  access = NULL,
  buff_inner = NULL,
  buff_outer = NULL,
  plot = FALSE,
  filename = NULL,
  overwrite = FALSE
)

Arguments

raster

spatRaster. Raster to be used for random sampling.

nSamp

Numeric. Number of desired samples.

mindist

Numeric. Minimum allowable distance between selected samples. Default = NULL.

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. Plots output strata raster with samples.

filename

Character. Path to write output samples.

overwrite

Logical. Choice to overwrite existing filename if it exists.

Value

An sf object with nSamp randomly sampled points.

Author

Tristan R.H. Goodbody & Martin Queinnec

Examples

#--- Load raster and access files ---#
r <- system.file("extdata", "sraster.tif", package = "sgsR")
sr <- terra::rast(r)

a <- system.file("extdata", "access.shp", package = "sgsR")
ac <- sf::st_read(a)
#> Reading layer `access' from data source 
#>   `/home/runner/work/_temp/Library/sgsR/extdata/access.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 167 features and 2 fields
#> Geometry type: MULTILINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 431100 ymin: 5337700 xmax: 438560 ymax: 5343240
#> Projected CRS: UTM_Zone_17_Northern_Hemisphere

#--- perform simple random sampling ---#
sample_srs(
  raster = sr,
  nSamp = 200,
)
#> Simple feature collection with 200 features and 0 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431110 ymin: 5337750 xmax: 438450 ymax: 5343210
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                  geometry
#> 1  POINT (438150 5340650)
#> 2  POINT (434550 5338790)
#> 3  POINT (431170 5339290)
#> 4  POINT (431270 5340730)
#> 5  POINT (433450 5340410)
#> 6  POINT (432230 5339630)
#> 7  POINT (432910 5341870)
#> 8  POINT (431250 5341130)
#> 9  POINT (436770 5341390)
#> 10 POINT (438250 5340230)