I’m writing a tool script in python and at a certain point I want to use the GRASS tool r.series. I want the algorithem to read all raster files from a folder and calculate the maximum with r.series. The thing is I’m getting the error: “Wrong parameter value: None” when using the code below:
##RasterMaxFinder=name
##Select_directory=Folder
##Save_results=Folder
import glob, os, processing
list = ( Select_directory + "/" + "*.tif" )
processing.runalg('grass7:r.series', list ,False,6,'-10000000000,10000000000',None,30.0, Save_results + "/" + "Output.tif")
It must have something to do with the extend, but I can't figure out what. When I'm using the tool directly in QGIS, erverything works fine. Any Ideas?
Answer
Yes, the extent probably has to be explicitly defined before you can run the algorithm. Seen a few posts about this. The following might work (note that I used grass:r.series
and not grass7:r.series
):
##RasterMaxFinder=name
##Select_directory=Folder
##Save_results=Folder
import glob, os, processing
from PyQt4.QtCore import QFileInfo
from qgis.core import QgsRasterLayer, QgsRectangle
os.chdir(Select_directory)
list = []
extent = QgsRectangle()
extent.setMinimal()
for raster in glob.glob("*.tif"):
fileInfo = QFileInfo(raster)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(raster, baseName)
# Combine raster layers to list
list.append(rlayer)
# Combine raster extents
extent.combineExtentWith(rlayer.extent())
# Get extent
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()
# Run algorithm
processing.runalg('grass:r.series', list ,False,6,'-10000000000,10000000000',"%f,%f,%f,%f"% (xmin, xmax, ymin, ymax),30.0, Save_results + "/" + "Output.tif")
No comments:
Post a Comment