[GIS] Set default GDAL/OGR config options

command linegdalgdaladdo

Is there a method to save GDAL/OGR Utilities --config default options?

For example I almost always want to use the option for smallest possible jpeg-in-tiff overviews, but that's a lot of frequent typing and/or pasting:

--config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR --config INTERLEAVE_OVERVIEW PIXEL

Can I set my shell to always use those options unless I specifically want otherwise? (Windows CMD most of the time, but Linux answer would be good too).

Best Answer

To answer your question directly - no, I don't think it's possible.

To workaround, use the *nix alias concept...

On Windows:

  • You can make your current method permanent by using setx or the Windows user environment variables GUI.
  • You can fake an alias by setting an env var to the command + config options (note need to open a new cmd prompt to use the env var set by setx, note lack of "=" and entire command must be on one line):

setx gdaljpgo "gdaladdo -r gauss --config PHOTOMETRIC_OVERVIEW=YCBCR --config INTERLEAVE_OVERVIEW PIXEL --config COMPRESS_OVERVIEW=JPEG --config JPEG_QUALITY_OVERVIEW=85"

C:\> %gdaljpgo% input.tif 2 4 8 16 32
  • You can use a shell that directly supports aliases, such as Windows Powershell or (my fave) the Git for Windows Bash prompt.

  • You can use the doskey command to set an alias/macro (note limitations in this answer)

On Linux:

  • set an alias in your shell startup, i.e. ~/.bashrc.

alias gdaljpgo='gdaladdo -r gauss \
                         --config PHOTOMETRIC_OVERVIEW=YCBCR \
                         --config INTERLEAVE_OVERVIEW PIXEL \
                         --config COMPRESS_OVERVIEW=JPEG \
                         --config JPEG_QUALITY_OVERVIEW=85'