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

# 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

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

...

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

getValues, focal

## Examples

r <- raster(nr=5, nc=5, crs='+proj=utm +zone=12')
values(r) <- 1:25
as.matrix(r)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    2    3    4    5
#> [2,]    6    7    8    9   10
#> [3,]   11   12   13   14   15
#> [4,]   16   17   18   19   20
#> [5,]   21   22   23   24   25
getValuesFocal(r, row=1, nrows=2, ngb=3, names=TRUE)
#>    r1c1 r1c2 r1c3 r2c1 r2c2 r2c3 r3c1 r3c2 r3c3
#> 1    NA   NA   NA   NA    1    2   NA    6    7
#> 2    NA   NA   NA    1    2    3    6    7    8
#> 3    NA   NA   NA    2    3    4    7    8    9
#> 4    NA   NA   NA    3    4    5    8    9   10
#> 5    NA   NA   NA    4    5   NA    9   10   NA
#> 6    NA    1    2   NA    6    7   NA   11   12
#> 7     1    2    3    6    7    8   11   12   13
#> 8     2    3    4    7    8    9   12   13   14
#> 9     3    4    5    8    9   10   13   14   15
#> 10    4    5   NA    9   10   NA   14   15   NA
getValuesFocal(stack(r,r), row=1, nrows=1, ngb=3, names=TRUE, array=TRUE)
#> , , layer.1
#>
#>   r1c1 r1c2 r1c3 r2c1 r2c2 r2c3 r3c1 r3c2 r3c3
#> 1   NA   NA   NA   NA    1    2   NA    6    7
#> 2   NA   NA   NA    1    2    3    6    7    8
#> 3   NA   NA   NA    2    3    4    7    8    9
#> 4   NA   NA   NA    3    4    5    8    9   10
#> 5   NA   NA   NA    4    5   NA    9   10   NA
#>
#> , , layer.2
#>
#>   r1c1 r1c2 r1c3 r2c1 r2c2 r2c3 r3c1 r3c2 r3c3
#> 1   NA   NA   NA   NA    1    2   NA    6    7
#> 2   NA   NA   NA    1    2    3    6    7    8
#> 3   NA   NA   NA    2    3    4    7    8    9
#> 4   NA   NA   NA    3    4    5    8    9   10
#> 5   NA   NA   NA    4    5   NA    9   10   NA
#>