gdal_translate
What is gdal_translate?
gdal_translate is the GDAL command-line utility for converting rasters between formats and performing non-warp transformations: changing driver, selecting or reordering bands, casting data types, clipping to a pixel or georeferenced window, rescaling pixel values, and setting creation options like compression and tiling. It does not reproject — pair it with gdalwarp for CRS changes — but it is the right tool for everything else you do to a raster before or after a warp.
gdal_translate [options] <src_dataset> <dst_dataset>Commonly used options:
-of <format>— output driver (GTiff,COG,PNG,JPEG,NetCDF,VRT, etc.)-ot <type>— output data type (Byte,UInt16,Int16,Float32,Float64, …)-b <band>— select input band(s); repeatable for multi-band output-mask <band>— set an explicit mask band-projwin <ulx> <uly> <lrx> <lry>— clip to a georeferenced window-srcwin <xoff> <yoff> <xsize> <ysize>— clip to a pixel window-outsize <xsize|xpct> <ysize|ypct>— resize output (percent or pixels)-scale [<src_min> <src_max> [<dst_min> <dst_max>]]— rescale pixel values-a_nodata <value>/-a_srs <crs>— assign NoData or CRS without resampling-co <NAME>=<VALUE>— creation options (e.g.COMPRESS=DEFLATE,TILED=YES)-expand <gray|rgb|rgba>— expand a paletted raster into component bands
When would you use gdal_translate?
Use gdal_translate whenever a raster needs to change format, shape, or pixel representation without warping. Typical jobs: converting a Float32 DEM to a smaller Int16 for hillshading, flipping a JPEG2000 down to an 8-bit PNG for a web preview, extracting bands 4-3-2 from a Sentinel-2 product to build a natural-colour composite, or clipping a raster to a rectangular study area with -projwin.
It is also the standard way to produce Cloud Optimized GeoTIFFs: gdal_translate in.tif out.tif -of COG -co COMPRESS=DEFLATE -co BIGTIFF=IF_SAFER. For subdatasets in NetCDF or HDF5, pass the full NETCDF:"file.nc":variable string as input to pull a single variable into a standalone GeoTIFF. When scaling pixel values for a visualisation, gdal_translate -scale 0 4000 0 255 -ot Byte gives you a web-friendly 8-bit render in one pass.
FAQs
When should I use gdal_translate versus gdalwarp?
Use gdal_translate when you are not changing the CRS and not resampling across a projection — format conversion, clipping, band selection, type casting, NoData assignment. Use gdalwarp when the pixel grid itself must change (reprojection, custom resolution with proper resampling, mosaicking, cutline clipping to a vector). They compose well: translate to extract, warp to reproject.
How do I build a Cloud Optimized GeoTIFF?
Modern GDAL includes a dedicated COG driver: gdal_translate in.tif out.tif -of COG -co COMPRESS=DEFLATE -co PREDICTOR=2 -co BLOCKSIZE=512. The driver takes care of internal tiling, overview generation, and IFD ordering. For older workflows without the COG driver, use -of GTiff -co TILED=YES -co COPY_SRC_OVERVIEWS=YES after building overviews with gdaladdo.
Why does -projwin give me an odd pixel offset?
-projwin coordinates are snapped to the nearest source pixel edge, so the output extent may differ from the values you requested by up to one pixel. If you need sub-pixel precision or an exact user-defined extent, use gdalwarp -te <xmin> <ymin> <xmax> <ymax> instead, which resamples to the requested grid.
Can gdal_translate reproject?
No. -a_srs only assigns a CRS label to the dataset without moving pixels — useful when a file lost its projection but the georeferencing is known, and catastrophic if misused. For actual reprojection, use gdalwarp -t_srs.