Pyramids, or overview images, sacrifice the disk space for map rendering speed by storing resampled, lower-resolution versions of images in the file alongside the full resolution image. Once you have finalized a raster, building pyramid overviews is a good idea.
For this recipe, we will use a false-color image, that you can download from https://geospatialpython.googlecode.com/files/FalseColor.zip.
Unzip this TIF
file and place it in your /qgis_data/rasters
directory.
The Processing Toolbox has a dedicated algorithm for building pyramid images. Perform the following steps to create pyramids for a raster
processing
module:import processing
gdalogr:overviews
algorithm, specifying the process name, input image, overview levels, the option to remove existing overviews, resampling method (0
is the nearest neighbor), and overview format (1
is internal):processing.runalg("gdalogr:overviews","/qgis_data/rasters/FalseColor.tif","2 4 8 16",True,0,1)
The concept of overview images is quite simple. You resample the images several times, and then a viewer chooses the most appropriate, smallest file to load on the map, depending on scale. The overviews can be stored in the header of the file for certain formats or as an external file format. The level of overviews needed depends largely on the file size and resolution of your current image, but is really arbitrary. In this example, we double the scale by a factor of 2, which a is common practice. Most of the zoom tools in the applications will double the scale when you click to zoom in. The factor of 2 gives you enough zoom levels, so that you usually won't zoom to a level where there is no pyramid image. There is a point of diminishing returns if you create too many levels because pyramids take up additional disk space. Usually 4 to 5 levels is effective.