R: Get raster cell values

getValues {raster} | R Documentation

## Get raster cell values

### Description

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).

### Usage

    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

### See Also

`getValuesBlock, getValuesFocal, setValues`

### Examples

    r <- raster(system.file("external/test.grd", package="raster"))
    r
    v <- getValues(r)
    length(v)
    head(v)
    getValues(r, row=10)

[Package raster version 3.5-15 Index]