Skip to contents

This function creates a boundary matrix which is required if you want to use a boundary penalty in prioritizr

Usage

create_boundary_matrix(spatial_grid, patches, patch_df)

Arguments

spatial_grid

a raster or sf template with the desired resolution and coordinate reference system; values in areas of interest are 1, while all other values are NA (only required if feature is a sf object)

patches

a raster or sf object generated by create_patches(); a single feature split into spatially distinct groups; each layer of the raster or each column of the sf object identifies the location of each patch

patch_df

a dataframe generated by create_patch_df() that includes constraints for each patch and grid cell combination

Value

A sparse matrix

Examples

# Import some planning data

#import planning units/ cost raster
pu_raster <- terra::rast(system.file("extdata/pu_raster.tif", package = "patchwise"))
#import species distributions - feature data for planning
species_distributions <- terra::rast(system.file("extdata/spp_distributions.tif", package = "patchwise"))

#import seamounts
seamounts <- terra::rast(system.file("extdata/seamounts.tif", package = "patchwise"))

# Create seamount patches as multi-layer raster
patches_raster <- create_patches(seamounts)

patches_df <- create_patch_df(spatial_grid = pu_raster, features = species_distributions,
patches = patches_raster, costs = pu_raster)
#> Processing patch 1 of 3
#> Processing patch 2 of 3
#> Processing patch 3 of 3

#Create boundary matrix if you want to use a boundary penatly function in prioritizr
boundary_matrix <- create_boundary_matrix(spatial_grid = pu_raster, patches = patches_raster, patch_df = patches_df)