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)
-
What happens when you run the script? Do you receive no output, errors?Joseph– Joseph2016年06月07日 13:54:21 +00:00Commented Jun 7, 2016 at 13:54
-
I get the following message: 'int' object has no attribute 'replace'Nico_77– Nico_772016年06月07日 14:26:51 +00:00Commented Jun 7, 2016 at 14:26
1 Answer 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)
Explore related questions
See similar questions with these tags.