gdalwarp
Reproject and transform raster images
TLDR
Reproject a raster dataset
Crop a raster dataset by using specific coordinates
Crop a raster dataset using a vector layer
SYNOPSIS
gdalwarp [<options>] <source_dataset> [<source_dataset> ...] <destination_dataset>
PARAMETERS
-s_srs <srs_def>
Defines the spatial reference system of the source dataset. Can be an EPSG code (e.g., EPSG:4326), a PROJ.4 string, or a WKT string.
-t_srs <srs_def>
Defines the spatial reference system for the output dataset.
-r <resample_method>
Selects the resampling method to use (e.g., nearest, bilinear, cubic, average).
See 'Resampling Methods' in 'Additional' section for more details.
-of <format>
Specifies the output format (e.g., GTiff, PNG, JPEG). Defaults to the format of the source if not specified.
-ot <type>
Forces the output band data type (e.g., Byte, UInt16, Float32). Useful for memory and storage optimization.
-ts <width> <height>
Sets the target output file size in pixels and lines. One of these can be 0 to maintain aspect ratio.
-tr <xres> <yres>
Sets the output file resolution in target georeferenced units.
-te <xmin> <ymin> <xmax> <ymax>
Sets the output georeferenced extents of the output file. Coordinates are in target SRS units.
-cutline <filename>
Enables clipping the output raster to the extent of a vector cutline specified by a file (e.g., a shapefile).
-crop_to_cutline
Crops the output raster to the extent of the cutline's bounding box, potentially reducing the output file size.
-srcnodata <value>
Sets the source nodata value(s) to be ignored or treated as transparent.
-dstnodata <value>
Assigns a specific nodata value to the output raster where input data is missing or out of bounds.
-overwrite
Allows overwriting the existing destination dataset without prompting.
-multi
Uses a multi-threaded warping algorithm, potentially speeding up processing on multi-core systems.
-co <NAME=VALUE>
Passes creation options to the output format driver (e.g., COMPRESS=LZW for GeoTIFF).
DESCRIPTION
gdalwarp is a powerful command-line utility from the GDAL (Geospatial Data Abstraction Library) suite. Its primary function is to transform raster images from one coordinate system to another, a process commonly known as reprojection or warping. This tool is indispensable for geospatial data harmonization, allowing users to align datasets originating from different projections, resolutions, or geographic extents. Beyond simple reprojection, gdalwarp can mosaic multiple input rasters into a single output, clip data using a vector cutline, change output resolution, and apply various resampling algorithms. It supports a vast array of input and output raster formats and handles complex georeferencing information automatically, making it a fundamental component in GIS and remote sensing workflows.
CAVEATS
For large datasets or complex transformations, gdalwarp can be resource-intensive, requiring significant CPU and RAM. Incorrectly defined source or target spatial reference systems can lead to misaligned or erroneous output. While -multi can improve performance, it's not always a panacea for extremely large files, and I/O can still be a bottleneck.
RESAMPLING METHODS
The choice of resampling method (controlled by -r) significantly impacts the output raster's appearance and data integrity.
nearest (Nearest Neighbor): Fastest, preserves original pixel values, best for categorical data.
bilinear (Bilinear Interpolation): Smooths data, suitable for continuous data, calculates new pixel value from weighted average of 4 nearest pixels.
cubic (Cubic Convolution): Smoother than bilinear, uses 16 nearest pixels, good for continuous data but computationally more intensive.
average: Computes the average of all contributing pixels.
SPATIAL REFERENCE SYSTEMS (SRS)
Defining the SRS is crucial for accurate reprojection. SRS can be specified using various formats:
EPSG Codes: A widely recognized code for a coordinate system (e.g., EPSG:4326 for WGS84 Lat/Lon).
PROJ.4 Strings: A text string defining projection parameters (e.g., '+proj=utm +zone=10 +ellps=WGS84').
WKT (Well-Known Text): A more verbose, standard text representation of coordinate systems.
gdalwarp relies on the PROJ library for performing the actual coordinate transformations.
HISTORY
gdalwarp is a core utility within the GDAL (Geospatial Data Abstraction Library) project, which was initially released in 1998. As GDAL evolved into the de-facto standard for reading and writing raster and vector geospatial data, gdalwarp steadily gained features and optimizations. Its development has been driven by the needs of the geospatial community, incorporating advanced resampling algorithms, improved projection support (leveraging the PROJ library), and performance enhancements like multi-threading, making it a robust and indispensable tool for geospatial data processing.
SEE ALSO
gdalinfo(1), gdal_translate(1), gdaladdo(1), ogr2ogr(1)