Results of a landscape analysis are scale dependent (Šímová 2012). One approach to deal with this is by using a moving window (Hagen-Zanker 2016). For each focal cell in the landscape, a matrix is used to specify the neighborhood and the metric value of this local neighborhood is assigned to each focal cell (Fletcher 2018). Thereby, the windows are allowed to overlap (McGarigal et al. 2012). The result of a moving window analysis is a raster with an identical extent as the input, however, each cell now describes the neighborhood in regard to the variability of the chosen metric (Hagen-Zanker 2016). Of course, the selection of the matrix size largely influences the scale of the result (Hagen-Zanker 2016).

Implementation in landscapemetrics

We provide the function window_lsm() in landscapemetrics to analyse an input raster using the moving window approach. The function allows to specify the neighborhood using a matrix using the terra::focal() function internally. Currently, only the landscape level metrics are possible to calculate and they can be specified similarly to calculate_lsm(). For details, see ?list_lsm().

library(landscapemetrics)
library(terra)
library(ggplot2)

# internal data needs to be read
landscape <- terra::rast(landscapemetrics::landscape)

First, we need to specify the local neighborhood matrix. This matrix must have sides defined as odd numbers, in which the focal cell is always the center cell (for more details, see ?terra::focal()).

moving_window <- matrix(1, nrow = 3, ncol = 3)
moving_window

Now, we can easily pass this matrix to window_lsm() together with the input landscape. For this example, we want to calculate the number of classes (lsm_l_pr) and the joint entropy (lsm_l_joinent) for the local neighborhoods.

result <- window_lsm(landscape, window = moving_window, what = c("lsm_l_pr", "lsm_l_joinent"))
result

To be type-stable, the result will be a nested list. The first level includes all layers of a SpatRaster (only one if a SpatRaster is provided), the second level contains all selected metrics. The resulting SpatRaster describe the local neighborhood according to the moving window around each focal cell. In the case of lsm_l_pr this the number of classes present.

result_stack <- c(landscape, result[[1]]$lsm_l_pr)

ggplot(data = terra::as.data.frame(result_stack[[1]], xy = TRUE)) + 
    geom_raster(aes(x = x, y = y, fill = factor(clumps))) + 
    scale_fill_viridis_d(name = "Landscape class") + 
    coord_equal() + 
    theme(axis.line = element_blank(), axis.ticks = element_blank(), 
          axis.text = element_blank(), axis.title = element_blank(), 
          legend.position = "bottom")

ggplot(data = terra::as.data.frame(result_stack[[2]], xy = TRUE)) + 
    geom_raster(ggplot2::aes(x = x, y = y, fill = factor(clumps))) + 
    scale_fill_viridis_d(name = "Number of classes", option = "C") + 
    coord_equal() + 
    theme(axis.line = element_blank(), axis.ticks = element_blank(), 
          axis.text = element_blank(), axis.title = element_blank(), 
          legend.position = "bottom")

In the future, we also plan to allow class level metrics, however, patch metrics are not meaningful (McGarigal 2012) and will not be added in the future.

References



landscapeecology/landscapemetrics documentation built on March 27, 2024, 10:13 a.m.