nh_patchdrop: Remove contiguous patches smaller than a given patch size...

View source: R/nh_patchdrop.R

nh_patchdropR Documentation

Remove contiguous patches smaller than a given patch size from binary output

Description

Takes a binary/thresholded raster (values either NA, 0, or 1), and returns a binary raster. Clumps of contiguous cells with the value (1) that are smaller than the min.patch size are given updatevalue (default = 0).

Usage

nh_patchdrop(
  spf = NULL,
  rast,
  min.patch = NULL,
  directions = 8,
  updatevalue = 0
)

Arguments

spf

input spatial features (sp or sf spatial object)

rast

input binary raster output (values either NA/0 or 1)

min.patch

area of minimum patch size, in area units used in rast

directions

Integer. Which cells are considered adjacent? Should be 8 (default; Queen's case) or 4 (Rook's case). From terra::patches

updatevalue

Integer or NA. Value to apply to cells which do not meet the min.patch size. Default = 0.

Details

If 'spf' is given, the smallest feature's area will be used to derive a min.patch value, and any given 'min.patch' is ignored. If 'spf' is not given, a 'min.patch' value must be given, in area units of the input raster.

Value

SpatRaster

Author(s)

David Bucklin

Examples

## Not run: 
spf <- sf::st_read("_data/occurrence/ambymabe.shp")
rast <- terra::rast("_data/species/ambymabe/outputs/model_predictions/ambymabe_20171018_130837.tif")
values(rast) <- ifelse(values(rast) > 0.9, 1, NA)

# use minimum patch size from presence features
rast_contig_minpres <- nh_patchdrop(spf, rast)

# use a minimum patch size of 10000 (in units from 'rast')
rast_contig_10km <- nh_patchdrop(rast = rast, min.patch = 10000)

## End(Not run)

VANatHeritage/nhSDM documentation built on Feb. 1, 2024, 6:39 a.m.