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
Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.