nh_patchdrop | R Documentation |
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).
nh_patchdrop(
spf = NULL,
rast,
min.patch = NULL,
directions = 8,
updatevalue = 0
)
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 |
directions |
Integer. Which cells are considered adjacent? Should be 8 (default; Queen's case) or 4 (Rook's case). From |
updatevalue |
Integer or NA. Value to apply to cells which do not meet the min.patch size. Default = 0. |
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.
SpatRaster
David Bucklin
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.