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: 431150 ymin: 5337710 xmax: 438550 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                  geometry
#> 1  POINT (435710 5340390)
#> 2  POINT (431210 5343230)
#> 3  POINT (436670 5339650)
#> 4  POINT (436490 5340670)
#> 5  POINT (433090 5342990)
#> 6  POINT (435690 5342970)
#> 7  POINT (432270 5342230)
#> 8  POINT (437510 5341350)
#> 9  POINT (431330 5340110)
#> 10 POINT (435670 5337870)