LinuxCommandLibrary

gdal_translate

Convert raster data between different formats

TLDR

Convert a raster dataset to JPEG format

$ gdal_translate -of [JPEG] [path/to/input.tif] [path/to/output.jpeg]
copy

Assign a projection to a raster dataset
$ gdal_translate -a_srs [EPSG:4326] [path/to/input.tif] [path/to/output.tif]
copy

Reduce the size of a raster dataset to a specific fraction
$ gdal_translate -outsize [40%] [40%] [path/to/input.tif] [path/to/output.tif]
copy

Convert a GeoTiff to a Cloud Optimized GeoTiff
$ gdal_translate [path/to/input.tif] [path/to/output.tif] -of COG -co COMPRESS=LZW
copy

SYNOPSIS

gdal_translate [-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}] [-of format] [-co "NAME=VALUE"]* [-a_ullr ulx uly lrx lry] [-apply-pm] [-b band]* [-mo "META-TAG=VALUE"]* [-gcp pixel line easting northing [z]]* [-outsize xsize[%%] ysize[%%]] [-a_nodata value] [-init "value[,value...]"] [-a_srs srs_def] [-projwin ulx uly lrx lry] [-srcwin xoff yoff xsize ysize] [-epo] [-woo] [-r {near/bilinear/cubic/cubicspline/lanczos/average/rms/gauss/max/min/med mode/q1/q3}] [-strict] [-s_srs srs_def] [-t_srs srs_def] [-tr xres yres] [-tap] [-norat] [-scale [dn_min [dn_max [ref_min [ref_max]]]]] [-exponent scale_exponent] [-unscale] [-q] src_dataset dst_dataset

PARAMETERS

-a_nodata <value>
    Set nodata value for output bands.

-a_srs <srs_def>
    Assign/override input SRS.

-apply-pm
    Apply pixel masking.

-b <band>
    Select input band(s) (default all).

-co "NAME=VALUE"
    Format-specific creation options.

-epo
    Write color table in pseudocolor (PCL) format.

-exponent <value>
    Apply power-law brightness scaling.

-gcp <pixel> <line> <easting> <northing> [<z>]
    Add Ground Control Point.

-init "value[,value...]"
    Initialize output bands with values.

-mo "META-TAG=VALUE"
    Set metadata.

-norat
    Do not process RAT (Raster Attribute Table).

-of <format>
    Select output format (e.g., GTiff).

-ot <type>
    Set output data type (Byte, Float32, etc.).

-outsize <xsize[%]> <ysize[%]>
    Resample to target size.

-projwin <ulx> <uly> <lrx> <lry>
    Subset via target georeferenced window.

-q
    Suppress progress display.

-r <method>
    Resampling method (near, bilinear, etc.).

-scale [[<dn_min>] [<dn_max>] [<ref_min>] [<ref_max>]]
    Scale input pixels linearly.

-srcwin <xoff> <yoff> <xsize> <ysize>
    Subset via source pixel window.

-strict
    Fail on unrecognized format options.

-s_srs <srs_def>
    Override source SRS.

-t_srs <srs_def>
    Set target SRS.

-tap
    Align target resolution to pixels.

-tr <xres> <yres>
    Set target resolution.

-unscale
    Remove scale/offset from source.

-woo
    Invert geotransform for world-to-output.

-a_ullr <ulx> <uly> <lrx> <lry>
    Subset via upper left/lower right coords.

DESCRIPTION

gdal_translate is a command-line utility from the GDAL (Geospatial Data Abstraction Library) toolkit for converting raster datasets between various formats. It supports reading from hundreds of input formats (e.g., GeoTIFF, JPEG, PNG, NetCDF) and writing to many output formats, making it essential for geospatial data processing.

Key capabilities include subsetting via pixel windows or geographic bounds, setting output data types, defining nodata values, embedding metadata and projections, scaling pixel values, and applying simple resampling during size changes. It preserves georeferencing, color tables, and overviews where possible but does not perform reprojection or warping (use gdalwarp for that).

Usage is straightforward for batch processing in scripts, GIS workflows, or preparing data for analysis in tools like QGIS or ArcGIS. Creation options allow format-specific tweaks, such as compression levels for GeoTIFF. Output filenames infer format from extension unless overridden with -of.

It's efficient for large files, supports VSI virtual file systems (e.g., /vsizip/), and handles multi-band data seamlessly.

CAVEATS

Does not reproject data (use gdalwarp); limited to simple scaling/resampling. Some formats lack full read/write support. Multi-threaded only via creation options. Large files may require significant memory.

SUPPORTED FORMATS

Use gdalinfo --formats for full list; common: GTiff, PNG, JPEG, NetCDF, HDF5, GRIB.

VIRTUAL FILE SYSTEMS

Supports /vsicurl/, /vsizip/, /vsis3/ for remote/cloud access.

HISTORY

Part of GDAL, started by Frank Warmerdam in 1998; first stable release ~2001. Evolved with open-source community contributions, now at GDAL 3.x (2020s), supporting 200+ formats due to ongoing format driver development.

SEE ALSO

Copied to clipboard