In the script editor in QGIS, when choosing string parameter type, a default value must be added according to https://docs.qgis.org/2.8/en/docs/user_manual/processing/scripts.html
What happen is that the parameter line in the GUI will be populated with the default value. 'average' in my case.
What I want to do is to add several different values so that the user can choose from. In my case, I want to add other statistics, so the user will have a drop-down list containing several options.
The solution in Letting user choose from 2 options for QGIS Processing script input parameter? does not work for me since I'm using QGIS 2.18.2, also the solution for check-box is not relevant.
Is it possible to create a drop-down list for the user in QGIS 2.18.2 las palmas?
In case it is needed, the full code is here:
##Cell Statistics=name
##Select_directory=Folder
##statistic_name=string average
##Output_raster=Output raster
import glob, os
from PyQt4.QtCore import QFileInfo
from qgis.core import QgsRasterLayer, QgsRectangle
os.chdir(Select_directory)
raster_list = []
extent = QgsRectangle()
extent.setMinimal()
statistic_dic = {'average':0, 'count':1, 'median':2,'mode':3, 'minimum':4, 'min_raster':5,'maximum':6, 'max_raster':7, 'std':8, 'range':9}
for raster in glob.glob("*.tif"):
fileInfo = QFileInfo(raster)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(raster, baseName)
# Combine raster layers to list
raster_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 and set relevant parameters
processing.runalg("grass7:r.series",
{"input":raster_list ,
"-n":False,
"method":statistic_dic[statistic_name],
"range":'-10000000000,10000000000',
"GRASS_REGION_PARAMETER":"%f,%f,%f,%f"% (xmin, xmax, ymin, ymax),
"GRASS_REGION_CELLSIZE_PARAMETER":0,
"output":Output_raster})
##statistic_name=string average
with##statistic_name=selection average;count;median;mode;minimum;min_raster;maximum;max_raster;std;range
.