Generate relative class abundances of original (finer resolution) grid cells for scaled (coarser resolution) grid cells

relative_abundance_scaled_grid(x, class_field, scale_factor, verbose = FALSE)

Arguments

x

SpatRaster object with categorical data (factor)

class_field

field name in the attribute table of the raster to be used as class names

scale_factor

ratio of lower (scaled) resolution to higher (original) raster resolution (resolution of lower resolution divided by resolution of higher resolution)

verbose

bolean; if TRUE progress will be printed in console; default = FALSE

Value

A data frame with relative abundance of classes. The first two columns are x and y coordinates; all other columns are counts of cells for each class.

Examples

# load categorical raster
r <- terra::rast(system.file("extdata/nlm_mid_geom_r3_sa0.tif", package = "landscapeScaling"))

# subset the raster
r_sub <- terra::crop(r,terra::ext(0,300,0,300))

# generate relative abundance of original classes for a scaled grid with scale factor of 15
rel_abund <- relative_abundance_scaled_grid(r_sub,class_field='cover',scale_factor=15)

head(rel_abund)
#>    x y          A        B        C
#> 1  0 0  4.8888889 38.22222 56.88889
#> 2 15 0 10.2222222 38.66667 51.11111
#> 3 30 0 20.0000000 42.66667 37.33333
#> 4 45 0 24.8888889 40.44444 34.66667
#> 5 60 0  0.8888889 28.00000 71.11111
#> 6 75 0 17.7777778 37.33333 44.88889