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

getValuesFocal

Get focal raster cell values


Description

This function returns a matrix (or matrices) for all focal values of a number of rows of a Raster* object

Usage

## S4 method for signature 'Raster'
getValuesFocal(x, row, nrows, ngb, names=FALSE, padValue=NA, array=FALSE, ...)

Arguments

x

Raster* object

row

Numeric. Row number, should be between 1 and nrow(x). Can be omitted to get all rows

nrows

Numeric. Number of rows, should be a positive integer smaller than row+nrow(x). Should be omitted if row is omitted

ngb

Neighbourhood size. Either a single integer or a vector of two integers c(nrow, ncol)

names

logical. If TRUE, the matrix returned has row and column names

padValue

numeric. The value of the cells of the "padded" rows and columns. That is 'virtual' values for cells within a neighbourhood, but outside the raster

array

logical. If TRUE and x has multiple layers, an array is returned in stead of a list of matrices

...

additional arguments (none implemented)

Value

If x has a single layer, a matrix with one row for each focal cell, and one column for each neighbourhood cell around it.

If x has multiple layers, an array (if array=TRUE) or a list of such matrices (one list element (matrix) for each layer)

See Also

Examples

r <- raster(nr=5, nc=5, crs='+proj=utm +zone=12')
values(r) <- 1:25
as.matrix(r)
getValuesFocal(r, row=1, nrows=2, ngb=3, names=TRUE)
getValuesFocal(stack(r,r), row=1, nrows=1, ngb=3, names=TRUE, array=TRUE)

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.