QGIS – Syntax Error When Using GDAL in Python Console QGIS

gdalpythonqgisrasterization

When I run the following code in the python console in QGIS I get a syntax error:

import osgeo.gdal
gdal_rasterize [-b 1] [-burn 255] [-a Pixelkost] [-te 170000.2 168000.27 177999.8 177999.8] <Adp322.shp> <work.tif>

b command for burning it in band number 1
burn command for the color red
a command for using the attribute pixelkost
te command for x,y min and x,y max
the already loaded Adp322.shp file (I also tried it with the whole system path towards the file but this didn't work either)
work.tif is the name the new file should have. (Should this maybe be an already existing file? but how should I produce this?)

Best Answer

gdal_rasterize is not a python module, but an exe file. You can not call it that easy inside the python console.

See this blogpost on how to wrap the operating system around it:

http://geoinformaticstutorial.blogspot.de/2012/11/convert-shapefile-to-raster-with-gdal.html

import os
os.system('gdal_rasterize -a ICE_TYPE -where \"ICE_TYPE=\'Open Water\'\" -burn 2 -l ' + shapefileshortname +' -tr 1000 -1000 ' +  shapefile + ' ' + outraster
Related Question