1

I have a very huge GeoTIFF file (around 12GB).

enter image description here

Most of it is made with white spaces. So, I thought that if I removed these white spaces from it, the GeoTIFF file would reduce its size to something smaller than 12GB. After researching for a while, I found this solution:

gdalbuildvrt -srcnodata "0 0 0" virtualimage.vrt myTiffFile.tif
gdal_translate virtualimage.vrt outputTiffFile.tif

However, even though I can validate on QGIS that it has written No Data on whitespaces, the size of my GeoTIFF file is still 12GB. I'm not sure what's happening, can I reduce the size of a GeoTIFF layer by writing No Data to white pixels? If not, how can I reduce its size?

4
  • 4
    In uncompressed image every pixel takes the same amount of space. Contiguous areas with same pixel values can fortunately be compressed well even with lossless methods. Try gdal_translate virtualimage.vrt outputTiffFile.tif -co compress:deflate -co tiled=yes and feel the difference. Tile the image by the same, it is always a good default with any bigger images.
    – user30184
    Nov 25 '21 at 21:33
  • @user30184 Cool, it went from 12GB to 18MB in my case... Is there any downside of compressing it like this?
    – raylight
    Nov 25 '21 at 22:48
  • 2
    As @user30184 said, the command line calls a lossless compression algorithm. So there is no downside in the quality of the image. Depending on the relative speed of your processor vs. disk I/O, you might have a slowdown in loading the file because it has to be decompressed to be used in most applications. This will be most apparent on a system with a fast disk (eg, SSD) and slow CPU. You might actually come out ahead on a system with slow disk and fast CPU.
    – Llaves
    Nov 26 '21 at 4:00
  • @user30184 - please add your comment as an answer
    – Ian Turton
    Nov 26 '21 at 10:17
2

I uncompressed TIFF files each pixel takes a fixed number of bits. However, TIFF files can be compressed and contiguous areas with uniform pixel values like the nodata-area in your image can be compressed extremely well even with lossless compression method like "deflate" https://en.wikipedia.org/wiki/Deflate.

Basic command for creating a deflate compressed and tiled image from a GDAL virtual raster file with gdal_translate:

gdal_translate -of GTiff  -co compress=deflate -co tiled=yes virtualimage.vrt outputTiffFile.tif

Tiling makes it possible for client programs to access small areas of interest from a large tiff file efficiently without reading all too much unnecessary pixels.

1

To go along with the answer by user30184, adding the following will further decrease your file size:

-co PREDICTOR=2

Reference: https://kokoalberti.com/articles/geotiff-compression-optimization-guide/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.