spatial.tools (version 1.6.0)

getValuesBlock_stackfix: Get a block of raster cell values (optimization fix for RasterStacks)

Description

A faster version of getValuesBlock for RasterStack.

Usage

getValuesBlock_stackfix(x, row = 1, nrows = 1, col = 1, ncols = (ncol(x)
  - col + 1), lyrs = (1:nlayers(x)))

Arguments

x

Raster* object

row

positive integer. Row number to start from, should be between 1 and nrow(x)

nrows

postive integer. How many rows? Default is 1

col

postive integer. Column number to start from, should be between 1 and ncol(x)

ncols

postive integer. How many columns? Default is the number of colums left after the start column

lyrs

integer (vector). Which layers? Default is all layers (1:nlayers(x))

Value

matrix or vector (if (x=RasterLayer), unless format='matrix')

Details

In certain cases, getValuesBlock may run very slowly on a RasterStack, particularly when the RasterStack is comprised of RasterBricks. This code attempts to fix the inefficiency by running the extract on each unique file of the RasterStack, rather than each unique layer.

See Also

getValuesBlock

Examples

Run this code
# NOT RUN {
library("raster")
tahoe_highrez <- brick(system.file("external/tahoe_highrez.tif", package="spatial.tools"))
tahoe_highrez_stack <- stack(tahoe_highrez,tahoe_highrez,tahoe_highrez)
# getValuesBlock stack extraction:
system.time(tahoe_highrez_extract <- getValuesBlock(tahoe_highrez_stack))
# getValuesBlock_stackfix stack extraction:
system.time(tahoe_highrez_extract <- getValuesBlock_stackfix(tahoe_highrez_stack))
# }

Run the code above in your browser using DataLab