Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Resampling raster resolution


Resampling an image allows you to change the current resolution of an image to a different resolution. Resampling to a lower resolution, also known as downsampling, requires you to remove pixels from the image while maintaining the geospatial referencing integrity of the dataset. In the QGIS Processing Toolbox, the gdalogr:warpproject algorithm is used, which is the same as the algorithm used for reprojection.

Getting ready

We will again use the SatImage raster available at https://geospatialpython.googlecode.com/files/SatImage.zip.

Place this raster in your /qgis_data/rasters directory.

How to do it...

There's an extra step in this process, where we will get the current pixel resolution of the raster as a reference to calculate the new resolution and pass it to the algorithm. To do this, we need to perform the following steps:

  1. Start QGIS.

  2. From the Plugins menu, select Python Console.

  3. Import the processing module:

    import processing
    
  4. Load and validate the raster layer:

    rasterLyr...