2

Based on the "Error when using r.series in a python script" discussion (Error when using r.series in a python script) and based upon the solution given by Joseph I tried to make the same but by using a loades set of rasters and saving the result as temporary file. I made the following script but it doesn't work to me. Any Idea to fix it?

##RasterMaxFinder=name
##1=multiple raster
##maximum=output raster
import glob, os, processing
from PyQt4.QtCore import QFileInfo
from qgis.core import QgsRasterLayer, QgsRectangle
raster = processing.getObject(1)
list = []
extent = QgsRectangle()
extent.setMinimal()
for raster in 1:
 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),0.0, maximum) 
asked Jun 7, 2016 at 13:37
2
  • What happens when you run the script? Do you receive no output, errors? Commented Jun 7, 2016 at 13:54
  • I get the following message: 'int' object has no attribute 'replace' Commented Jun 7, 2016 at 14:26

1 Answer 1

1

You should use strings for naming objects instead of integers as this could cause confusion. The following script runs for me which use the following line to split the multiple input rasters:

layers = input.split(';')

##Example=name
##input=multiple raster
##maximum=output raster
import glob, os, processing
from PyQt4.QtCore import QFileInfo
from qgis.core import QgsRasterLayer, QgsRectangle
layers = input.split(';')
list = []
extent = QgsRectangle()
extent.setMinimal()
for raster in layers:
 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),0.0, maximum)
answered Jun 7, 2016 at 14:45
2
  • 1
    YES! Indeed, it works that way! Commented Jun 7, 2016 at 15:15
  • @Nico_77 - Awesome, glad it works :) Commented Jun 7, 2016 at 15:16

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.