View source: R/dsmartr_prepare.R
prep_polygons | R Documentation |
Prepares soil map inputs for use in
dsmartr::iterate()
.
prep_polygons(
src_map = NULL,
covariates = NULL,
id_field = NULL,
sample_method = c("flat", "area_p"),
sample_rate = NULL,
rate_floor = NULL,
rate_ceiling = NULL
)
src_map |
An sfc_POLYGON/MULTIPOLYGON or SpatialPolygonsDataFrame object representing the soil map to be disaggregated. Format requirements:
Other columns may exist in the object; they will be ignored. |
covariates |
RasterStack or RasterBrick; environmental covariate datasets. |
id_field |
String; name of unique identifier field in |
sample_method |
String; choice of flat rate per polygon or area-proportional rate. |
sample_rate |
Integer; Number of samples per polygon. |
rate_floor |
Integer; desired minimum number of samples per polygon.
Optional; used with |
rate_ceiling |
Integer; desired maximum number of samples per polygon.
Optional; use with |
A data frame holding polygon input attributes and four new attribute columns:
area_sqkm
: Polygon area in square kilometers, by
sf::st_area()
.
n_soils
: The number of soil classes within the map unit.
n_samples
: The number of environmental covariate point samples
that will be taken on each model iteration.
intersecting_cells
: Raster cell index numbers for any cell
whose center falls within the polygon boundary.
Outputs are also written to disk.
The output of this function is a required input for
dsmartr::iterate()
.
Covariate data should be in a projected CRS with defined units. While the function will run with lat/long data, polygon area calculations may be dangerously inaccurate. Vector inputs will be transformed to match the covariate CRS.
The intersecting_cells
attribute field is a list-column, so
the returned object cannot be written to e.g. csv format.
This function runs faster with a RasterBrick than a Stack.
## Not run:
data('heronvale_soilmap')
data('heronvale_covariates')
# flat rate
pr_flat <- prep_polygons(src_map = heronvale_soilmap,
covariates = heronvale_covariates,
id_field = 'POLY_NO', sample_method = 'flat',
sample_rate = 6)
# area_proportional rate with floor
pr_ap <- prep_polygons(src_map = heronvale_soilmap,
covariates = heronvale_covariates,
id_field = 'POLY_NO', sample_method = 'area_p',
sample_rate = 20, rate_floor = 6)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.