[Qgis-user] QGIS processing script: No raster output from gdalogr:translate and gdalogr:cliprasterbyextent

Sophie Crommelinck sophie.crommelinck at gmail.com
Thu Oct 6 02:31:20 PDT 2016


Hi, when I import a processing script in the QGIS Python console (see parts
of it below), it does not give any error and even displays ("*Executing
algorithm xy*"). However, the output file is not generated, i.e., there is
no file in the output directory. Does anyone know why? Do I need to save
raster output files differently? I also tried by hardcoding the
filepath (resampled
= "C:/result.tif").

# List files in data directory
files = os.listdir(os.curdir)

# Loop over all .tif files in input directory
for f in files:
# Check if file extension is .tif
if os.path.splitext(f)[1]=='.tif':
# Load image as raster layer
fileInfo = QFileInfo(f)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(f, baseName)

# Save raster layer extent
extent = rlayer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()

# Define name of resampled raster
resampled = str(os.path.splitext(f)[0] + "_" + str(j) + "pixels.tif")

# Run resampling of raster

*processing.runalg('gdalogr:translate',{"INPUT":rlayer, "OUTSIZE":j,
"OUTSIZE_PERC":False, "EXPAND":2, "PROJWIN":"%f,%f,%f,%f" % (xmin, xmax,
ymin, ymax), "OUTPUT":resampled})*


*... code parts removed ...*
# Define name of tiled raster
tiled = str(os.path.splitext(f)[0] + "_" + str(j) + "pixels" + "_tiling_x"
+ str(l+1) + "y" + str(k) + ".tif")

# Run tiling of raster

*processing.runalg('gdalogr:cliprasterbyextent', {"INPUT":reslayer,
"PROJWIN":"%f,%f,%f,%f" % (t_xmin,t_xmax,t_ymin,t_ymax), "OUTPUT":tiled})*


Thank you,

Sophie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20161006/b9d93fa5/attachment.html>


More information about the Qgis-user mailing list