1

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?)

3

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
  • But I am trying to do this straight in the command line from the console in QGIS... Your document is telling me to do this: Using gdal_rasterize is described here and from command line I would call for one of the polygons: gdal_rasterize -a ICE_TYPE -where "ICE_TYPE='Open Water'" -burn 2 -l ice20120608_3575 -tr 1000 -1000 C:\...\ice20120608_3575.shp C:\...\ice20120608_3575.tif What I am already doing. – Peter Vanvoorden May 10 '14 at 13:55
  • Command line is the DOS box called OSGEO4W Shell on Windows, or Terminal on Linux. That is not the python console. – AndreJ May 10 '14 at 14:08
  • or Mac OS X ...(Terminal) – gene May 10 '14 at 14:16
  • Still not working. When I run the following code in python console after 'import os', I just get the value '32512' as a result... os.system('gdal_rasterize -b 1 -a Pixelkost -burn 255 -te 170000.2 168000.27 177999.8 177999.8 /Users/PeterVanvoorden/Desktop/GRBgis_322/Shapefile/Adp322.shp /Users/PeterVanvoorden/Desktop/Test.tif') – Peter Vanvoorden May 10 '14 at 15:52
  • when I type the command as in the link, in the terminal: mbp-van-peter:~ PeterVanvoorden$ gdal_rasterize -b 1 -a Pixelkost -burn 255 -te 170000.2 168000.27 177999.8 177999.8 /Users/PeterVanvoorden/Desktop/GRBgis_322/Shapefile/Adp322.shp /Users/PeterVanvoorden/Desktop/test.tif ....... I get: -bash: gdal_rasterize: command not found ........ maybe there is something wrong with my gdal installation? – Peter Vanvoorden May 10 '14 at 16:40

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.