I need to apply r.neighbours or Neighbourhood analysis (QGIS plugin LecoS (or equivalent) to 3000 rasters and define a neighbourhood of 5 x 5 and calculate the mean.
I suppose I need to create a script with a loop that goes through the raster files and applies the same analysis settings. Unfortunately I only know how to program in R. So I'm asking if anyone can show me how to create a script that does this.
I use QGIS and I would prefer to do this using the QGIS Processing Framework. But GRASS GIS or SAGA GIS are also OK for me.
Thanks in advance
EDIT: This how I did it on Ubuntu 12.04. Thanks @Curlew.
I created GRASS Location/Mapstet and batch imported the 3000 rasters using "Common formats import (r.in.gdal)" to the mapset (I recommend deactivating the option "add to layer tree"). I used one of the rasters for setting the region (g.region).
Then I opened R, set the workspace to the folder where the rasters are stored and run this:
library(raster)
library(spgrass6)
initGRASS(gisBase = "/usr/lib/grass64", home = tempdir(), gisDbase = "/path/to/gis/data/directory", location = "Location", mapset = "Mapset", override = TRUE) #Initate the previously created Location/Mapset
ls <- lapply(list.files(".","*.tif"),FUN=raster) # Import all raster to the list "ls"
for(i in seq_along(ls)){
execGRASS("r.neighbors", input=names(ls[[i]]),size=5,output="teste",flags=c("overwrite"))
execGRASS("r.out.gdal", input="teste",output=paste(paste("/path/to/output/folder",sep="",names(ls[[i]])),sep="",".tif"))
}
This solves my problem, but I'm still curious about how the equivalent Python code for QGIS Processing looks like.