Creating the simplest map renderer

In order to turn a dynamic GIS map into a static map image or document, you must create a renderer to freeze the map view and create a graphic version of it. In this recipe, we'll render a map to a JPEG image and save it.

Getting ready

You will need to download the following zipped shapefile and extract it to your qgis_data directory in a subdirectory named hancock:

https://github.com/GeospatialPython/Learn/raw/master/hancock.zip

You will also need to open the Python Console under the Plugins menu in QGIS. You can run these lines of code inside the console.

How to do it...

In this recipe, we will load our shapefile, add it to the map, create a blank image, set up the map view, render the map image, and save it. To ...

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.