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:


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).


3 Answers 3


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):


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'
  • Accepted as best practical and immediately available solution. Ideal would be for GDAL to load dot-gdal files following standard 'nix practice, a feature request waiting to happen. ;-) Sep 6, 2017 at 17:31
  • More on Windows aliases and doskey: stackoverflow.com/questions/20530996/… Sep 6, 2017 at 17:40
  • 1
    @Matt, one advantage of Win doskey over Win env vars or *nix aliases (though you can also do this with a bash function instead of an alias) is easily access arguments, so you could include overview levels in the"alias", doskey gdaljpgo=gdaladdo -r gauss etc... $1 2 4 8 16 32 where $1 will substitute the filename argument. Looks more painful to setup permanent doskey commands though.
    – user2856
    Sep 6, 2017 at 23:01
  • Oh, arguments access is a good point! (Won't be needed for gdaladdo in 2.3+ though, which calcs number of levels automatically) Sep 7, 2017 at 1:04

Your "set _opts" method is a tricky way for doing the same that is directly supported by --optfile http://www.gdal.org/gdal_utilities.html

--optfile file

Read the named file and substitute the contents into the command line options list. Lines beginning with # will be ignored. Multi-word arguments may be kept together with double quotes.

It is also possible to set the system level environmental variables with "export" or "set" https://trac.osgeo.org/gdal/wiki/ConfigOptions which will make them defaults for GDAL. The problem is that then the user may not know or remember what the defaults are. Optfile saves most part of writing, user still has full control for what happens, and it is easy to make different optfiles for example for jpeg compressed overviews for aerial images and deflate compressed ones for raster maps.

  • Thanks for reminding me of --optfile. I discarded and consequently forgot about this approach because typing gdaladdo --optfile %HOME%\gdal.opt is still too much. I guess what I'm looking at is a feature request for gdal utils to pick up the file automatically if it exists. Sep 6, 2017 at 17:25
  • There should be many optfiles because what would be fine default optfile for gdaladdo would make no sense at all for ogr2ogr or gdal_translate.
    – user30184
    Sep 7, 2017 at 11:55

This is what I do now:

set _opts= -r gauss ^

gdaladdo %_opts% infile.tif

It's not ideal, but works to some extent. I'm happy to drop it for a more comprehensive solution (such as reading .gdal file in HOME?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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