spm_discretize | R Documentation |
sspm
model objectDiscretize a sspm model object with a function from a discretization_method object class. This function divides the boundary polygons into smaller patches.
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)
## S4 method for signature 'sspm_boundary,missing,ANY'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)
## S4 method for signature 'sspm_boundary,ANY,missing'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)
## S4 method for signature 'sspm_boundary,character,ANY'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)
## S4 method for signature 'sspm_boundary,function,ANY'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)
## S4 method for signature 'sspm_boundary,discretization_method,ANY'
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)
boundary_object |
[sspm] An object of class sspm_boundary. |
method |
[character OR method]
Either a |
with |
[sspm_dataset OR sf] Either an object of class sspm_dataset or a set of custom points. |
... |
[named list] Further arguments to be passed onto the function
used in |
Custom discretization functions can be written. The function must:
Accept at least 1 argument: boundaries (the sf
boundary object),
and optionnaly with (can be NULL) a separate object to be used for
discretization and boundary, the boundary column of
boundaries (these last 2 arguments are passed and connot be
overwritten but could be ignored).
Returns a named list with 2 elements: patches
. an sf
object that
stores the discretized polygons, and points
, an sf
object that
stores the points that were used for discretization.
An object of class sspm_discrete_boundary (the updated
and discretized sspm
object given as input).
# Voronoi tesselation
sfa_boundaries
bounds <- spm_as_boundary(boundaries = sfa_boundaries,
boundary = "sfa")
biomass_dataset <- spm_as_dataset(data.frame(borealis_simulated), name = "borealis",
density = "weight_per_km2",
time = "year_f",
coords = c('lon_dec','lat_dec'),
uniqueID = "uniqueID")
bounds_voronoi <- bounds %>%
spm_discretize(method = "tesselate_voronoi",
with = biomass_dataset,
nb_samples = 10)
# Custom method
custom_func <- function(boundaries, ...){
args <- list(...)
# Can access passed arguments with args$arg_name
# Do your custom discretization
# Careful: must return sf objects!
return(list(patches = c(),
points = c())
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.