gdal_translate
Convert raster data between different formats
TLDR
Convert a raster dataset to JPEG format
Assign a projection to a raster dataset
Reduce the size of a raster dataset to a specific fraction
Convert a GeoTiff to a Cloud Optimized GeoTiff
SYNOPSIS
gdal_translate [options]
src_filename: The path to the source raster dataset.
dst_filename: The path for the output raster dataset.
PARAMETERS
-of
Select the output format. Common formats include GeoTIFF (GTiff), ERDAS Imagine (HFA), PNG, JPEG, NetCDF, etc.
-ot
Specify the output data type. Examples: Byte, UInt16, Int16, UInt32, Int32, Float32, Float64.
-sds
Copy all subdatasets from the input to the output. Each subdataset becomes a new file.
-b
Select specific input band(s) to process. Can be used multiple times.
-mask
Specify an input band to use as a mask band for the output dataset.
-srcwin
Select a rectangular region from the source image using pixel/line coordinates.
-projwin
Select a rectangular region from the source image using georeferenced coordinates (e.g., longitude/latitude).
-outsize
Set the output file size in pixels and lines, or as a percentage of the input (e.g., 50%).
-tr
Set the output file resolution in georeferenced units.
-r
Select a resampling algorithm. Options: near, bilinear, cubic, cubicspline, lanczos, average, mode.
-a_srs
Assign a coordinate system to the output. Can be a WKT string, EPSG code, Proj.4 string, etc.
-a_ullr
Assign georeferenced coordinates for the upper-left and lower-right corners of the output image.
-a_nodata
Assign a NoData value to the output bands.
-scale [
Apply a linear scaling to pixel values. Can specify input/output ranges.
-co
Specify creation options for the output format. These are format-specific (e.g., TFW=YES for GeoTIFF).
-mo
Add metadata to the output dataset.
-q
Suppress progress messages and other non-error output (quiet mode).
-v
Report more details about the process (verbose mode).
DESCRIPTION
gdal_translate is a fundamental utility within the GDAL (Geospatial Data Abstraction Library) suite. It serves as a versatile tool for converting raster images between various formats, performing fundamental image manipulations, and handling georeferencing information.
Its primary function is to transform a source dataset into a new destination dataset, allowing users to:
- Change the file format (e.g., GeoTIFF to PNG, NetCDF to JPEG).
- Adjust the spatial resolution or dimensions of the image.
- Subset or clip regions of interest from a larger image.
- Change the data type of the pixel values (e.g., float to byte).
- Assign or modify georeferencing information, such as coordinate systems or ground control points (GCPs).
- Apply scaling, offset, or NoData value transformations.
- Copy metadata and color interpretation information.
gdal_translate is widely used in GIS, remote sensing, and mapping workflows for preparing data for analysis, visualization, or integration into different systems. It leverages the extensive driver support of the GDAL library, enabling compatibility with a vast array of raster formats.
CAVEATS
gdal_translate is a powerful tool, but users should be aware of a few considerations:
1. Memory Usage: For very large datasets, processing can consume significant memory, especially when resampling or changing data types.
2. Driver Dependencies: The availability of input and output formats depends on how the GDAL library was compiled. Some formats might require specific external libraries.
3. Georeferencing Nuances: While -a_srs and -a_ullr assign georeferencing, they do not reproject data. For reprojection, gdalwarp is the appropriate command.
4. Creation Options: Understanding format-specific creation options (-co) is crucial for optimizing output size, compression, and internal structure. Refer to GDAL's format-specific documentation for details.
GDAL DRIVERS
gdal_translate leverages GDAL drivers to read and write numerous raster formats. To see a list of supported formats and their capabilities, use the command gdalinfo --formats.
Each driver may support specific creation options (-co) which can be found in the GDAL online documentation for that particular format.
COORDINATE SYSTEMS
When dealing with coordinate systems, GDAL supports various definitions including EPSG codes (e.g., EPSG:4326 for WGS84), WKT (Well-Known Text) strings, or Proj.4 strings. Correctly specifying the SRS is critical for geospatial data integrity.
HISTORY
gdal_translate is a core component of the GDAL (Geospatial Data Abstraction Library) project, which was initiated by Frank Warmerdam in 1998. GDAL quickly became the de facto standard for reading and writing raster and vector geospatial data formats.
As one of the earliest and most fundamental utilities provided by the library, gdal_translate has evolved alongside GDAL itself. Its design reflects GDAL's philosophy of providing a consistent API and command-line interface for diverse geospatial data, abstracting away the complexities of different file formats. Over the years, it has seen continuous development, with new options added to support advanced transformations, broader format compatibility, and improved performance, cementing its role as an indispensable tool in the geospatial community.