GDAL_CALC(1)
β¨ GDAL_CALC(1) β¨ β the gdal_calc glow-up (GDAL manual, bestie edition)
okay so you opened the GDAL manual and landed on GDAL_CALC(1) β congrats, you're in the right place π this is the page for gdal_calc, the command line raster calculator, and it's genuinely iconic. let's get into it.
πΈ NAME πΈ
gdal_calc β command line raster calculator with numpy syntax. that's the whole vibe. numpy brain, terminal body. π
π SYNOPSIS π
gdal_calc.py --calc=expression --outfile=out_filename [-A filename]
[--A_band=n] [-B...-Z filename] [other_options]
π¦ DESCRIPTION π¦
Command line raster calculator with numpy syntax, periodt. use any basic arithmetic supported by numpy arrays β like +, -, *, and \ β along with logical operators such as >. it's giving math but make it a CLI β¨
heads up bestie π: all files must have the same dimensions (unless theextentoption is used), but no projection checking is performed (unless theprojectionCheckoption is used). so likeβ¦ it will simply not notice if your projections don't match. you've been warned π«Ά
π§ the options, one by one
--helpβ show this help message and exit. classic.-hβ the same as--help. same energy, shorter name π--calc=expressionβ the calculation itself, in numpy syntax using+,-,/,*, or any numpy array functions (i.e.log10()). multiple--calcoptions can be listed to produce a multiband file (GDAL >= 3.2). yes bestie, multiband β stack 'em ππ₯-A<filename>β input gdal raster file, and you can use any letter (a-z, A-Z). (lower case supported since GDAL 3.3 π)
a letter may be repeated (GDAL >= 3.3). the effect will be to create a 3-dim numpy array. in such a case, the calculation formula must use this input as a 3-dim array and must return a 2D array (see examples below). in case the calculation does not return a 2D array, an error would be generated. so like, read that twice, it matters π
--A_band=<n>β number of raster band for file A (default1).--outfile=<filename>β output file to generate or fill. the whole point, honestly.--NoDataValue=<value>β output NoDataValue (default: datatype specific value). to indicate not setting a NoDataValue use--NoDataValue=none(GDAL >= 3.3).
NOTE π: using the Python API:Nonevalue will indicate default datatype specific value.'none'value will indicate not setting a NoDataValue. yes they're different. no you cannot mix them up. i don't make the rules π
--hideNoDataβ new in version 3.3. ignores the input bands NoDataValue. by default, the input bands NoDataValue are not participating in the calculation. by setting this setting β no special treatment will be performed on the input NoDataValue, and they will be participating in the calculation as any other value. the output will not have a set NoDataValue, unless you explicitly specified a specific value by setting--NoDataValue=<value>. so it's a real "choose your fighter" situation π--type=<datatype>β output datatype, must be one of[Int32, Int16, Float64, UInt16, Byte, UInt32, Float32].
NOTE π: despite the datatype set using --type, when doing intermediate arithmetic operations using operands of the same type, the operation result will honor the original datatype. this may lead into unexpected results in the final result. not me finding this out the hard way β you don't have to, bestie π«Ά
--format=<gdal_format>β GDAL format for output file.color-table=<filename>β allows specifying a filename of a color table (or aColorTableobject) (with Palette Index interpretation) to be used for the output raster. supported formats:txt(i.e. likegdaldem, but color names are not supported),qlr,qml(i.e. exported from QGIS). aesthetic AND functional π--extent=<option>β new in version 3.3. this option determines how to handle rasters with different extents. this option is mutually exclusive with theprojwinoption, which is used for providing a custom extent. for all the options below the pixel size (resolution) and SRS (Spatial Reference System) of all the input rasters must be the same. the options:ignore(default) β only the dimensions of the rasters are compared. if the dimensions do not agree the operation will fail.failβ the dimensions and the extent (bounds) of the rasters must agree, otherwise the operation will fail.unionβ the extent (bounds) of the output will be the minimal rectangle that contains all the input extents.intersectβ the extent (bounds) of the output will be the maximal rectangle that is contained in all the input extents.
--projwin <ulx> <uly> <lrx> <lry>β new in version 3.3. this option provides a custom extent for the output, and it is mutually exclusive with theextentoption. pick one, babe β¨--projectionCheckβ new in version 3.3. by default, no projection checking will be performed. by setting this option, if the projection is not the same for all bands then the operation will fail. main character energy: it finally cares π--creation-option=<option>β passes a creation option to the output format driver. multiple options may be listed. see format specific documentation for legal creation options for each format.--co=<option>β the same ascreation-option. short and slay.--allBands=[a-z, A-Z]β process all bands of given raster (a-z, A-Z). requires a single calc for all bands. one calc to rule them all π₯--overwriteβ overwrite output file if it already exists. overwriting must be understood here as deleting and recreating the file from scratch. note that if this option is not specified and the output file already exists, it will be updated in place. so likeβ¦ very different outcomes, choose wisely π--debugβ print debugging information.--quietβ suppress progress messages. for when you just want peace π§ββοΈ
π PYTHON OPTIONS π
new in version 3.3. these are available by using the python interface of gdal_calc, and they are not available using the command prompt. iykyk π
user_namespaceβ a dictionary of custom functions or other names to be available for use in the Calc expression.return_dsβ if enabled, the output dataset would be returned from the function and not closed.color_tableβ allows specifying aColorTableobject (with Palette Index interpretation) to be used for the output raster.
β EXAMPLE β
okay bestie, this is the part where it all clicks. watch π
add two files together
gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"
average of two layers
gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="(A+B)/2"
NOTE π: in the previous example, beware that if A and B inputs are of the same datatype, for example integers, you may need to force the conversion of one of the operands before the division operation.
gdal_calc.py -A input.tif -B input2.tif --outfile=result.tif --calc="(A.astype(numpy.float64) + B) / 2"
add three files together (two options with the same result)
gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="A+B+C"
new in version 3.3:
gdal_calc.py -A input1.tif -A input2.tif -A input3.tif --outfile=result.tif --calc="numpy.sum(A,axis=0)"
average of three layers (two options with the same result)
gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="(A+B+C)/3"
new in version 3.3:
gdal_calc.py -A input1.tif -A input2.tif -A input3.tif --outfile=result.tif --calc="numpy.average(a,axis=0)"
maximum of three layers (two options with the same result)
gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="numpy.max((A,B,C),axis=0)"
new in version 3.3:
gdal_calc.py -A input1.tif -A input2.tif -A input3.tif --outfile=result.tif --calc="numpy.max(A,axis=0)"
set values of zero and below to null
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
using logical operator to keep a range of values from input
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*logical_and(A>100,A<150)"
work with multiple bands
gdal_calc.py -A input.tif --A_band=1 -B input.tif --B_band=2 --outfile=result.tif --calc="(A+B)/2" --calc="B*logical_and(A>100,A<150)"
π AUTHOR π
Chris Yesson <chris dot yesson at ioz dot ac dot uk>, Etienne Tourigny <etourigny dot dev at gmail dot com> β literal legends, we stan π«Άπ
π COPYRIGHT π
1998-2026
and that's the page, bestie π official GDAL GDAL_CALC(1) manual, dated Jan 08, 2026, source/version GDAL. go forth and calculate β you're gonna eat π
β¨
π¦ where this page comes from
- epel 9: gdal3.4 3.4.3-5.el9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms