Title: | Structurally Guided Sampling |
---|---|
Description: | Structurally guided sampling (SGS) approaches for airborne laser scanning (ALS; LIDAR). Primary functions provide means to generate data-driven stratifications & methods for allocating samples. Intermediate functions for calculating and extracting important information about input covariates and samples are also included. Processing outcomes are intended to help forest and environmental management practitioners better optimize field sample placement as well as assess and augment existing sample networks in the context of data distributions and conditions. ALS data is the primary intended use case, however any rasterized remote sensing data can be used, enabling data-driven stratifications and sampling approaches. |
Authors: | Tristan RH Goodbody [aut, cre, cph]
|
Maintainer: | Tristan RH Goodbody <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.4.5 |
Built: | 2025-01-30 04:09:06 UTC |
Source: | https://github.com/tgoodbody/sgsr |
Determine how many samples to allocate within strata.
calculate_allocation( sraster, nSamp, allocation = "prop", weights = NULL, mraster = NULL, existing = NULL, force = FALSE )
calculate_allocation( sraster, nSamp, allocation = "prop", weights = NULL, mraster = NULL, existing = NULL, force = FALSE )
sraster |
spatRaster. Stratification raster to be used for sampling. |
nSamp |
Numeric. Number of desired samples. |
allocation |
Character. Allocation algorithm to be used. Either |
weights |
Numeric. Only applicable when |
mraster |
spatRaster. ALS metric raster. Required when |
existing |
sf 'POINT' or data.frame. Existing plot network. |
force |
Logical. |
Returns a data.frame of:
strata - Strata ID.
total - Number of samples to be allocated. Values correspond to under representation (samples needed; positive value) or over representation
(too many samples; negative value) based on the nSamp
provided.
need - Required samples per strata based on allocation method. Rounded.
Tristan R.H. Goodbody
Gregoire, T.G., & Valentine, H.T. (2007). Sampling Strategies for Natural Resources and the Environment (1st ed.). Chapman and Hall/CRC. https://doi.org/10.1201/9780203498880
Other calculate functions:
calculate_allocation_existing()
,
calculate_coobs()
,
calculate_distance()
,
calculate_pcomp()
,
calculate_pop()
,
calculate_representation()
,
calculate_sampsize()
## Not run: #--- Load strata raster and existing samples---# r <- system.file("extdata", "sraster.tif", package = "sgsR") sr <- terra::rast(r) e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) #--- proportional allocation ---# calculate_allocation( sraster = sr, nSamp = 10, allocation = "prop" ) ## End(Not run)
## Not run: #--- Load strata raster and existing samples---# r <- system.file("extdata", "sraster.tif", package = "sgsR") sr <- terra::rast(r) e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) #--- proportional allocation ---# calculate_allocation( sraster = sr, nSamp = 10, allocation = "prop" ) ## End(Not run)
Perform the COunt of OBServations (coobs) algorithm using existing site data and raster metrics. This algorithm aids the user in determining where additional samples could be located by comparing existing samples to each pixel and associated covariates. The output coobs raster could be used to constrain clhs sampling to areas that are underreprented.
calculate_coobs( mraster, existing, cores = 1, threshold = 0.95, plot = FALSE, filename = NULL, overwrite = FALSE )
calculate_coobs( mraster, existing, cores = 1, threshold = 0.95, plot = FALSE, filename = NULL, overwrite = FALSE )
mraster |
spatRaster. ALS metrics raster. Requires at least 2 layers to calculate covariance matrix. |
existing |
sf 'POINT'. Existing plot network. |
cores |
Numeric. Number of cores to use for parallel processing. |
threshold |
Numeric. Proxy maximum pixel quantile to avoid outliers. |
plot |
Logical. Plots output strata raster and visualized strata with boundary dividers. |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
Output raster with coobs and classified coobs layers.
Special thanks to Dr. Brendan Malone for the original implementation of this algorithm.
Tristan R.H. Goodbody
Malone BP, Minasny B, Brungard C. 2019. Some methods to improve the utility of conditioned Latin hypercube sampling. PeerJ 7:e6451 DOI 10.7717/peerj.6451
Other calculate functions:
calculate_allocation()
,
calculate_allocation_existing()
,
calculate_distance()
,
calculate_pcomp()
,
calculate_pop()
,
calculate_representation()
,
calculate_sampsize()
## Not run: #--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) calculate_coobs( mraster = mr, existing = e, cores = 4 ) ## End(Not run)
## Not run: #--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) calculate_coobs( mraster = mr, existing = e, cores = 4 ) ## End(Not run)
Per pixel distance to nearest access vector. Intended to be used as a 'cost' constraint
within the sample_clhs
function
calculate_distance( raster, access, slope = FALSE, plot = FALSE, filename = NULL, overwrite = FALSE )
calculate_distance( raster, access, slope = FALSE, plot = FALSE, filename = NULL, overwrite = FALSE )
raster |
spatRaster. Raster to be used to calculate pixel level distance to access layer. |
access |
sf 'LINESTRING' or 'MULTILINESTRING'. Access network. |
slope |
Logical. Calculate slope distance instead of geographic distance. |
plot |
Logical. Plots output strata raster with samples. |
filename |
Character. Path to write output samples. |
overwrite |
Logical. Choice to overwrite existing |
Input raster with dist2access
layer appended.
Tristan R.H. Goodbody
Other calculate functions:
calculate_allocation()
,
calculate_allocation_existing()
,
calculate_coobs()
,
calculate_pcomp()
,
calculate_pop()
,
calculate_representation()
,
calculate_sampsize()
## Not run: #--- Load raster and access files ---# r <- system.file("extdata", "mraster_small.tif", package = "sgsR") mr <- terra::rast(r) a <- system.file("extdata", "access.shp", package = "sgsR") ac <- sf::st_read(a) calculate_distance( raster = mr, access = ac, ) ## End(Not run)
## Not run: #--- Load raster and access files ---# r <- system.file("extdata", "mraster_small.tif", package = "sgsR") mr <- terra::rast(r) a <- system.file("extdata", "access.shp", package = "sgsR") ac <- sf::st_read(a) calculate_distance( raster = mr, access = ac, ) ## End(Not run)
Population level analysis of metric raster data to determine optimal Latin Hypercube sample size
calculate_lhsOpt( mats, PCA = TRUE, quant = TRUE, KLdiv = TRUE, minSamp = 10, maxSamp = 100, step = 10, rep = 10, iter = 10000 )
calculate_lhsOpt( mats, PCA = TRUE, quant = TRUE, KLdiv = TRUE, minSamp = 10, maxSamp = 100, step = 10, rep = 10, iter = 10000 )
mats |
List. Output from |
PCA |
Logical. Calculates principal component loadings of the population for PCA similarity factor testing.
|
quant |
Logical. Perform quantile comparison testing. |
KLdiv |
Logical. Perform Kullback–Leibler divergence testing. |
minSamp |
Numeric. Minimum sample size to test. |
maxSamp |
Numeric. Maximum sample size to test. |
step |
Numeric. Sample step size for each iteration. |
rep |
Numeric. Internal repetitions for each sample size. |
iter |
Positive Numeric. The number of iterations for the Metropolis-Hastings
annealing process. Defaults to |
data.frame with summary statistics.
Special thanks to Dr. Brendan Malone for the original implementation of this algorithm.
Tristan R.H. Goodbody
Malone BP, Minasny B, Brungard C. 2019. Some methods to improve the utility of conditioned Latin hypercube sampling. PeerJ 7:e6451 DOI 10.7717/peerj.6451
## Not run: #--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- calculate lhsPop details ---# mats <- calculate_pop(mraster = mr) calculate_lhsOpt(mats = mats) calculate_lhsOpt( mats = mats, PCA = FALSE, iter = 200 ) ## End(Not run)
## Not run: #--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- calculate lhsPop details ---# mats <- calculate_pop(mraster = mr) calculate_lhsOpt(mats = mats) calculate_lhsOpt( mats = mats, PCA = FALSE, iter = 200 ) ## End(Not run)
Calculate and rasterize principal components from a metric raster
calculate_pcomp( mraster, nComp, center = TRUE, scale = TRUE, maxcells = Inf, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE, ... )
calculate_pcomp( mraster, nComp, center = TRUE, scale = TRUE, maxcells = Inf, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE, ... )
mraster |
spatRaster. ALS metrics raster. |
nComp |
Numeric. Value indicating number of principal components to be rasterized. |
center |
Logical. Value indicating whether the variables should be shifted to be zero centered. |
scale |
Logical. Value indicating whether the variables should be scaled to have unit variance. |
maxcells |
Numeric. Maximum number of samples to use to generate principal components.
For objects that are too large to feed into |
plot |
Logical. Plots output strata raster with samples. |
details |
Logical. If |
filename |
Character. Path to write output samples. |
overwrite |
Logical. Choice to overwrite existing |
... |
Additional arguments to be passed to |
Output raster with specified number of principal components as layers.
Tristan R.H. Goodbody
Other calculate functions:
calculate_allocation()
,
calculate_allocation_existing()
,
calculate_coobs()
,
calculate_distance()
,
calculate_pop()
,
calculate_representation()
,
calculate_sampsize()
#--- Load raster ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) calculate_pcomp( mraster = mr, nComp = 2 ) pcomp <- calculate_pcomp( mraster = mr, nComp = 3, details = TRUE ) #--- Display principal component details ---# # pcomp$pca #--- Display importance of components ---# # summary(pcomp$pca)
#--- Load raster ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) calculate_pcomp( mraster = mr, nComp = 2 ) pcomp <- calculate_pcomp( mraster = mr, nComp = 3, details = TRUE ) #--- Display principal component details ---# # pcomp$pca #--- Display importance of components ---# # summary(pcomp$pca)
Population matrices and descriptions of metric raster data
Calculates population level statistics including principal components, quantile matrix, and covariance matrix
needed necessary for calculate_lhsOpt
. Outputs can also be used as an input for sample_ahels
.
calculate_pop(mraster, PCA = FALSE, matQ = TRUE, nQuant = 10, matCov = TRUE)
calculate_pop(mraster, PCA = FALSE, matQ = TRUE, nQuant = 10, matCov = TRUE)
mraster |
spatRaster. ALS metrics raster. |
PCA |
Logical. Calculates principal component loadings of the population for PCA similarity factor testing.
|
matQ |
Logical. Calculates quantile matrix of the population for quantile comparison testing.
|
nQuant |
Numeric. Number of quantiles to divide the population into for |
matCov |
Logical. Calculates covariate matrix of the population. Needed for Kullback–Leibler divergence testing.
|
List of matrices to be used as input for calculate_lhsOpt
.
Special thanks to Dr. Brendan Malone for the original implementation of this algorithm.
Tristan R.H. Goodbody
Malone BP, Minasny B, Brungard C. 2019. Some methods to improve the utility of conditioned Latin hypercube sampling. PeerJ 7:e6451 DOI 10.7717/peerj.6451
Other calculate functions:
calculate_allocation()
,
calculate_allocation_existing()
,
calculate_coobs()
,
calculate_distance()
,
calculate_pcomp()
,
calculate_representation()
,
calculate_sampsize()
#--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) calculate_pop(mraster = mr)
#--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) calculate_pop(mraster = mr)
Compare sample representation within sraster strata
calculate_representation(sraster, existing, drop = NULL, plot = FALSE)
calculate_representation(sraster, existing, drop = NULL, plot = FALSE)
sraster |
spatRaster. Stratification raster. |
existing |
sf 'POINT'. Existing plot network. |
drop |
Numeric. Numeric value between 0-1 representing the |
plot |
Logical. Plot frequency of strata coverage and sampling coverage
for |
Calculate how sraster strata are represented in existing samples
Returns a tibble where:
strata - sraster
strata ID.
srasterFreq - sraster
coverage frequency.
sampleFreq - Sampling frequency within sraster
strata.
diffFreq - Difference between srasterFreq
& sampleFreq
. Positive values indicate over representation.
nSamp - Number of samples within each strata in existing
.
need - srasterFreq * sum(nSamp)
. Total theoretical number of required samples to be representative of strata coverage.
This values is rounded. It is important for the user to consider diffFreq
. A small difference - e.g. 1
in sampleFreq
vs. srasterFreq
frequency could make the algorithm allocate or remove samples that could likely be ignored.
Tristan R.H. Goodbody, Martin Queinnec
Other calculate functions:
calculate_allocation()
,
calculate_allocation_existing()
,
calculate_coobs()
,
calculate_distance()
,
calculate_pcomp()
,
calculate_pop()
,
calculate_sampsize()
### --- generate example stratification ---### #--- load ALS metrics from sgsR internal data ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") #--- read ALS metrics using the terra package ---# mraster <- terra::rast(r) #--- perform stratification ---# sraster <- strat_kmeans( mraster = mraster$zq90, nStrata = 6 ) ### --- create existing sample network ---### #--- simple random sampling ---# existing <- sample_srs( raster = mraster$zq90, nSamp = 100 ) #--- calculate representation ---# calculate_representation( sraster = sraster, existing = existing )
### --- generate example stratification ---### #--- load ALS metrics from sgsR internal data ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") #--- read ALS metrics using the terra package ---# mraster <- terra::rast(r) #--- perform stratification ---# sraster <- strat_kmeans( mraster = mraster$zq90, nStrata = 6 ) ### --- create existing sample network ---### #--- simple random sampling ---# existing <- sample_srs( raster = mraster$zq90, nSamp = 100 ) #--- calculate representation ---# calculate_representation( sraster = sraster, existing = existing )
Determine a samples size for simple random sampling using relative standard error
calculate_sampsize( mraster, rse = NULL, start = 0.01, end = 0.05, increment = 0.001, plot = FALSE )
calculate_sampsize( mraster, rse = NULL, start = 0.01, end = 0.05, increment = 0.001, plot = FALSE )
mraster |
spatRaster. Metrics raster. All values must be numeric. |
rse |
Numeric. Desired relative standard error (coefficient of variation of the mean) threshold to determine sample size. |
start |
Numeric. First rse value to begin rse sequence. default = |
end |
Numeric. Final rse value to end rse sequence. default = |
increment |
Numeric. Value to increment between |
plot |
Logical. if |
A data.frame of sample size and rse by raster variable.
Where:
SE
- Standard error of the mean
s
- Standard deviation of the observations
n
- Number of observations
Tristan R.H. Goodbody
Benedetti, R., Piersimoni, F., & Postiglione, P. (2015). Sampling spatial units for agricultural surveys. pp 202-203. Berlin: Springer.
Other calculate functions:
calculate_allocation()
,
calculate_allocation_existing()
,
calculate_coobs()
,
calculate_distance()
,
calculate_pcomp()
,
calculate_pop()
,
calculate_representation()
#--- Load raster ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) calculate_sampsize( mraster = mr, rse = 0.01 ) calculate_sampsize( mraster = mr ) calculate_sampsize( mraster = mr, rse = 0.025, start = 0.01, end = 0.08, increment = 0.01 ) #--- higher variance leads to need for more samples ---#
#--- Load raster ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) calculate_sampsize( mraster = mr, rse = 0.01 ) calculate_sampsize( mraster = mr ) calculate_sampsize( mraster = mr, rse = 0.025, start = 0.01, end = 0.08, increment = 0.01 ) #--- higher variance leads to need for more samples ---#
Extract metric values to existing samples
extract_metrics( mraster, existing, quiet = FALSE, data.frame = FALSE, filename = NULL, overwrite = FALSE )
extract_metrics( mraster, existing, quiet = FALSE, data.frame = FALSE, filename = NULL, overwrite = FALSE )
mraster |
spatRaster. Metrics Raster. |
existing |
sf 'POINT'. Existing plot network. |
quiet |
Logical. If |
data.frame |
Logical. Output as data.frame if |
filename |
Character. Path to write output samples. |
overwrite |
Logical. Choice to overwrite existing |
An sf or data.frame object of samples with metrics attributes.
If data.frame = TRUE
output will be written using write.table
Tristan R.H. Goodbody
Other extract functions:
extract_strata()
#--- Load mraster ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #' #--- load existing samples ---# e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) extract_metrics( mraster = mr, existing = e )
#--- Load mraster ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #' #--- load existing samples ---# e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) extract_metrics( mraster = mr, existing = e )
Extract stratum values to existing samples
extract_strata( sraster, existing, quiet = FALSE, data.frame = FALSE, filename = NULL, overwrite = FALSE )
extract_strata( sraster, existing, quiet = FALSE, data.frame = FALSE, filename = NULL, overwrite = FALSE )
sraster |
spatRaster. Stratification raster. |
existing |
sf 'POINT'. Existing plot network. |
quiet |
Logical. If |
data.frame |
Logical. Output as data.frame if |
filename |
Character. Path to write output samples. |
overwrite |
Logical. Choice to overwrite existing |
An sf or data.frame object of samples with strata attribute.
If data.frame = TRUE
output will be written using write.table
Tristan R.H. Goodbody
Other extract functions:
extract_metrics()
#--- Load sraster ---# r <- system.file("extdata", "sraster.tif", package = "sgsR") sr <- terra::rast(r) #--- load existing samples ---# e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) extract_strata( sraster = sr, existing = e )
#--- Load sraster ---# r <- system.file("extdata", "sraster.tif", package = "sgsR") sr <- terra::rast(r) #--- load existing samples ---# e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) extract_strata( sraster = sr, existing = e )
Perform the adapted Hypercube Evaluation of a Legacy Sample (ahels) algorithm using existing site data and raster metrics. New samples are allocated based on quantile ratios between the existing sample and covariate dataset.
sample_ahels( mraster, existing, nQuant = 10, nSamp = NULL, threshold = 0.9, tolerance = 0, matrices = NULL, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
sample_ahels( mraster, existing, nQuant = 10, nSamp = NULL, threshold = 0.9, tolerance = 0, matrices = NULL, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
mraster |
spatRaster. ALS metrics raster. |
existing |
sf 'POINT'. Existing plot network. |
nQuant |
Numeric. Number of quantiles to divide covariates and samples into. Quantiles that do not
cover at least 1 percent of the area of interest will be excluded and be returned as |
nSamp |
Numeric. Maximum number of new samples to allocate. |
threshold |
Numeric. Sample quantile ratio threshold. After the threshold |
tolerance |
Numeric. Allowable tolerance (<= 0.1 (10
added until the |
matrices |
List. Quantile and covariance matrices generated from |
plot |
Logical. Plots samples of type |
details |
Logical. If |
filename |
Character. Path to write output samples. |
overwrite |
Logical. Choice to overwrite existing |
Returns sf point object with existing samples and supplemental samples added by the ahels algorithm.
Messages in the algorithm will state that samples have been added to under-represented quantiles. The number between
square brackets that follow represent the matrix row and column respectively that can be printed using details = TRUE
.
In some cases, generally when a single metric is used as mraster
, sampling ratios all be >= 1 before the
nSamp
number of samples are allocated. The algorithm will stop in this scenario.
Special thanks to Dr. Brendan Malone for the original implementation of this algorithm.
Tristan R.H. Goodbody
Malone BP, Minasny B, Brungard C. 2019. Some methods to improve the utility of conditioned Latin hypercube sampling. PeerJ 7:e6451 DOI 10.7717/peerj.6451
Other sample functions:
sample_balanced()
,
sample_clhs()
,
sample_existing()
,
sample_nc()
,
sample_srs()
,
sample_strat()
,
sample_sys_strat()
,
sample_systematic()
## Not run: #--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) sample_ahels( mraster = mr, existing = e, plot = TRUE ) #--- supply quantile and covariance matrices ---# mat <- calculate_pop(mraster = mr) sample_ahels( mraster = mr, existing = e, matrices = mat, nSamp = 300 ) ## End(Not run)
## Not run: #--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) sample_ahels( mraster = mr, existing = e, plot = TRUE ) #--- supply quantile and covariance matrices ---# mat <- calculate_pop(mraster = mr) sample_ahels( mraster = mr, existing = e, matrices = mat, nSamp = 300 ) ## End(Not run)
Balanced raster sampling using lcube
and
lpm2_kdtree
methods
sample_balanced( mraster, nSamp, algorithm = "lpm2_kdtree", p = NULL, access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, filename = NULL, overwrite = FALSE )
sample_balanced( mraster, nSamp, algorithm = "lpm2_kdtree", p = NULL, access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, filename = NULL, overwrite = FALSE )
mraster |
spatRaster. ALS metrics raster. |
nSamp |
Numeric. Number of desired samples. |
algorithm |
Character. One of |
p |
Numeric. Vector with length equal to the number of cells in |
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 and visualized strata with boundary dividers. |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
An sf object with nSamp
samples.
Tristan R.H. Goodbody
Anton Grafström and Jonathan Lisic (2019). BalancedSampling: Balanced and Spatially Balanced Sampling. R package version 1.5.5. https://CRAN.R-project.org/package=BalancedSampling
Jonathan Lisic and Anton Grafström (2018). SamplingBigData: Sampling Methods for Big Data. R package version 1.0.0. https://CRAN.R-project.org/package=SamplingBigData
Grafström, A. Lisic, J (2018). BalancedSampling: Balanced and Spatially Balanced Sampling. R package version 1.5.4. http://www.antongrafstrom.se/balancedsampling
Other sample functions:
sample_ahels()
,
sample_clhs()
,
sample_existing()
,
sample_nc()
,
sample_srs()
,
sample_strat()
,
sample_sys_strat()
,
sample_systematic()
#--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) sample_balanced( mraster = mr, nSamp = 200 )
#--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) sample_balanced( mraster = mr, nSamp = 200 )
Conditioned Latin Hypercube Sampling using clhs
functionality.
sample_clhs( mraster, nSamp, iter = 10000, cost = NULL, existing = NULL, access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE, ... )
sample_clhs( mraster, nSamp, iter = 10000, cost = NULL, existing = NULL, access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE, ... )
mraster |
spatRaster. ALS metrics raster. |
nSamp |
Numeric. Number of desired samples. |
iter |
Numeric. Value giving the number of iterations within the Metropolis-Hastings process. |
cost |
Numeric/Character. Index or name of covariate within |
existing |
sf 'POINT'. Existing plot network. |
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. |
details |
Logical. If |
filename |
Character. Path to write output samples. |
overwrite |
Logical. Choice to overwrite existing |
... |
Additional arguments for clhs sampling. See |
An sf object with nSamp
stratified samples.
Tristan R.H. Goodbody
Minasny, B. and McBratney, A.B. 2006. A conditioned Latin hypercube method for sampling in the presence of ancillary information. Computers and Geosciences, 32:1378-1388.
Minasny, B. and A. B. McBratney, A.B.. 2010. Conditioned Latin Hypercube Sampling for Calibrating Soil Sensor Data to Soil Properties. In: Proximal Soil Sensing, Progress in Soil Science, pages 111-119.
Roudier, P., Beaudette, D.E. and Hewitt, A.E. 2012. A conditioned Latin hypercube sampling algorithm incorporating operational constraints. In: Digital Soil Assessments and Beyond. Proceedings of the 5th Global Workshop on Digital Soil Mapping, Sydney, Australia.
Other sample functions:
sample_ahels()
,
sample_balanced()
,
sample_existing()
,
sample_nc()
,
sample_srs()
,
sample_strat()
,
sample_sys_strat()
,
sample_systematic()
#--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) a <- system.file("extdata", "access.shp", package = "sgsR") ac <- sf::st_read(a) sample_clhs( mraster = mr, nSamp = 200, plot = TRUE, iter = 100 ) sample_clhs( mraster = mr, nSamp = 400, existing = e, iter = 250, details = TRUE )
#--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) e <- system.file("extdata", "existing.shp", package = "sgsR") e <- sf::st_read(e) a <- system.file("extdata", "access.shp", package = "sgsR") ac <- sf::st_read(a) sample_clhs( mraster = mr, nSamp = 200, plot = TRUE, iter = 100 ) sample_clhs( mraster = mr, nSamp = 400, existing = e, iter = 250, details = TRUE )
Sub-sample an existing sample. Four sampling methods are available:
clhs
, balanced
, srs
and strat
.
sample_existing( existing, nSamp, raster = NULL, type = "clhs", access = NULL, buff_inner = NULL, buff_outer = NULL, details = FALSE, filename = NULL, overwrite = FALSE, ... )
sample_existing( existing, nSamp, raster = NULL, type = "clhs", access = NULL, buff_inner = NULL, buff_outer = NULL, details = FALSE, filename = NULL, overwrite = FALSE, ... )
existing |
sf 'POINT'. Existing plot network. |
nSamp |
Numeric. Number of desired samples. |
raster |
SpatRaster. Raster to guide the location of the samples. If |
type |
Character. A string indicating the type of sampling method to use.
Possible values are |
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 |
filename |
Character. Path to write output samples. |
overwrite |
Logical. Choice to overwrite existing |
... |
Additional arguments for the sampling method selected. |
An sf object of samples or a list object if details = TRUE
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.
Tristan R.H. Goodbody
Other sample functions:
sample_ahels()
,
sample_balanced()
,
sample_clhs()
,
sample_nc()
,
sample_srs()
,
sample_strat()
,
sample_sys_strat()
,
sample_systematic()
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 ) #--- perform balanced sub-sampling ---# sample_existing( existing = e, nSamp = 50, type = "balanced" ) #--- perform simple random sub-sampling ---# sample_existing( existing = e, nSamp = 50, type = "srs" )
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 ) #--- perform balanced sub-sampling ---# sample_existing( existing = e, nSamp = 50, type = "balanced" ) #--- perform simple random sub-sampling ---# sample_existing( existing = e, nSamp = 50, type = "srs" )
Sampling using the nearest centroid (NC) approach described in Melville & Stone (2016).
sample_nc( mraster, nSamp, k = 1, iter = 500, algorithm = "Lloyd", access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
sample_nc( mraster, nSamp, k = 1, iter = 500, algorithm = "Lloyd", access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
mraster |
spatRaster. ALS metrics raster. |
nSamp |
Numeric. Number of desired samples. |
k |
Numeric. The number of nearest neighbours to take for each k-means center.
When |
iter |
Numeric. The maximum number of kmeans iterations allowed. |
algorithm |
Character. |
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. Plot |
details |
Logical. If |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
An sf object with nSamp
randomly sampled points.
When details = TRUE
, a list is returned where:
samples
output nearest centroid samples with kcenter
attribute linking
to associated kmeans centers.
kmeans
is a list output of the kmeans
function
centers
Un-scaled kmeans center values for each layer in mraster
with kcenter
attribute to link with the same attribute in samples
.
kplot
is a ggplot
scatterplot object visualizing the kmeans centers
and associated nearest neighbor samples.
Tristan R.H. Goodbody
G. Melville & C. Stone (2016) Optimising nearest neighbour information—a simple, efficient sampling strategy for forestry plot imputation using remotely sensed data, Australian Forestry, 79:3, 217-228, DOI: 10.1080/00049158.2016.1218265
Other sample functions:
sample_ahels()
,
sample_balanced()
,
sample_clhs()
,
sample_existing()
,
sample_srs()
,
sample_strat()
,
sample_sys_strat()
,
sample_systematic()
#--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- perform simple random sampling ---# sample_nc( mraster = mr, nSamp = 5, )
#--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- perform simple random sampling ---# sample_nc( mraster = mr, nSamp = 5, )
Randomly sample within a stratification raster extent.
sample_srs( raster, nSamp, mindist = NULL, access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, filename = NULL, overwrite = FALSE )
sample_srs( raster, nSamp, mindist = NULL, access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, filename = NULL, overwrite = FALSE )
raster |
spatRaster. Raster to be used for random sampling. |
nSamp |
Numeric. Number of desired samples. |
mindist |
Numeric. Minimum allowable distance between selected
samples. |
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 |
An sf object with nSamp
randomly sampled points.
Tristan R.H. Goodbody & Martin Queinnec
Other sample functions:
sample_ahels()
,
sample_balanced()
,
sample_clhs()
,
sample_existing()
,
sample_nc()
,
sample_strat()
,
sample_sys_strat()
,
sample_systematic()
#--- 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) #--- perform simple random sampling ---# sample_srs( raster = sr, nSamp = 200, )
#--- 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) #--- perform simple random sampling ---# sample_srs( raster = sr, nSamp = 200, )
Sampling based on a stratified raster.
sample_strat( sraster, nSamp, allocation = "prop", method = "Queinnec", weights = NULL, force = FALSE, mraster = NULL, mindist = NULL, existing = NULL, include = FALSE, remove = FALSE, access = NULL, buff_inner = NULL, buff_outer = NULL, wrow = 3, wcol = 3, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
sample_strat( sraster, nSamp, allocation = "prop", method = "Queinnec", weights = NULL, force = FALSE, mraster = NULL, mindist = NULL, existing = NULL, include = FALSE, remove = FALSE, access = NULL, buff_inner = NULL, buff_outer = NULL, wrow = 3, wcol = 3, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
sraster |
spatRaster. Stratification raster to be used for sampling. |
nSamp |
Numeric. Number of desired samples. |
allocation |
Character. Allocation algorithm to be used. Either |
method |
Character. Sampling design approach |
weights |
Numeric. Only applicable when |
force |
Logical. |
mraster |
spatRaster. ALS metric raster. Required when |
mindist |
Numeric. Minimum allowable distance between selected
samples. |
existing |
sf 'POINT' or data.frame. Existing plot network. |
include |
Logical. If |
remove |
Logical. If |
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. |
wrow |
Numeric. Number of row in the focal window ( |
wcol |
Numeric. Number of columns in the focal window ( |
plot |
Logical. Plots samples of type 'existing' (if provided; croses) and 'new' (circles) along with |
details |
Logical. If |
filename |
Character. Path to write output samples. |
overwrite |
Logical. Choice to overwrite existing |
An sf object with nSamp
stratified samples.
The sampling is performed in 2 stages when method = "Queinnec"
:
Rule 1
- Sample within grouped stratum pixels defined within the
wrow, wcol
parameters
Rule 2
- If no samples exist to satisfy Rule 1
individual stratum pixels are sampled.
The rule applied to allocate each sample is defined in the rule
attribute of output samples.
existing
may contain samples that fall in sraster
cells that are 'NA'. If this occurs and include = TRUE
, 'NA' samples
are separated during sampling and re-appended at the end of the sampling process.
If the sraster
provided contains factor values, the algorithm will automatically convert these into the numeric factor levels and
perform sampling using those values. The categories (factor values) will be extracted and appended to the algorithm output as the 'category' attribute.
Tristan R.H. Goodbody & Martin Queinnec
Queinnec, M., White, J. C., & Coops, N. C. (2021). Comparing airborne and spaceborne photon-counting LiDAR canopy structural estimates across different boreal forest types. Remote Sensing of Environment, 262 (August 2020), 112510. https://doi.org/10.1016/j.rse.2021.112510
Other sample functions:
sample_ahels()
,
sample_balanced()
,
sample_clhs()
,
sample_existing()
,
sample_nc()
,
sample_srs()
,
sample_sys_strat()
,
sample_systematic()
#--- Load raster and access files ---# r <- system.file("extdata", "sraster.tif", package = "sgsR") sr <- terra::rast(r) #--- perform stratified sampling random sampling ---# sraster <- sample_strat( sraster = sr, nSamp = 50 )
#--- Load raster and access files ---# r <- system.file("extdata", "sraster.tif", package = "sgsR") sr <- terra::rast(r) #--- perform stratified sampling random sampling ---# sraster <- sample_strat( sraster = sr, nSamp = 50 )
Systematic stratified sampling with random start point and translation within a square or hexagonal tessellation for each stratum.
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 )
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 )
sraster |
spatRaster. Stratified raster with name |
cellsize |
Numeric. Desired cellsize for tessellation. |
square |
Logical. Tessellation shape. Default is regular square grid,
if |
location |
Character. Sample location within tessellation. |
force |
Logical. Only applies when |
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 |
details |
Logical. If |
An sf object with sampled points over unique tessellations.
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.
Tristan R.H. Goodbody
Other sample functions:
sample_ahels()
,
sample_balanced()
,
sample_clhs()
,
sample_existing()
,
sample_nc()
,
sample_srs()
,
sample_strat()
,
sample_systematic()
#--- 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 ) sample_sys_strat( sraster = sr, cellsize = 1000, square = FALSE, location = "corners" )
#--- 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 ) sample_sys_strat( sraster = sr, cellsize = 1000, square = FALSE, location = "corners" )
Systematic sampling with random start point and translation within a square or hexagonal tessellation.
sample_systematic( raster, cellsize, square = TRUE, location = "centers", force = FALSE, access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, filename = NULL, overwrite = FALSE, details = FALSE, ... )
sample_systematic( raster, cellsize, square = TRUE, location = "centers", force = FALSE, access = NULL, buff_inner = NULL, buff_outer = NULL, plot = FALSE, filename = NULL, overwrite = FALSE, details = FALSE, ... )
raster |
spatRaster. Raster used to define extent of fishnet grid. |
cellsize |
Numeric. Desired cellsize for tessellation. |
square |
Logical. Tessellation shape. Default is regular square grid,
if |
location |
Character. Sample location within tessellation. |
force |
Logical. Only applies when |
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 |
details |
Logical. If |
... |
Additional arguments for |
An sf object with sampled points over a tessellation.
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.
Tristan R.H. Goodbody, Lukas Winiwarter
Other sample functions:
sample_ahels()
,
sample_balanced()
,
sample_clhs()
,
sample_existing()
,
sample_nc()
,
sample_srs()
,
sample_strat()
,
sample_sys_strat()
#--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- perform grid sampling ---# sample_systematic( raster = mr, cellsize = 1000 ) sample_systematic( raster = mr, cellsize = 1000, location = "corners", plot = TRUE ) sample_systematic( raster = mr, cellsize = 1000, square = FALSE, location = "random", plot = TRUE )
#--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- perform grid sampling ---# sample_systematic( raster = mr, cellsize = 1000 ) sample_systematic( raster = mr, cellsize = 1000, location = "corners", plot = TRUE ) sample_systematic( raster = mr, cellsize = 1000, square = FALSE, location = "random", plot = TRUE )
Stratify metrics raster using user defined breaks
strat_breaks( mraster, breaks, map = FALSE, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
strat_breaks( mraster, breaks, map = FALSE, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
mraster |
Spatraster. Raster to stratify. Layers in |
breaks |
Numeric. Vector of breakpoints for each layer of |
map |
Logical. Map individual stratified layers to a combined stratification. Will output a multi-layer
|
plot |
Logical. Plots output strata raster and visualized strata with boundary dividers. |
details |
Logical. If |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
Returns an output stratification spatRaster
or a list when details = TRUE
.
When a list is returned:
raster
is a stratified spatRaster
based on quantiles. If stack = TRUE
will
be the number of layers of mraster
plus the final output
breaks
is a list output of breaks
plot
is a ggplot
histogram object showing distribution(s) and break point(s).
Tristan R.H. Goodbody
Other stratify functions:
strat_kmeans()
,
strat_map()
,
strat_poly()
,
strat_quantiles()
#--- Load raster ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- create vector breaks ---# br.zq90 <- c(3, 5, 11, 18) br.pz2 <- c(20, 40, 60, 80) strat_breaks( mraster = mr$zq90, breaks = br.zq90 ) strat_breaks( mraster = mr[[1:2]], breaks = list(br.zq90, br.pz2), details = TRUE )
#--- Load raster ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- create vector breaks ---# br.zq90 <- c(3, 5, 11, 18) br.pz2 <- c(20, 40, 60, 80) strat_breaks( mraster = mr$zq90, breaks = br.zq90 ) strat_breaks( mraster = mr[[1:2]], breaks = list(br.zq90, br.pz2), details = TRUE )
Stratify metrics raster using kmeans
algorithm
strat_kmeans( mraster, nStrata, iter = 500, algorithm = "Lloyd", center = TRUE, scale = TRUE, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE, ... )
strat_kmeans( mraster, nStrata, iter = 500, algorithm = "Lloyd", center = TRUE, scale = TRUE, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE, ... )
mraster |
spatRaster. ALS metrics raster. |
nStrata |
Numeric. Number of desired strata. |
iter |
Numeric. The maximum number of iterations allowed. |
algorithm |
Character. |
center |
Logical. Value indicating whether the variables should be shifted to be zero centered. |
scale |
Logical. Value indicating whether the variables should be scaled to have unit variance. |
plot |
Logical. Plots output strata raster and visualized strata with boundary dividers. |
details |
Logical. If |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
... |
Additional arguments to be passed to |
output stratification spatRaster
, or a list when details = TRUE
.
Tristan R.H. Goodbody
Other stratify functions:
strat_breaks()
,
strat_map()
,
strat_poly()
,
strat_quantiles()
#--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- perform stratification using k-means ---# kmeans <- strat_kmeans( mraster = mr, nStrata = 5 ) kmeans <- strat_kmeans( mraster = mr, nStrata = 5, iter = 1000, algorithm = "MacQueen", details = TRUE )
#--- Load raster and access files ---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) #--- perform stratification using k-means ---# kmeans <- strat_kmeans( mraster = mr, nStrata = 5 ) kmeans <- strat_kmeans( mraster = mr, nStrata = 5, iter = 1000, algorithm = "MacQueen", details = TRUE )
Map stratified rasters to a combined stratification.
strat_map( sraster, stack = FALSE, filename = NULL, overwrite = FALSE, plot = FALSE, details = FALSE )
strat_map( sraster, stack = FALSE, filename = NULL, overwrite = FALSE, plot = FALSE, details = FALSE )
sraster |
spatRaster or list. Stratification raster stack or list of rasters. If |
stack |
Logical. Default = |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
plot |
Logical. Plots output strata raster and visualized strata with boundary dividers. |
details |
Logical. If |
A spatRaster object.
The mapping algorithm will take the stratification from sraster
and combine it with
overlying strata values across all layers. This will result in a strata
attribute
where the values from all inputs are combined.
i.e.
If strata_1 = 1
and strata_2 = 1
then strata = 11
.
If strata_1 = 2
and strata_2 = 14
then strata = 214
.
If strata_1 = "A"
and strata_2 = 14
then strata = "A14"
.
Tristan R.H. Goodbody, Tommaso Trotto, Robert Hijmans
Other stratify functions:
strat_breaks()
,
strat_kmeans()
,
strat_poly()
,
strat_quantiles()
#--- load input metrics rasters ---# raster <- system.file("extdata", "sraster.tif", package = "sgsR") sraster <- terra::rast(raster) #--- read polygon coverage ---# poly <- system.file("extdata", "inventory_polygons.shp", package = "sgsR") fri <- sf::st_read(poly) #--- stratify polygon coverage ---# #--- specify polygon attribute to stratify ---# attribute <- "NUTRIENTS" #--- specify features within attribute & how they should be grouped ---# #--- as a single vector ---# features <- c("poor", "rich", "medium") srasterfri <- strat_poly( poly = fri, attribute = attribute, features = features, raster = sraster ) #--- map srasters with raster stack ---# stack <- c(srasterfri, sraster) strat_map( sraster = stack ) #--- map sraster with list of rasters ---# rast_list <- list(srasterfri, sraster) strat_map( sraster = rast_list, stack = TRUE, details = TRUE )
#--- load input metrics rasters ---# raster <- system.file("extdata", "sraster.tif", package = "sgsR") sraster <- terra::rast(raster) #--- read polygon coverage ---# poly <- system.file("extdata", "inventory_polygons.shp", package = "sgsR") fri <- sf::st_read(poly) #--- stratify polygon coverage ---# #--- specify polygon attribute to stratify ---# attribute <- "NUTRIENTS" #--- specify features within attribute & how they should be grouped ---# #--- as a single vector ---# features <- c("poor", "rich", "medium") srasterfri <- strat_poly( poly = fri, attribute = attribute, features = features, raster = sraster ) #--- map srasters with raster stack ---# stack <- c(srasterfri, sraster) strat_map( sraster = stack ) #--- map sraster with list of rasters ---# rast_list <- list(srasterfri, sraster) strat_map( sraster = rast_list, stack = TRUE, details = TRUE )
Stratify based on polygon coverage attributes and features.
strat_poly( poly, attribute, features, raster, filename = NULL, overwrite = FALSE, plot = FALSE, details = FALSE )
strat_poly( poly, attribute, features, raster, filename = NULL, overwrite = FALSE, plot = FALSE, details = FALSE )
poly |
sf. Input polygon coverage. e.g. - forest resources inventory coverage. |
attribute |
Character. Name of attribute within |
features |
Vector / list of vectors. Features within |
raster |
spatRaster. Raster template to enable polygon to raster conversion. |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
plot |
Logical. Plots output spatRaster. |
details |
Logical. If |
A spatRaster object.
Tristan R.H. Goodbody
Other stratify functions:
strat_breaks()
,
strat_kmeans()
,
strat_map()
,
strat_quantiles()
#--- load input metrics raster ---# raster <- system.file("extdata", "sraster.tif", package = "sgsR") sraster <- terra::rast(raster) #--- read polygon coverage ---# poly <- system.file("extdata", "inventory_polygons.shp", package = "sgsR") fri <- sf::st_read(poly) #--- stratify polygon coverage ---# #--- specify polygon attribute to stratify ---# attribute <- "NUTRIENTS" #--- specify features within attribute & how they should be grouped ---# #--- as a single vector ---# features <- c("poor", "rich", "medium") srasterpoly <- strat_poly( poly = fri, attribute = attribute, features = features, raster = sraster ) #--- or as multiple lists ---# g1 <- "poor" g2 <- c("rich", "medium") features <- list(g1, g2) srasterpoly <- strat_poly( poly = fri, attribute = attribute, features = features, raster = sraster, details = TRUE )
#--- load input metrics raster ---# raster <- system.file("extdata", "sraster.tif", package = "sgsR") sraster <- terra::rast(raster) #--- read polygon coverage ---# poly <- system.file("extdata", "inventory_polygons.shp", package = "sgsR") fri <- sf::st_read(poly) #--- stratify polygon coverage ---# #--- specify polygon attribute to stratify ---# attribute <- "NUTRIENTS" #--- specify features within attribute & how they should be grouped ---# #--- as a single vector ---# features <- c("poor", "rich", "medium") srasterpoly <- strat_poly( poly = fri, attribute = attribute, features = features, raster = sraster ) #--- or as multiple lists ---# g1 <- "poor" g2 <- c("rich", "medium") features <- list(g1, g2) srasterpoly <- strat_poly( poly = fri, attribute = attribute, features = features, raster = sraster, details = TRUE )
Stratify metric raster using metric quantiles.
strat_quantiles( mraster, nStrata, map = FALSE, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
strat_quantiles( mraster, nStrata, map = FALSE, plot = FALSE, details = FALSE, filename = NULL, overwrite = FALSE )
mraster |
spatRaster. ALS metrics raster. |
nStrata |
Numeric. A positive integer representing the number of desired classes
or a numeric vector of probabilities with values between |
map |
Logical. Map individual stratified layers to a combined stratification. Will output a multi-layer
|
plot |
Logical. Plots output strata raster and visualized strata with boundary dividers. |
details |
Logical. If |
filename |
Character. Path to write stratified raster to disc. |
overwrite |
Logical. Specify whether |
Returns an output stratification spatRaster
or a list when details = TRUE
.
When a list is returned:
details
lookUp table for stratification(s).
raster
is a stratified spatRaster
based on quantiles
plot
is a ggplot
histogram / scatter plot object (depends on whether metric2 was supplied).
Histogram shows distribution and break points.
Tristan R.H. Goodbody
Other stratify functions:
strat_breaks()
,
strat_kmeans()
,
strat_map()
,
strat_poly()
#--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) strat_quantiles( mraster = mr$zq90, nStrata = 4 ) strat_quantiles( mraster = mr[[1:2]], nStrata = list(c(0.2, 0.4, 0.8), 3), map = TRUE )
#--- Load raster and existing plots---# r <- system.file("extdata", "mraster.tif", package = "sgsR") mr <- terra::rast(r) strat_quantiles( mraster = mr$zq90, nStrata = 4 ) strat_quantiles( mraster = mr[[1:2]], nStrata = list(c(0.2, 0.4, 0.8), 3), map = TRUE )