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

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

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

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

# S4 method for class '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

# Voronoi tesselation
sfa_boundaries
#> Simple feature collection with 4 features and 2 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -64.18658 ymin: 46.00004 xmax: -46.6269 ymax: 60.84333
#> Geodetic CRS:  WGS 84
#>   sfa                       geometry               area
#> 1   4 MULTIPOLYGON (((-59.36453 5...  47575648300 [m^2]
#> 2   5 MULTIPOLYGON (((-55 53.75, ...  62857719164 [m^2]
#> 3   6 MULTIPOLYGON (((-49.9269 49... 178716060645 [m^2]
#> 4   7 MULTIPOLYGON (((-54.48779 4... 147799572836 [m^2]
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")
#>   Casting data matrix into simple feature collection using columns: lon_dec, lat_dec
#> !  Warning: sspm is assuming WGS 84 CRS is to be used for casting
bounds_voronoi <- bounds %>%
  spm_discretize(method = "tesselate_voronoi",
                 with = biomass_dataset,
                 nb_samples = 10)
#>   Discretizing using method tesselate_voronoi

# 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())
         )
}