getValues returns all values or the values for a number of rows of a Raster* object. Values returned for a RasterLayer are a vector. The values returned for a RasterStack or RasterBrick are always a matrix, with the rows representing cells, and the columns representing layers

values is a shorthand version of getValues (for all rows).

getValues(x, row, nrows, ...)

values(x, ...)

Arguments

x

Raster* object

row

Numeric. Row number, should be between 1 and nrow(x), or missing in which case all values are returned

nrows

Numeric. Number of rows. Should be an integer > 0, or missing

...

Additional arguments. When x is a RasterLayer: format to specify the output format. Either "matrix" or, the default "", in which case a vector is returned

Value

vector or matrix of raster values

Examples

r <- raster(system.file("external/test.grd", package="raster"))
r
#> class      : RasterLayer 
#> dimensions : 115, 80, 9200  (nrow, ncol, ncell)
#> resolution : 40, 40  (x, y)
#> extent     : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
#> crs        : +proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +datum=WGS84 +units=m +no_defs 
#> source     : test.grd 
#> names      : test 
#> values     : 138.7071, 1736.058  (min, max)
#> 
v <- getValues(r)
length(v)
#> [1] 9200
head(v)
#> [1] NA NA NA NA NA NA
getValues(r, row=10)
#>  [1]       NA       NA       NA       NA       NA       NA       NA       NA
#>  [9]       NA       NA       NA       NA       NA       NA       NA       NA
#> [17]       NA       NA       NA       NA       NA       NA       NA       NA
#> [25]       NA       NA       NA       NA       NA       NA       NA       NA
#> [33]       NA       NA       NA       NA       NA       NA       NA       NA
#> [41]       NA       NA       NA       NA       NA       NA       NA       NA
#> [49]       NA       NA       NA       NA       NA       NA       NA       NA
#> [57]       NA       NA       NA       NA       NA       NA       NA       NA
#> [65]       NA       NA       NA       NA 655.5997 612.2552       NA       NA
#> [73]       NA       NA       NA       NA       NA       NA       NA       NA