sp_summarise: Spatial Summarization

Description Usage Arguments Details Value See Also Examples

View source: R/sp_summarise.R

Description

Summarization tool for calculating tree counts and statistics within various spatial units.

Usage

1
2
3
4
5
6
7
sp_summarise(
  trees,
  areas = NULL,
  grid = NULL,
  variables = NULL,
  statFuns = NULL
)

Arguments

trees

SpatialPointsDataFrame or SpatialPolygonsDataFrame. The locations of a set of trees, typically detected from a canopy height model using vwf. Tree attributes, such as height or crown size, should be stored within this object's @data slot. Tree crowns delineated using mcws can also be used.

areas

SpatialPolygonsDataFrame. An optional set of polygons corresponding to areas of interest. Tree counts and statistics will be returned for each area.

grid

RasterLayer (see raster) or numeric. An alternative to the areas argument. Using grid will compute tree counts and statistics within the cells of a spatial grid. Grid size and placement can be defined by inputting a raster object. A single numeric value can also be used, in which case the function will generate a grid with a cell size equal to this value.

variables

character. The names of tree attribute variables (stored in the trees@data slot). In addition to tree counts, the function will compute statistics for each of these variables. Only numeric variables are accepted.

statFuns

list. A named list of custom functions that are used to compute tree attribute statistics. If none are provided, default statistics are mean, median, standard deviation, minimum and maximum. Note that each element of the list should have a name that describes the statistics generated by the function. See below for details on defining custom functions.

Details

Input trees can either be point locations (SpatialPointsDataFrame) or crown outlines (SpatialPolygonsDataFrame). If crown outlines (or other polygons) are inputted, they will be partitioned between spatial units according to their geographic centroids.

In addition to tree counts, statistics for the trees' attributes can also be generated. These attributes should be defined within the @data slot of the input. Only numeric variables are accepted.

By default, the statistics generated for each attribute will be its mean, median, standard deviation, minimum and maximum. However, custom functions can also be used with the statFuns argument. This should be a named list of functions, wherein each list element is given a name to represent the statistic computed by the function.

For example: list(qunt98 = function(x, ...) quantile(x, c(.98), na.rm = TRUE))

Furthermore, custom functions should:

Value

Tree count and, if any variables are supplied, tree attribute statistics. If no areas or grid is supplied, the tree count and statistics are computed for the entire trees dataset, and returned as a 'data.frame' object. If areas are defined, an identical SpatialPolygonsDataFrame will be returned, with all computed statistics appended to the object's @data slot. If a grid is defined, tree count will be returned as a RasterLayer, with cell values equal to the number of trees in each cell. If a grid and variables are defined, a RasterBrick (see brick) will be returned instead, with tree count and attribute statistics stored as stacked layers.

See Also

vwf mcws

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Load sample data
library(ForestTools)
library(sp)
data("kootenayTrees", "kootenayBlocks", "kootenayCrowns")

# Get total tree count
sp_summarise(kootenayTrees)

# Get total tree count, tree height and crown area statistics
sp_summarise(kootenayCrowns, variables = c("height", "crownArea"))

# Get tree count, height statistics for specific areas of interest
areaStats <- sp_summarise(kootenayTrees, areas = kootenayBlocks, variables = "height")

# Plot according to tree count
plot(areaStats, col = heat.colors(3)[order(areaStats$TreeCount)])

# Get tree count and height statistics for a 20 x 20 m spatial grid
gridStats <- sp_summarise(kootenayTrees, grid = 20, variables = "height")

# Plot gridded tree count and statistics
plot(gridStats$TreeCount)
plot(gridStats$heightMax)

ForestTools documentation built on Sept. 11, 2021, 9:07 a.m.