PixelsToTables: PixelsToTables

Description Usage Arguments Value Examples

Description

This function converts a RasterLayer or RasterStack/Brick to two objects returned in a list: a data.table that is the 'map', with x, y, and a point ID, and a data.table that contains the variable the raster contained, and the dimension (if it's a RasterStack/Brick).

Usage

1
PixelsToTables(rast, dimensions = NULL, dim_name = NULL, var_name = NULL)

Arguments

rast

A RasterStack or RasterLayer object

dimensions

A vector of what each layer (in order, first to last) means– for example, a list of years (seq(2000,2015)). Default value (if left null) will be the names of the raster layers.

dim_name

Only applicable/relevant if 'rast' is a RasterStack/Brick with multiple layers. A character string (no spaces, please) that you want to use to describe the dimensions in your raster (ex: "year"). This will exist in the "data" object returned by the function. Default value (if left null) is "dimension".

var_name

A character string (no spaces, please) that you want to use to describe the variable that the raster represents. This will exist in the "data" object returned by the function if the rast is a RasterStack, or in the "map" object if the rast is a RasterLayer. Default value (if left null) is "variable".

Value

This function will return a list with data tables: map, and data (only included if the rast object is a RasterStack/Brick). The map object will be a data.table with columns for x, y, a point ID column named "id", and the raster values in a column named according to "var" (default if left null is "variable") with the raster values. The data object will a data.table with columns for X, Y, point ID, the variable represented in the raster, and a column with your dimension (named using the dim_name parameter), where the values in that dimension will be the dimensions provided to the dim_name parameter.

Note that order of your dimensions provided to the function matters, if your rast object is a RasterStack/Brick – if years are "stacked" earliest to lowest going from 1-16, you need to pass a sequence going from smallest to largest years to dimensions– the values for "dimension" are assigned, in order, to the layers of the RasterStack.

Examples

1
2
3
4
5
6
7
8
9
# For a single-band/RasterLayer
  single_rasterlayer<-raster::raster(results_tif_filepath)
  results_table<-PixelsToTables(rast=single_rasterlayer,var_name="value")

# For a multi-band/RasterStack
  annual_raster_stack<-raster::stack(results_tif_filepath)
  time_series<-PixelsToTables(rast=annual_raster_stack,var_name="mean",dimensions=seq(2000,2015),dim_name="year")
  map<-time_series$map
  data<-time_series$data

RebeccaStubbs/MapSuite documentation built on May 9, 2019, 9:37 a.m.