I'm trying to use gdal_translate tool in a python script I'm writing in QGIS 2.18.3. I use the translate tool because I want to change all the zero values (in all 8 bands of my raster) to nodata. I'm able to do so manually by using the tool from the toolbox. When I run my code in QGIS script editor the processing window disappear after a second, I don't get any error message but no new file is created. I think it is something to do with how this tool understands what is raster, but I've successfully used other gdal tools (merge, raster calculator) in python script using the same method, so I don't understand why it does not work in the translate tool.
This is a simple code I'm trying to use:
##last_try=name
##Select_directory=Folder
import glob, os
from PyQt4.QtCore import QFileInfo
from qgis.core import *
for raster in glob.glob("*.tif"):
fileInfo = QFileInfo(raster)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(raster, baseName)
trans = os.path.join(Select_directory,"image_suffix.tif")
outputs_GDALOGRTRANSLATE_1=processing.runalg('gdalogr:translate', rlayer,100.0,True,'0',0,'',None,False,5,4,75.0,6.0,1.0,False,0,False,None,trans)
As I mentioned, this type of code works great with other gdal tools.
What's wrong with my code?
transparameter, so I deleted my answer because yours is correct! – mgri Feb 16 '17 at 10:39os.chdir(Select_Folder)before so that the loop is executed in the correct library.. – user88484 Feb 16 '17 at 17:14Nonecan be used. Which just leaves the extent parameter :) – Joseph Feb 17 '17 at 10:02