Skip to content

Instantly share code, notes, and snippets.

@obrl-soil
Created November 8, 2016 02:02
Show Gist options
  • Save obrl-soil/cd7f1e9917138586532cc1e706dfbd9b to your computer and use it in GitHub Desktop.
Save obrl-soil/cd7f1e9917138586532cc1e706dfbd9b to your computer and use it in GitHub Desktop.
relative values within a moving window
library(raster)
r <- raster('path\\to\\your\\file.ext')
winmin <- function(x) min(x, na.rm = T)
winmax <- function(x) max(x, na.rm = T)
focalmin <- focal(r, w = matrix(1, ncol = 3, nrow = 3), winmin)
focalmax <- focal(r, w = matrix(1, ncol = 3, nrow = 3), winmax)
rel_el <- abs(focalmin - focalmax)
writeRaster(rel_el, file='path\\and\\output\\filename.ext')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment