clump,GRaster-method | R Documentation |
clump()
identifies groups of adjacent cells that have the same value or same approximate value, and assigns them a unique number, creating "clumps" of same- or similar-valued cells.
## S4 method for signature 'GRaster'
clump(x, minDiff = 0, minClumpSize = 1, diagonal = TRUE)
x |
A |
minDiff |
Numeric in the range [0, 1): Minimum difference between cells in order for them to be assigned to the same clump. This is a proportion of the range across all cells. For example, if |
minClumpSize |
Numeric integer >= 1. Minimum number of cells in a clump. The default is 1. |
diagonal |
Logical: If |
A GRaster
.
if (grassStarted()) {
# Setup
library(sf)
library(terra)
# Elevation raster
madElev <- fastData("madElev")
# Convert a SpatRaster to a GRaster:
elev <- fast(madElev)
# Find clumps based on exact values. This will appear as a gradient because
# most cells are assigned to a group of 1 cell.
exact <- clump(elev)
plot(exact)
# Clump based on approximate values:
approx <- clump(elev, minDiff = 0.0075)
plot(approx)
# Clump based on approximate values with minimum clump size:
approx20 <- clump(elev, minDiff = 0.005, minClumpSize = 20)
plot(approx20)
approx
approx20
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.