gdalwarp
What is gdalwarp?
gdalwarp is the GDAL command-line utility for reprojecting, warping, mosaicking, clipping, and resampling raster datasets. It is the workhorse tool for almost every raster transformation in a GIS pipeline and handles everything from swapping coordinate systems to stitching hundreds of tiles into a single mosaic.
gdalwarp [options] <src_dataset_1> [<src_dataset_2> ...] <dst_dataset>Commonly used options:
-t_srs <CRS>— target coordinate reference system (e.g.EPSG:3857)-tr <xres> <yres>— target pixel resolution-r <method>— resampling method (near,bilinear,cubic,cubicspline,lanczos,average,mode)-te <xmin> <ymin> <xmax> <ymax>— target extent-cutline <vector>— clip to a vector cutline-crop_to_cutline— shrink output extent to the cutline bounds-co <NAME>=<VALUE>— creation options (e.g.-co COMPRESS=DEFLATE)
When would you use gdalwarp?
Reach for gdalwarp whenever a raster needs to change shape, projection, or resolution before downstream analysis. Typical jobs: reprojecting a Landsat scene from UTM to Web Mercator for tile serving, mosaicking a folder of SRTM tiles into one continent-wide DEM, clipping a national land-cover raster to a study-area boundary, or resampling a 10-metre DEM down to 30 metres to match a coarser auxiliary dataset.
It is also the go-to tool for creating Cloud Optimized GeoTIFFs (COGs) as part of a preprocessing pipeline — often chained with gdal_translate and gdaladdo — and for warping drone orthomosaics into a standard national CRS before hand-off to analysts.
FAQs
Which resampling method should I use?
Use near (nearest neighbour) for categorical rasters like land cover or classified imagery — any other method will invent pixel values that don't exist in your legend. Use bilinear or cubic for continuous rasters like elevation or temperature. Use average or mode when downsampling to a coarser resolution. lanczos gives the sharpest visual result for imagery but is slower.
How do I mosaic many rasters into one file?
List all input files before the output file: gdalwarp tile1.tif tile2.tif tile3.tif mosaic.tif. For hundreds of tiles, write the list to a text file and use gdalbuildvrt to create a virtual raster first, then gdalwarp that VRT — it is dramatically faster than invoking warp on each tile.
How do I clip a raster to an irregular shape?
Use -cutline with a vector file (Shapefile, GeoPackage, GeoJSON) containing the clip polygon: gdalwarp -cutline boundary.gpkg -crop_to_cutline input.tif clipped.tif. Add -dstnodata 0 to mark pixels outside the cutline as nodata in the output.
Why is gdalwarp slow on my large raster?
Default settings are conservative. Speed it up with -multi (multithreaded warping), -wo NUM_THREADS=ALL_CPUS, and a larger cache via the environment variable GDAL_CACHEMAX=4096. Also ensure the source raster has overviews (gdaladdo) so GDAL can read downsampled pyramids instead of full-resolution pixels when you request a coarser target.