Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

getValuesBlock

Get a block of raster cell values


Description

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

Usage

## S4 method for signature 'RasterLayer'
getValuesBlock(x, row=1, nrows=1, col=1, ncols=(ncol(x)-col+1), format='', ...)

## S4 method for signature 'RasterBrick'
getValuesBlock(x, row=1, nrows=1, col=1, ncols=(ncol(x)-col+1), lyrs, ...)

## S4 method for signature '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

positive integer. How many rows? Default is 1

col

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

ncols

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

format

character. When x is a RasterLayer, if format='matrix' or format='m', a matrix is returned instead of a vector. If format='matrix', it is a nrow x ncol matrix. If format='m' it is a 1 column matrix (the benefit is that the type of output is now the same for all Raster objects)

lyrs

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

...

additional arguments (none implemented)

Value

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

See Also

Examples

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)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.