Adding a world file to a map image

Exporting a map as an image removes all of its spatial information. However, you can create an external text file, called a world file, which provides the georeferencing information for the raster image so that it can be used by GIS software, including QGIS, as a raster layer. In this recipe, we'll export a map composition as an image and create a world file along with it.

Getting ready

You will need to download the zipped shapefile from https://github.com/GeospatialPython/Learn/raw/master/Mississippi.zip and extract it to your qgis_data directory in a subdirectory named ms.

In addition to the shapefile, you will also need the MapComposer class, to simplify the code needed to add this one element. If you have not ...

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.