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?

  • 2
    PROJWIN 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 Sep 30 '16 at 15:23

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})
| improve this answer | |
  • 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 Oct 3 '16 at 14:54
  • Hmm not sure, I received an output. Will test this again at some point and see where the problem is... – Joseph Oct 4 '16 at 11:35
  • 1
    Thanks, 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 Oct 4 '16 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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