Part of the GDAL/OGR cheat sheet.
gdalinfo input.tifgdal_translate --formatsRequires libgeotiff.
listgeo -tfw mappy.tifRequires libgeotiff.
listgeo -proj4 mappy.tifgdal_translate -of "GTiff" input.grd output.tifUseful for Landsat 8 imagery.
gdal_translate -of "GTiff" -co "COMPRESS=LZW" -scale 0 65535 0 255 -ot Byte input_uint16.tif output_byte.tifYou can change '0' and '65535' to your image's actual min/max values to preserve more color variation or to apply the scaling to other band types. Find those numbers with:
gdalinfo -mm input.tif | grep Min/MaxAll files must be of the same format:
basename -s.img *.img | xargs -n1 -I % gdal_translate -of "GTiff" %.img %.tifgdalwarp -t_srs "EPSG:102003" input.tif output.tifBe sure to add -r bilinear if reprojecting elevation data to prevent funky
banding artifacts.
gdal_translate -of GTiff -a_ullr <top_left_lon> <top_left_lat> <bottom_right_lon> <bottom_right_lat> \
-a_srs EPSG:4269 input.png output.tifgdalwarp -te <x_min> <y_min> <x_max> <y_max> input.tif clipped_output.tifgdalwarp -dstnodata <nodata_value> -cutline input_polygon.shp input.tif clipped_output.tifgdalwarp -cutline cropper.shp -crop_to_cutline input.tif cropped_output.tifgdal_merge.py -o merged.tif input1.tif input2.tifAlternatively:
gdalwarp input1.tif input2.tif merged.tifOr, to preserve nodata values:
gdalwarp input1.tif input2.tif merged.tif -srcnodata <nodata_value> -dstnodata <merged_nodata_value>Where LC81690372014137LGN00 is a Landsat 8 ID and B4, B3 and B2 correspond
to the R, G and B bands respectively:
gdal_merge.py -co "PHOTOMETRIC=RGB" -separate LC81690372014137LGN00_B{4,3,2}.tif -o LC81690372014137LGN00_rgb.tifgdal_merge.py -co "PHOTOMETRIC=RGB" input.tif -o output_rgb.tifgdal_translate -of KMLSUPEROVERLAY input.tif output.kmz -co FORMAT=JPEGAverage two rasters:
gdal_calc.py -A input1.tif -B input2.tif --outfile=output.tif --calc="(A+B)/2"Add two rasters:
gdal_calc.py -A input1.tif -B input2.tif --outfile=output.tif --calc="A+B"And so on.
gdaldem hillshade -of PNG input.tif hillshade.pngChange the light direction:
gdaldem hillshade -of PNG -az 135 input.tif hillshade_az135.pngUse the correct vertical scaling in meters if the input is projected in degrees:
gdaldem hillshade -s 111120 -of PNG input_WGS1984.tif hillshade.pngFirst, create a color-ramp.txt file, with lines of height, red, green,
blue:
0 110 220 110
900 240 250 160
1300 230 220 170
1900 220 220 220
2500 250 250 250Then apply those colors to a DEM:
gdaldem color-relief input.tif color_ramp.txt color-relief.tifFirst, make a slope raster from the DEM:
gdaldem slope input.tif slope.tifSecond, create a color-slope.txt file, with lines of slope angle, red,
green, blue:
0 255 255 255
90 0 0 0Finally, color the slope raster based on the angles in color-slope.txt:
gdaldem color-relief slope.tif color-slope.txt slopeshade.tifgdalwarp -ts <width> <height> -r cubic dem.tif resampled_dem.tifEntering 0 for either width or height guesses it from the current dimensions.
Alternatively:
gdal_translate -outsize 10% 10% -r cubic dem.tif resampled_dem.tifFor both of these, -r cubic specifies cubic interpolation: when resampling
continuous data (like a DEM), the default nearest neighbor interpolation can
result in "stair step" artifacts.
gdal_rasterize -b 1 -i -burn -32768 -l layername input.shp input.tifgdal_polygonize.py input.tif -f "GeoJSON" output.jsongdal_contour -a elev -i 50 input_dem.tif output_contours.shpgdallocationinfo -xml -wgs84 input.tif <lon> <lat>Assumes data for the entire globe in WGS84. Be sure to specify the band, or you may end up with a nonsense RGB image composed of the first three.
gdal_translate input.grib -a_ullr -180 -90 180 90 -a_srs EPSG:4326 -b 1 output_band1.tifgdal_edit.py -offset 0 -scale 3.05185094759971e-05 input.tifgdal_edit.py -unsetnodata input.tifgdal_edit.py -a_nodata -32768 input.tifLinks to this page: GDAL/OGR cheat sheet
Last edited Thu 15 October 2026