Sometimes, a raster dataset is the most efficient way to display a complex vector that is merely a backdrop in a map. In these cases, you can rasterize a vector layer to turn it into an image.
We will demonstrate how to rasterize a vector layer using the following contour shapefile, which you can download from https://geospatialpython.googlecode.com/svn/contour.zip.
Extract it to your /qgis_data/rasters
directory.
We will run the gdalogr:rasterize
algorithm to convert this vector data to a raster, as follows:
Start QGIS.
From the Plugins menu, select Python Console.
Import the
processing
module:import processing
Run the algorithm, specifying the input data, the attribute from which raster values need to be drawn,
0
in order to specify pixel dimensions for the output instead of map dimensions, width and height, and finally the output raster name:processing.runalg("gdalogr:rasterize","/qgis_data/rasters/contour.shp","ELEV",0,1000,1000,"/qgis_data...