[GIS] osgeo.gdal.Translate – How to set compression on GDAL GTiff driver

gdalgdal-translate

How do I force the use of compression on the GTiff driver when called from osgeo.gdal in Python?

Example on the workflow, which currently reads LZW tiffs and dumps them to uncompressed tiffs.

from osgeo import gdal,gdalconst,osr
translateoptions = gdal.TranslateOptions(rgbExpand='RGB', format='GTiff')
outFile = gdal.Translate(gdaloutput, gdalinput, options=translateoptions)

Would be nice to do this without the use of subprocess.

Environment:

  • Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 11:27:44) [MSC v.1900 64 bit (AMD64)] on win32
  • gdal-2.2.2
  • libgdal-2.2.2

Best Answer

You have "creationOptions" for this:

translate_options = gdal.TranslateOptions(format = 'GTiff',
                                          creationOptions = ['TFW=YES', 'COMPRESS=LZW']
                                          )
Related Question