When I import the following processing script in the QGIS Python console it does not give any error and even displays ("Executing algorithm xy"). However the output file is not generated. Does anyone know why? Do I need to save raster output files differently than vector output files in processing scripts?
The two versions of code access the input image differently and the extent values do not make much sense in these snippets.
### gdalogr:translate ###
from PyQt4.QtCore import QFileInfo
import processing
file = iface.activeLayer()
f = file.source()
fileInfo = QFileInfo(f)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(f, baseName)
extent = rlayer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()
output = "C:/result.tif"
processing.runalg('gdalogr:translate',{"INPUT":rlayer,"OUTSIZE":100,"OUTSIZE_PERC":False,"EXPAND":2,"PROJWIN":"%f,%f,%f,%f"%(xmin, xmax, ymin, ymax),"OUTPUT":output})
##########################################################################
### gdalogr:cliprasterbyextent ###
from PyQt4.QtCore import QFileInfo
import processing
import os
os.chdir(r"D:\...\3_Resizing")
files = os.listdir(os.curdir)
for f in files:
if os.path.splitext(f)[1]=='.tif':
fileInfo = QFileInfo(f)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(f, baseName)
rextent = rlayer.extent()
xmin = rextent.xMinimum()
xmax = rextent.xMaximum()
ymin = rextent.yMinimum()
ymax = rextent.yMaximum()
clip_output= "D:/.../test.tif"
# I also get no result when providing a name 'test' only, which did work to generate a vector output from qgis:vectorgrid
processing.runalg('gdalogr:cliprasterbyextent', {"INPUT":rlayer, "PROJWIN":"%f,%f,%f,%f"% (xmin,xmax,ymin,ymax),"OUTPUT":"%s"%(clip_output)})
processing.runalg('qgis:vectorgrid', {"EXTENT":"%f,%f,%f,%f"% (r_xmin, r_xmax, r_ymin, r_ymax), "STEP_X":x, "STEP_Y":y, "TYPE":1,"OUTPUT":grid_output})
in a similar script in the same directory did save a vector output. However, how do I check the access rights of Qgis processing scripts?