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)  
2
  • What happens when you run the script? Do you receive no output, errors?
    – Joseph
    Commented Jun 7, 2016 at 13:54
  • I get the following message: 'int' object has no attribute 'replace'
    – Nico_77
    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)
2
  • 1
    YES! Indeed, it works that way!
    – Nico_77
    Commented Jun 7, 2016 at 15:15
  • @Nico_77 - Awesome, glad it works :)
    – Joseph
    Commented Jun 7, 2016 at 15:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.