5

I'm new to GDAL and its utilities. My experience with both these programs (Warp and Translate) doesn't go much further than doing some image clipping, whether by coordinate's bounding box (that I do with both programs), "size"'s bounding box (that I only can do with translate) or use a polygon cut-line (that I only can do with gdalwarp).

Besides these clipping operations, what other operations can I do? And from those which are exclusive from each program.

Vince
  • 20,017
  • 15
  • 45
  • 64
Ruben Silva
  • 123
  • 1
  • 7
  • This https://gdal.org/programs/gdal_translate.html and https://gdal.org/programs/gdalwarp.html should help a bit. Fundamental difference is that gdalwarp can reproject rasters between different coordinate reference systems but gdal_translate can't. With gdal_translate it is more straight forward to translate data between the supported raster formats https://gdal.org/drivers/raster/index.html. – user30184 Jun 11 '20 at 00:43

2 Answers2

7

In some ways gdalwarp is a generalization and improvement on gdal_translate.

gdalwarp can reproject rasters, this covers much of what gdal_translate can do (resize, crop, resample, convert format etc). It uses a different kind of settings, you specify the 'target grid properties', whereas with translate you specify 'crop/outsize'.

It is also more performant and better parallelizable see arguments -multi and -wo NUM_THREADS.

https://gdal.org/programs/gdalwarp.html

gdal_translate is more suitable if you need to assign the extent or crs to a raster that has incorrect metadata.

Griffith Rees
  • 125
  • 1
  • 4
mdsumner
  • 8,196
  • 1
  • 27
  • 30
4

Beside the information you can get from https://gdal.org/programs/index.html, there are a lot more hidden options, which are sometimes hard to find.

It takes plenty of time to make oneself familiar with the myriads of parameters the command line tools offer.

Use gdal_translate to add ground control points (GCPs) to a raw image (aka: georeferencing) and gdalwarp to reproject and crop this image (-cutline datasource -crop-to-cutline).

When making use of gdal_translate to convert or compress images, you have many choices to get optimal results regarding file size, processing speed and/or image quality.

You can find a good explanation here: http://blog.cleverelephant.ca/2015/02/geotiff-compression-for-dummies.html

These are my preferred settings for the compression of 3 different kinds of GeoTIFF files:

non-transparent Color-GeoTiff (i.e. arial photos):
gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR -co TILED=YES -co JPEG_QUALITY=90 -b 1 -b 2 -b 3 --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS  <source.tif> <target.tif>

transparent Color-GeoTiff (i.e. CAD drawings): gdal_translate -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 -co TILED=YES --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS <source.tif> <target.tif>

monochrome 1bit-GeoTiff (i.e. scanned hand-drawn maps): gdal_translate -co COMPRESS=CCITTFAX4 -co PHOTOMETRIC=MINISWHITE -co NBITS=1 -co TILED=YES --config GDAL_CACHEMAX 1024 -co NUM_THREADS=ALL_CPUS <source.tif> <target.tif>

If you like, you can use environment variables instead of the -co and --config options (i.e. in Windows: set GDAL_CACHEMAX=1024).

To achieve better loading performance, I often add overviews to my images:

gdaladdo --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR --config GDAL_TIFF_INTERNAL_MASK YES -r cubicspline <source.tif> 2 4 8 16

My tips:

Acquaint yourself with the available raster file formats (https://gdal.org/drivers/raster/index.html) and their possible Open- and Creation-Options.

Read the GDAL Config-Options: https://gdal.org/user/configoptions.html

Take some time and dig into the description of the GDAL Virtual Raster Format (https://gdal.org/drivers/raster/vrt.html#raster-vrt) which you can use to merge multiple images:

Merging all tiles from one directory using GDAL

Search in gis.stackexchange.com: https://gis.stackexchange.com/search?tab=newest&q=%5bgdal%5d%20gdal_translate%20gdalwarp

christoph
  • 5,605
  • 1
  • 20
  • 34