getValues: Get raster cell values

Description Usage Arguments Value See Also Examples

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

1
2
3
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

1
2
3
4
5
6
r <- raster(system.file("external/test.grd", package="raster"))
r
v <- getValues(r)
length(v)
head(v)
getValues(r, row=10)

Example output

Loading required package: sp
class       : RasterLayer 
dimensions  : 115, 80, 9200  (nrow, ncol, ncell)
resolution  : 40, 40  (x, y)
extent      : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:28992 +towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812 +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs 
data source : /usr/lib/R/site-library/raster/external/test.grd 
names       : test 
values      : 128.434, 1805.78  (min, max)

[1] 9200
[1] NA NA NA NA NA NA
 [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 1003.870  945.002  769.047  661.724  593.855  537.250
[73]       NA       NA       NA       NA       NA       NA       NA       NA

raster documentation built on Sept. 24, 2019, 5:05 p.m.