apply_majority_rule {flexurba}R Documentation

Apply the majority rule algorithm

Description

The functions applies the majority rule to smooth edges of clusters of cells. The function supports two different version of the majority rule algorithm: the version of GHSL Data Package 2022 and GHSL Data Package 2023:

Usage

apply_majority_rule(
  x,
  version = "R2022A",
  permanent_water = NULL,
  land = NULL,
  pop = NULL
)

Arguments

x

SpatRaster. Grid with clusters of cells

version

character. Version of the majority rule algorithm. Supported versions are "R2022A" and "R2023A".

permanent_water

SpatRaster. Grid with permanent water cells (only required when version="R2023A")

land

SpatRaster. Grid with proportion of permanent land (only required when version="R2023A")

pop

SpatRaster. Grid with population (only required when version="R2023A")

Value

SpatRaster with clusters of cells with smoothed edges

Examples

nr <- nc <- 8
r <- terra::rast(nrows = nr, ncols = nc, ext = c(0, nc, 0, nr), vals = c(
  NA, NA, 1, 1, 1, NA, NA, NA,
  NA, NA, NA, 1, 1, NA, NA, NA,
  NA, NA, 2, NA, NA, NA, NA, NA,
  NA, NA, 2, NA, NA, 2, NA, NA,
  NA, NA, 2, NA, 2, 2, NA, NA,
  2, 2, 2, 2, 2, 2, NA, NA,
  NA, NA, 2, 2, NA, NA, NA, NA,
  NA, NA, NA, 2, NA, NA, NA, NA
))
terra::plot(r)
smoothed <- apply_majority_rule(r)
terra::plot(smoothed)

[Package flexurba version 0.2.2 Index]