Systematic stratified sampling with random start point and translation within a square or hexagonal tessellation for each stratum.
Usage
sample_sys_strat(
sraster,
cellsize,
square = TRUE,
location = "centers",
force = FALSE,
access = NULL,
buff_inner = NULL,
buff_outer = NULL,
plot = FALSE,
filename = NULL,
overwrite = FALSE,
details = FALSE
)
Arguments
- sraster
spatRaster. Stratified raster with name
"strata"
.- cellsize
Numeric. Desired cellsize for tessellation.
- square
Logical. Tessellation shape. Default is regular square grid, if
FALSE
hexagons are used.- location
Character. Sample location within tessellation.
Default = "centers"
) returns samples at tessellation centers,"corners"
- corners of tessellation are returned,"random"
- samples are randomly located within tessellations.- force
Logical. Only applies when
location = "random"
. IfTRUE
, random samples are forced to fall in areas whereraster
does not haveNA
values. This will considerably slow processing.- 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.
- 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.- details
Logical. If
FALSE
(default) output is sf object of systematic samples. IfTRUE
returns a list of sf objects wheretessellation
is the tessellation grid for sampling, andsamples
are the systematic samples.
Note
Specifying location = "random"
can result in tessellations with no samples.
This results from raster
have NA
values at the random location chosen.
Using force = TRUE
removes areas of NA
from sampling entirely, but
considerably slows processing speeds. Thanks to R. Hijmans for help in debugging and
providing suggestions for this script.
All stratum are sampled using random tessellation start points and translations.
See also
Other sample functions:
sample_ahels()
,
sample_balanced()
,
sample_clhs()
,
sample_existing()
,
sample_nc()
,
sample_srs()
,
sample_strat()
,
sample_systematic()
Examples
#--- Load raster and access files ---#
r <- system.file("extdata", "sraster.tif", package = "sgsR")
sr <- terra::rast(r)
#--- perform grid sampling ---#
sample_sys_strat(
sraster = sr,
cellsize = 1000
)
#> Processing strata : 1
#> Warning: [extract] source already open for reading
#> Processing strata : 2
#> Warning: [extract] source already open for reading
#> Processing strata : 3
#> Warning: [extract] source already open for reading
#> Processing strata : 4
#> Warning: [extract] source already open for reading
#> Simple feature collection with 39 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431113.6 ymin: 5337828 xmax: 438487.1 ymax: 5343203
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata geometry
#> 1 1 POINT (436164 5337828)
#> 2 1 POINT (437141.6 5338038)
#> 3 1 POINT (437908.8 5339226)
#> 4 1 POINT (433367.2 5341317)
#> 5 1 POINT (434344.8 5341528)
#> 6 1 POINT (435112 5342716)
#> 7 1 POINT (436089.6 5342926)
#> 8 2 POINT (432529.9 5342241)
#> 9 2 POINT (432558.4 5341242)
#> 10 2 POINT (433529.5 5342270)
sample_sys_strat(
sraster = sr,
cellsize = 1000,
square = FALSE,
location = "corners"
)
#> Processing strata : 1
#> Warning: [extract] source already open for reading
#> Processing strata : 2
#> Warning: [extract] source already open for reading
#> Processing strata : 3
#> Warning: [extract] source already open for reading
#> Processing strata : 4
#> Warning: [extract] source already open for reading
#> Simple feature collection with 223 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431127.7 ymin: 5337718 xmax: 438206.3 ymax: 5343172
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata geometry
#> 1 1 POINT (438177.9 5338179)
#> 2 1 POINT (438177.9 5338179)
#> 3 1 POINT (437864.4 5338663)
#> 4 1 POINT (438127.5 5339177)
#> 5 1 POINT (438127.5 5339177)
#> 6 1 POINT (438077.1 5340176)
#> 7 1 POINT (437864.4 5338663)
#> 8 1 POINT (438177.9 5338179)
#> 9 1 POINT (437024.6 5338120)
#> 10 1 POINT (437864.4 5338663)