eliminatesmallpatches: Eliminate small patches by replacing their cell content with...

eliminatesmallpatchesR Documentation

Eliminate small patches by replacing their cell content with the mode of nearby cell values.

Description

This function replaces the values in cells within small patches with values from neighboring cells not in the small patch. If targetclasses are specified it will only process cells within the supplied classes.

Usage

eliminatesmallpatches(x, maxsize, nr = 8, ...)  # generic function
## S3 method for class 'matrix'
eliminatesmallpatches(x, maxsize, nr = 8, targetclasses = NA,
na.replace.value = -99, ...)
## S3 method for class 'grid'
eliminatesmallpatches(x, maxsize, nr = 8, targetclasses = NA,
na.replace.value = -99, ...)

Arguments

x

A grid object

maxsize

patches of this size and smaller will be eliminated

nr

the neighbor rule; either 4 or 8 indicating the orthogonal neighbors, or orthogonal and diagonal; this is used to identify patches when determining which patches will be eliminated. Note, however, that when determining the replacement value the mode of all 8 neighbors is always used.

targetclasses

Set to NA to consider all patches. Otherwise set to values in x which will be considered eligable for elimination

na.replace.value

This value is used internally to replace NA's prior to nibbling. It is up to the user to make sure a value that doesn't occur in x is used.

...

passed on to other methods

Value

The function returns a object of the same class and dimensions as x in which all the small patches have been replaced with the mode of values from neighboring cells.

Note

This function is only appropriate for use with categorical grids.

Author(s)

Ethan Plunkett

See Also

This relies on findsmallpatches, patchscan, and nibbleNA

Examples

  set.seed(1)
  g <- asgrid(matrix(runif(n = 48)> .7, 6, 8), xll = 0, yll = 0, cellsize = 10)
  plot(g)
  plot(eliminatesmallpatches(g, 3, nr = 8))
  g$m[1, 1] <- NA

  plot(eliminatesmallpatches(g, 2, nr = 8))

  plot(eliminatesmallpatches(g, 2, nr = 4))  # 4 neighbor rule - diagonal connections don't count


ethanplunkett/gridprocess documentation built on Feb. 1, 2024, 2:24 a.m.