Discretize 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 sspm_boundary,missing,ANY
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

# S4 method for sspm_boundary,ANY,missing
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

# S4 method for sspm_boundary,character,ANY
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

# S4 method for sspm_boundary,`function`,ANY
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

# S4 method for sspm_boundary,discretization_method,ANY
spm_discretize(boundary_object, method = "tesselate_voronoi", with = NULL, ...)

Arguments

boundary_object

[sspm] An object of class sspm_boundary.

method

[character OR method] Either a character from the list of available methods (see spm_methods for the list) OR an object of class discretization_method.

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 method.

Value

An object of class sspm_discrete_boundary (the updated and discretized sspm object given as input).

Details

Custom discretization functions can be written. The function must:

  1. 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).

  2. 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.

Examples

if (FALSE) {
# Voronoi tesselation
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())
         )
}

spm_discretize(boundary_object, method = custom_func)
}