Creating pyramids for a raster

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.

Getting ready

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.

How to do it...

The Processing Toolbox has a dedicated algorithm for building pyramid images. Perform the following steps to create pyramids for a raster

  1. Start QGIS.
  2. From the Plugins menu, select Python Console.
  3. Import the processing module:
    import processing
    
  4. Run the 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)
    
  5. Now, load the raster into QGIS by dragging and dropping it from the filesystem onto the map canvas.
  6. Double-click on the layer name in the map's legend to open the Layer Properties dialog.
  7. In the Layer Properties dialog, click on the Pyramids tab and verify that the layer has multiple resolutions listed.

How it works...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset