raster (version 2.1-41)

getValuesBlock: Get a block of raster cell values

Description

getValuesBlock returns values for a block (rectangular area) of values of a Raster* object.

Usage

## S3 method for class 'RasterLayer':
getValuesBlock(x, row=1, nrows=1, col=1, ncols=(ncol(x)-col+1), format='')

## S3 method for class 'RasterBrick':
getValuesBlock(x, row=1, nrows=1, col=1, ncols=(ncol(x)-col+1), lyrs)

## S3 method for class 'RasterStack':
getValuesBlock(x, row=1, nrows=1, col=1, ncols=(ncol(x)-col+1), lyrs)

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
format
character. If format='matrix', a matrix is returned instead of a vector
lyrs
integer (vector). Which layers? Default is all layers (1:nlayers(x))

Value

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

See Also

getValues

Examples

Run this code
r <- raster(system.file("external/test.grd", package="raster"))
b <- getValuesBlock(r, row=100, nrows=3, col=10, ncols=5)
b 
b <- matrix(b, nrow=3, ncol=5, byrow=TRUE)
b

logo <- brick(system.file("external/rlogo.grd", package="raster"))
getValuesBlock(logo, row=35, nrows=3, col=50, ncols=3, lyrs=2:3)

Run the code above in your browser using DataCamp Workspace