My Question is related to: How to make Processing algorithms use default parameter values in QGIS 2.14?
I would like to use gdalogr:translate and only set the values of "INPUT","OUTSIZE","EXPAND" and "OUTPUT".
However, when I run:
processing.runalg('gdalogr:translate', {"INPUT":rlayer,"OUTSIZE":j,"EXPAND":2,"OUTPUT":output})
I get the following error (even tough PROJWIN is not a mandatory parameter):
Error: Missing parameter value for parameter PROJWIN.
I would like to let this parameter as default. When I change the code and include one of the following snippets:
"PROJWIN": '' OR "PROJWIN": None
The following error occurs:
Error: Wrong parameter value for parameter PROJWIN.
Alternatively, I tried setting the paramter PROJWIN to the extent of my current raster layer, without success:
fileInfo = QFileInfo(f)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(f, baseName)
e = rlayer.extent()
processing.runalg('gdalogr:translate', {"INPUT":rlayer,"OUTSIZE":j,"EXPAND":2,"PROJWIN":e,"OUTPUT":output})
Does anyone know how this could work?
-
2PROJWIN is in fact a mandatory parameter for processing. It might be that the Processing GUI does some stuff for you, like taking the extent from the input layer. But if you want to call the algorithm from the console, you must pass that parameter.Germán Carrillo– Germán Carrillo2016年09月30日 15:23:13 +00:00Commented Sep 30, 2016 at 15:23
1 Answer 1
Not sure if the extent of the layer can be pre-set with a default value when running it from the console. I always define the extent when it is one of the parameters (which I assume is always required):
from PyQt4.QtCore import QFileInfo
import processing
f = iface.activeLayer()
fileName = f.source()
fileInfo = QFileInfo(fileName)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(fileName, baseName)
extent = rlayer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()
output = "C:/Users/You/Desktop/result.tif"
processing.runalg('gdalogr:translate', {"INPUT":rlayer,"OUTSIZE":j,"EXPAND":2,"PROJWIN":"%f,%f,%f,%f"% (xmin, xmax, ymin, ymax),"OUTPUT":output})
-
Perfect solution! Unfortunately, the result does not exist in the given output directory. When importing the module in the QGIS Python console, everything seems to work fine, but there is no .tif file created in the directory. Its hard to figure out where the error is, if there is no error message...any idea?Sophie Crommelinck– Sophie Crommelinck2016年10月03日 14:54:59 +00:00Commented Oct 3, 2016 at 14:54
-
Hmm not sure, I received an output. Will test this again at some point and see where the problem is...Joseph– Joseph2016年10月04日 11:35:10 +00:00Commented Oct 4, 2016 at 11:35
-
1Thanks, I created a new question for this issue (link), since I encountered the same problem of not getting an output file for
gdal:cliprasterbyextent
. I thought the answer might be useful for others not having the initial problem of this post.Sophie Crommelinck– Sophie Crommelinck2016年10月04日 14:06:55 +00:00Commented Oct 4, 2016 at 14:06
Explore related questions
See similar questions with these tags.