strucDiv {StrucDiv} | R Documentation |
Quantify Spatial Structural Diversity in an Arbitrary Raster Layer
Description
This is a wrapper function that returns a 'spatial structural diversity map'
as a raster layer. Spatial refers to horizontal, i.e. spatially explicit, and
'spatial structural diversity' will hereafter be used synonymous to 'structural diversity'.
Pixels are considered as pairs in user-specified distances and angles.
Angles include horizontal and vertical direction, and the diagonals at 45° and 135°.
The direction-invariant version considers all angles.
The frequencies of pixel pairs are normalized by the total number of pixel pairs,
which returns the gray level co-occurrence matrix (GLCM).
The GLCM contains the empirical probabilities that pixel values are arranged in the specified way (distance and angle).
The total number of pixel pairs depends on the extent of the area within which pixel pairs are counted, i.e. on the spatial scale.
The spatial scale is defined by the window side length (wsl
) of a moving window.
The values in a GLCM are the same values that occur in the area within which pixel pairs were counted,
therefore they can differ between GLCMs.
In each GLCM, pixel values can be replaced with ranks.
Structural diversity metrics are calculated on every element of the GLCM,
their sum is assigned to the center pixel of the moving window
and represents spatial structural diversity of the area captured by the moving window.
The final map is called a '(spatial) structural diversity map' and is returned as a raster layer
with the same dimensions as the input raster.
Usage
strucDiv(
x,
wsl,
dist = 1,
angle = "all",
rank = FALSE,
fun,
delta = 0,
na.handling = na.pass,
padValue = NA,
aroundTheGlobe = FALSE,
filename = "",
verbose = TRUE,
...
)
Arguments
x |
raster layer. Input raster layer for which spatial structural diversity should be calculated. |
wsl |
uneven integer. The window side length,
|
dist |
integer. The distance between two pixels that should be considered as a pair,
defaults to |
angle |
string. The angle on which pixels should be considered as pairs.
Takes 5 options: |
rank |
logical. Should pixel values be replaced with ranks in each GLCM? Defaults to |
fun |
function, the structural diversity metric. Takes one of the following: |
delta |
numeric, takes three options: |
na.handling |
|
padValue |
numeric or |
aroundTheGlobe |
logical. If the input raster goes around the whole globe,
set |
filename |
character. If the output raster should be written to a file, define file name (optional). |
verbose |
logical. If |
... |
possible further arguments. |
Details
The memory requirement of the function is determined
by raster::canProcessInMemory()
.
If the raster file cannot be processed in memory, its size needs to be reduced before strucDiv
can be used.
Value
The output is a (spatial) structural diversity map, returned as a raster layer with the same dimensions as the input raster.
When na.handling = na.pass
, then the output map will have an NA-edge of 0.5*(wsl
-1),
and it will contain more missing values than the input raster.
The output represents spatial structural diversity quantified on a spatial scale defined by the
size of the moving window.
Examples
## Not run:
# Construct a small raster file containing realizations of normal random variables:
a <- raster::raster(matrix(rnorm(648), 18, 36))
raster::plot(a)
# Calculate contrast:
contrast_a <- strucDiv(a, wsl = 3, fun = contrast)
raster::plot(contrast_a)
# Calculate dissimilarity:
b <- raster::raster(matrix(rnorm(100), 10, 10))
raster::plot(b)
dissim_b <- strucDiv(b, wsl = 5, angle = "horizontal", fun = dissimilarity)
raster::plot(dissim_b)
# Calculate structural diversity entropy with delta = 2 on NDVI data binned to 15 gray levels
ndvi.15gl <- raster::raster(ndvi.15gl)
sde_ndvi15 <- strucDiv(ndvi.15gl, wsl = 3, fun = entropy, delta = 2)
raster::plot(sde_ndvi15)
## End(Not run)