Data aggregation via moving window or direct methods. Aggregate a fine-resolution raster to a grid. The moving window method smooths the surface using a specified function within a moving window of a specified size and shape prior to aggregation. The direct method simply aggregates to the grid using the specified function.
grainchanger package provides functionality for data aggregation
to a grid via moving-window or direct methods.
The moving-window data aggregation method smooths the surface using a specified function within a moving window of a specified size and shape prior to aggregation.
The moving window approach allows users to capture some information about landscape structure at the scale at which the process acts in the landscape.
The direct method simply aggregates to the grid using the specified
function, essentially acting as a wrapper for the
You can install the development version from GitHub with:
The below example shows the moving-window data aggregation in action. It
aggregates a categorical raster to a grid using Shannon evenness as the
function calculated within a square moving window of 5 units. This value
is included as a column on the grid
library(grainchanger)library(ggplot2)library(landscapetools)# categorical landscapeshow_landscape(cat_ls)#> Loading required package: raster#> Loading required package: sp
# moving-window aggregation using Shannon evennessg_sf$mwda <- winmove_agg(g = g_sf,dat = cat_ls,d = 5,type = "rectangle",fun = "shei",lc_class = 0:3)ggplot(g_sf) + geom_sf(aes(fill = mwda))
The below example shows the direct data aggregation in action. It
aggregates a continuous raster to a grid using the range as the function
calculated for each cell of the larger grid. This value is included as a
column on the grid
var_range is an inbuilt function in
# continuous landscapeshow_landscape(cont_ls)
# direct aggregation using rangeg_sf$range <- nomove_agg(g = g_sf,dat = cat_ls,fun = "var_range")ggplot(g_sf) + geom_sf(aes(fill = range))
There are a number of inbuilt functions in the grainchanger package,
with their useage outlined below. While it is possible to use
user-defined functions within both
welcome suggestions for additional functions. Please add as an
issue - doing
it this way means we can maximise the speed of the
|wm_prop||Calculate the proportion of a given class within the moving window||lc_class (numeric)|
|wm_classes||Calculate the number of classes within the moving window|
|wm_shei||Calculate the Shannon evenness within the moving window||lc_class (numeric)|
|wm_mean||Calculate the mean value within the moving window|
|nm_shei||Calculate the Shannon evenness within the larger cell||lc_class (numeric)|
|nm_prop||Calculate the proportion of a given class within the larger cell||lc_class (numeric)|
|var_range||Calculate the range of values (can be used with or without a moving window|
create_torus function takes as input a square or rectangular
landscape and pads it by a specified radius, creating the effect of a
torus. We developed this function in order to avoid edge effects when
testing methods on simulated landscapes (such as those from
torus <- create_torus(cat_ls, 5)show_landscape(torus)
NEWS.mdfile to track changes to the package.