LinuxCommandLibrary

gdalwarp

Reproject and transform raster images

TLDR

Reproject a raster dataset

$ gdalwarp -t_srs [EPSG:4326] [path/to/input.tif] [path/to/output.tif]
copy

Crop a raster dataset by using specific coordinates
$ gdalwarp -te [min_x] [min_y] [max_x] [max_y] -te_srs [EPSG:4326] [path/to/input.tif] [path/to/output.tif]
copy

Crop a raster dataset using a vector layer
$ gdalwarp -cutline [path/to/area_to_cut.geojson] -crop_to_cutline [path/to/input.tif] [path/to/output.tif]
copy

SYNOPSIS

gdalwarp [options] source_file(s) dest_file

PARAMETERS

-s_srs srs_def
    Defines the source spatial reference system. This can be specified as a PROJ.4 string, WKT, EPSG code, or filename.

-t_srs srs_def
    Defines the target spatial reference system. This can be specified as a PROJ.4 string, WKT, EPSG code, or filename.

-geoloc
    Specifies that the output file should be geolocated based on the input's GCPs.
This is deprecated and should be replaced with -gcp 0 0 0 0

-gcp pixel line easting northing [elevation]
    Adds the indicated ground control point. Easting, northing and elevation are in the coordinate system defined by -s_srs. The pixel and line location is in the source image.

-te xmin ymin xmax ymax
    Sets the georeferenced extents of the output file. All values should be expressed in target SRS coordinates.

-tr xres yres
    Sets the target resolution. The values must be expressed in target SRS units. Both xres and yres must be positive values.

-ts width height
    Sets the output file size in pixels. Note that -ts cannot be used with -tr.

-r resampling_method
    Selects a resampling method. Options include near (nearest neighbour), bilinear, cubic, cubicspline, lanczos, average, mode, max, min, med, q1, q3.

-of format
    Selects the output format name. The default is GeoTIFF.

-co "NAME=VALUE"
    Passes a creation option to the output format driver. Multiple -co options may be listed.

-cutline datasource
    Uses the specified datasource (vector layer) to cut the output image to the shape of the layer's geometry.
Requires -crop_to_cutline.

-crop_to_cutline
    Crops the output raster to the extent of the cutline.

-wm memory_in_mb
    Set the amount of memory (in MB) that gdalwarp is allowed to use. (Defaults to 64MB)

-multi
    Enable use of multi-threaded warping implementation.

-q
    Suppress progress messages.

DESCRIPTION

gdalwarp is a powerful command-line utility for image warping, reprojection, and image transformation. It can reproject raster images from one coordinate system to another, resize images, perform image mosaicking, and apply various other image transformations. It supports a wide range of input and output formats through the GDAL (Geospatial Data Abstraction Library) library. gdalwarp effectively allows for the manipulation and combination of geospatial raster data, enabling users to prepare data for various applications, including mapping, analysis, and visualization.

It utilizes a grid warping approach or a more accurate control point based warping. The power of gdalwarp comes from its ability to perform sophisticated warping operations while providing fine-grained control over the process through numerous command-line options.

gdalwarp is an essential tool for any geospatial data professional working with raster data.

CAVEATS

gdalwarp can be resource-intensive, especially for large datasets. Using appropriate memory allocation and tiling strategies is important to prevent excessive memory usage or slow processing.

COORDINATE SYSTEMS

When specifying coordinate systems with -s_srs or -t_srs, ensure that the definition is accurate and corresponds to the actual spatial reference system of the data. Incorrect coordinate system definitions can lead to inaccurate warping results.

RESAMPLING METHODS

The choice of resampling method significantly affects the quality of the warped image. Nearest neighbour is fastest but can introduce blocky artifacts. Bilinear, cubic, and other methods provide smoother results but are computationally more expensive. Select the resampling method that best balances processing speed and image quality for your specific application.

WARPING ORDER

The -order parameter is important when using the polynomial or TPS warping methods. Higher order warping can potentially improve accuracy but can also introduce unwanted distortions. Experiment to determine the appropriate order for your data and application.

SEE ALSO

Copied to clipboard