Compress a Raster File and Generate a Raster World File in QGIS

Compress a Raster File and Generate a Raster World File in QGIS

A big size raster file usually can be compressed to reduce its size. A lot of QGIS raster tools/commands have a built-in option to select a method to compress a raster file when you Clip, Save as, Translate (Convert Format), or Warp a raster file (or other commands with generating a raster file as output). As shown in Figure 1, the built-in option is in “Profile” under “Advanced Parameters” or “Create Options”.

Figure 1

There are several different ways (parameter settings) to compress a raster file as shown in Figure 1: Low Compression, High Compression, and JPEG Compression.

  • Lossless Compression: Low Compression and High Compression – the output raster file has the exact pixel values as the original raster file, so it can be used for DEM or other raster files requiring the exact pixel values.
  • Lossy Compression: JPEG Compression – higher compression ratio than lossless compression, but the output raster file does not have the exact pixel values as the original raster file, so it can be used to compress orthophotos or satellite imagery files but should NOT be used for raster files requiring the exact pixel values.

In QGIS, by default, Low Compression (Figure 2) parameter is set as COMPRESS – PACKBITS, while High Compression (Figure 3) parameters are set as COMPRESS – DEFLATE, PREDICTOR – 2, and ZLEVEL – 9.

Figure 2
Figure 3

For JPEG Compression in QGIS, by default, the corresponding parameters are set as COMPRESS – JPEG AND JPEG_QUALITY – 75 (Figure 4). If you want to further reduce the output raster file size by JPEG Compression, you may change the parameter of JPEG_QUALITY from the default 75 to 60, 50, or another smaller value.

Figure 4

It appears that XPSWMM (Version 2020) has an issue when loading background image with a raster file compressed by JPEG Compression method. As an alternative, try to use High Compression (COMPRESS – DEFLATE) if you want to compress a background image raster file before loading it to XPSWMM.

Certain raster image formats, such as GeoTIFF (*.tif) contain the georeference information in the header of a raster image file itself which GIS software can read and understand, however, sometimes such a file still needs a separate world file so that software other than GIS can read and load it correctly (XPSWMM for example). To create a copy of a raster image file with a world file, click the green color “+” button to add an additional row in “Profile” under “Advanced Parameters” or “Create Options” and type in tfw under Name field (here output file format is set as a *.tif file) and yes under Value field (Figure 5). Similar to raster compression, this can also be done by a lot of QGIS built-in raster tools, such as Save as, Clip, Translate (Convert Format), and Warp. You can just add a world file without the need of compressing it at the same time. Refer to this post for more information about generating a background image file with world file for XPSWMM.

Figure 5

Leave a Reply

Your email address will not be published. Required fields are marked *