3

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?

asked Apr 1, 2016 at 13:49

1 Answer 1

2

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") 
answered Apr 1, 2016 at 14:24
8
  • Well that looks good but I get the error „Error: Wrong parameter value: []". I run it with "grass7:r.series" Commented Apr 4, 2016 at 8:51
  • @Miron - Forgot to mention that I haven't used this tool before so I guessed that the minimum extent would be the combined extent of all rasters (maybe I'm wrong?). I tested it with several rasters in the same folder and got a result but this is with grass6. I do not have grass7 installed so cannot test this but I wouldn't expect there to be that much difference for it to cause an error. Not sure if I could help with much more, apologies! Commented Apr 4, 2016 at 9:11
  • My mistake, works like a charm, thank you very much! Commented Apr 4, 2016 at 12:14
  • @Miron - Most welcome buddy but what was the mistake if I may ask? ;) Commented Apr 4, 2016 at 12:16
  • Since this is the second step my processing model I integrated the code in my model and confused the Input and Output folder ;) Commented Apr 4, 2016 at 13:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.