eliminatesmallpatches | R Documentation |
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.
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, ...)
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 |
... |
passed on to other methods |
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.
This function is only appropriate for use with categorical grids.
Ethan Plunkett
This relies on findsmallpatches
, patchscan
, and
nibbleNA
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.