getValuesBlock.Rd
getValuesBlock returns values for a block (rectangular area) of values of a Raster* object.
# S4 method for class 'RasterLayer'
getValuesBlock(x, row=1, nrows=1, col=1, ncols=(ncol(x)-col+1), format='', ...)
# S4 method for class 'RasterBrick'
getValuesBlock(x, row=1, nrows=1, col=1, ncols=(ncol(x)-col+1), lyrs, ...)
# S4 method for class 'RasterStack'
getValuesBlock(x, row=1, nrows=1, col=1, ncols=(ncol(x)-col+1), lyrs, ...)
Raster* object
positive integer. Row number to start from, should be between 1 and nrow(x)
positive integer. How many rows? Default is 1
positive integer. Column number to start from, should be between 1 and ncol(x)
positive integer. How many columns? Default is the number of columns left after the start column
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)
integer (vector). Which layers? Default is all layers (1:nlayers(x)
)
additional arguments (none implemented)
matrix or vector (if (x=RasterLayer)
, unless format='matrix'
)
r <- raster(system.file("external/test.grd", package="raster"))
b <- getValuesBlock(r, row=100, nrows=3, col=10, ncols=5)
b
#> [1] 415.3237 402.8039 386.8084 363.9359 330.1638 421.1981 406.2414 385.8557
#> [9] 355.2898 306.0941 431.7786 414.9258 392.2016 360.3550 314.3130
b <- matrix(b, nrow=3, ncol=5, byrow=TRUE)
b
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 415.3237 402.8039 386.8084 363.9359 330.1638
#> [2,] 421.1981 406.2414 385.8557 355.2898 306.0941
#> [3,] 431.7786 414.9258 392.2016 360.3550 314.3130
logo <- brick(system.file("external/rlogo.grd", package="raster"))
getValuesBlock(logo, row=35, nrows=3, col=50, ncols=3, lyrs=2:3)
#> green blue
#> [1,] 168 220
#> [2,] 176 231
#> [3,] 175 226
#> [4,] 167 219
#> [5,] 176 230
#> [6,] 175 226
#> [7,] 167 219
#> [8,] 176 230
#> [9,] 175 224