Scroll to navigation



gdal_calc - Command line raster calculator with numpy syntax.

SYNOPSIS --calc=expression --outfile=out_filename [-A filename]
             [--A_band=n] [-B...-Z filename] [other_options]


Command line raster calculator with numpy syntax. Use any basic arithmetic supported by numpy arrays such as +, -, *, and \ along with logical operators such as >. Note that all files must have the same dimensions, but no projection checking is performed.

Show this help message and exit

The same as --help.

Calculation in gdalnumeric syntax using +, -, /, *, or any numpy array functions (i.e. log10()).

-A <filename>
Input gdal raster file, you can use any letter (A-Z).

Number of raster band for file A (default 1).

Output file to generate or fill.

Output nodata value (default datatype specific value).

Output datatype, must be one of [Int32, Int16, Float64, UInt16, Byte, UInt32, Float32].

GDAL format for output file.

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.

The same as creation-option.

Process all bands of given raster (A-Z).

Overwrite output file if it already exists.

Print debugging information.

Suppress progress messages.


Add two files together: -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"

Average of two layers: -A input.tif -B input2.tif --outfile=result.tif --calc="(A+B)/2"

Set values of zero and below to null: -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0


Chris Yesson <chris dot yesson at ioz dot ac dot uk>, Etienne Tourigny <etourigny dot dev at gmail dot com>


September 1, 2020