EcoGenetics (version 1.2.1-6)

eco.slide.matrix: Sliding window for matrix data

Description

This program applies a function defined by the user, using a moving window (circle area or square) and assigning the value to the focal pixel.

Usage

eco.slide.matrix(
  mat,
  r,
  slide,
  fun,
  window = c("square", "circle"),
  within = TRUE
)

Arguments

mat

Input raster matrix.

r

Half a side for square, radius for circle, diagonal length for rhombus.

slide

Number of elements between two focal pixels, for column and row dimension

fun

Function to apply in each focal pixel.

window

Window type. Default "square".

within

Should the function be computed in focal pixels of the borders, only if the area is within the matrix? Default TRUE.

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
data(eco.test)
ras <- matrix(eco[["P"]][, 1], 15, 15)
image(ras)
ras.square <- eco.slide.matrix(ras, 1, 1, mean, "square")
image(ras.square)

# or allowing more control over the function:
ras.square <- eco.slide.matrix(ras, r = 3, slide = 1, function(x) mean(x, na.rm = TRUE), "square")
image(ras.square)

# sliding a circle:
ras.circle <- eco.slide.matrix(ras, r = 3, slide = 1, mean, "circle", within = FALSE)
image(ras.circle) 

# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace