Rasterizing a vector layer
Sometimes, a raster dataset is a more 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.
Getting ready
We will demonstrate rasterizing a vector layer using the following contour shapefile, which you can download:
https://github.com/GeospatialPython/Learn/raw/master/contour.zip
Extract it to your /qgis_data/rasters
directory.
How to do it...
We will run the gdalogr:rasterize
algorithm to convert this vector data to a raster:
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 to draw raster values,
0
to specify the pixel dimensions for the output instead of map dimensions, then the width and height, and finally the output raster name:processing.runalg("gdalogr:rasterize", "/qgis_data/rasters/contour...