GDAL Utilities

A collection of snippets for GDAL, the best commandline utility suite for processing rasters (used under the hood by a lot of Esri tools as well).

Optimized gdalwarp commandline for converting any image of known coordinate system to Yukon Albers:

gdalwarp ^
  --config GDAL_CACHEMAX 350 ^
  -wm 350 ^
  -multi ^
  -co TILED=YES ^
  -co COMPRESS=LZW ^
  -t_srs EPSG:3579 ^
  -r cubic ^
  %Infiles% ^
  outfile.tif

3 Band images:

set _opts= -r gauss ^
  --config PHOTOMETRIC_OVERVIEW=YCBCR ^
  --config INTERLEAVE_OVERVIEW PIXEL ^
  --config COMPRESS_OVERVIEW=JPEG ^
  --config JPEG_QUALITY_OVERVIEW=85 ^
  --config USE_RRD=NO

From <http://www.northrivergeographic.com/archives/pyramid-layers-qgis-arcgis>

 

GDAL_CACHEMAX option. With this you can increase the GDAL block-cache from the standard value to something more fitting of your system. This had no effect on the write times but decreased my read times by ca. 50%. (more)

From <http://www.digital-geography.com/geotiff-compression-comparison/>

 

Elevation data:

set _opts= -r gauss --config COMPRESS_OVERVIEW JPEG ^
  --config JPEG_QUALITY_OVERVIEW 85 --config USE_RRD NO

Optimal LZW Compression

Photoshop users will note that it achieves noticeably smaller files on the same data than does gdal (using the defaults). One can improve gdal compression, though still not match Photoshop, by using the -co predictor=[1/2/3] option.

gdal_translate -co compress=lzw -co predictor=2 -co tiled=yes ^
  inimage.tif outimage.tif

The default is 1 (no predictor), 2 is horizontal differencing and 3 is floating point prediction. If your image is not floating point you will not get any effect from predictor 3. For integer data (e.g. byte) choose predictor 2.

To see what compression scheme and predictor Photoshop or whatever has used on a tiff file, use the tiffinfo utility.

Smallest overviews

To produce the smallest possible JPEG-In-TIFF overviews, you should add to your gdaladdo command line:

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

gdaladdo -ro --config USE_RRD YES --config COMPRESS_OVERVIEW JPEG ^
  --config PHOTOMETRIC_OVERVIEW YCBCR --config INTERLEAVE_OVERVIEW PIXEL ^
  --config JPEG_QUALITY_OVERVIEW 85 -r gauss N60-W138_ll.tif 2 4 8 16 32 64

From <https://trac.osgeo.org/gdal/wiki/UserDocs/GeoTiff, http://www.gdal.org/gdaladdo.html>

Convert

gdal_translate -ot byte -a_nodata 256 -co compress=lzw -co predictor=2 ^
-co tiled=yes -scale 0 255 0 254 Arctic_Clip.tif compressed\Arctic3.tif

Leave a Reply

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