as_tibble: Convert a Raster to a data frame.

as_tibbleR Documentation

Convert a Raster to a data frame.

Description

Generate a data frame version of any raster object. Use the arguments 'cell', 'dim', 'split_date' and 'value' to control the columns that are included in the output.

Usage

## S3 method for class 'BasicRaster'
as_tibble(
  x,
  cell = TRUE,
  dim = nlayers(x) > 1L,
  value = TRUE,
  split_date = FALSE,
  xy = FALSE,
  ...
)

Arguments

x

a RasterLayer, RasterStack or RasterBrick

cell

logical to include explicit cell number

dim

logical to include slice index

value

logical to return the values as a column or not

split_date

logical to split date into components

xy

logical to include the x and y centre coordinate of each cell

...

unused

Details

If the raster has only one layer, the slice index is not added. Use 'dim = FALSE' to not include the slice index value.

Value

a data frame (tibble) with columns:

  • cellvalue the actual value of the raster cell

  • cellindex the index of the cell (numbered from 1 to ncell() in the raster way).

Columns cellindex or cellvalue may be omitted if either or both of cell and/or value are FALSE, respectively

Other columns might be included depending on the properties of the raster and the arguments to the function:

  • year,month,day if split_date is TRUE

  • x,y if xy is TRUE

  • dimindex if the input has more than 1 layer and dim is TRUE.

Examples

## basic data frame version of a basic raster
as_tibble(raster::raster(volcano))

## data frame with time column since raster has that set
r <- raster::raster(volcano)
br <- raster::brick(r, r)
as_tibble(raster::setZ(br, Sys.Date() + 1:2), cell = TRUE)

tabularaster documentation built on Nov. 2, 2023, 5:14 p.m.