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.
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.
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:
processing
module:import processing
rasterLyr = QgsRasterLayer("/qgis_data/rasters/SatImage.tif", "Resample") rasterLyr.isValid()
epsg = rasterLyr.crs().postgisSrid() srs = "EPSG:%s" % epsg
res = rasterLyr.rasterUnitsPerPixelX() * 2
0
is the nearest neighbor), any additional parameters, 0
for output raster data type, and the output filename:processing.runalg("gdalogr:warpreproject", rasterLyr, srs, srs, res, 0, None, 0, "/qgis_data/rasters/resampled.tif")
resampled.tif
image was created in your /qgis_data/rasters
directory.It is counterintuitive at first to reduce the resolution by multiplying it. However, by increasing the spatial coverage of each pixel, it takes less pixels to cover the extent of the raster. You can easily compare the difference between the two in QGIS visually by loading both the images and zooming to an area with buildings or other detailed structures and then turning one layer off or on.