Learn R Programming

raster (version 3.5-15)

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

getValues, focal

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab