gdal_calc(1)

gdal_calc1

Command line raster calculator with numpy syntax.

Usage

DESCRIPTION

NOTE:

TIP:

Return status code

The program returns status code 0 in case of success, and non-zero in case of error (non-blocking errors emitted as warnings are considered as a successful execution).

Options

Added in version 3.3.

The following options are available by using the Python interface of gdal_calc. They are not available using the command prompt.

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 will be returned from the function and not closed.

color_table

Allows specifying a ColorTable object (with Palette Index interpretation) to be used for the output raster.

Examples

Example 1: Average of two files

gdal_calc -A input1.tif -B input2.tif --outfile=result.tif --calc="(A+B)/2"

CAUTION:

If A and B inputs both have integer data types, integer division will be performed. To avoid this, you can convert one of the operands to a floating point type before the division operation.

gdal_calc -A input.tif -B input2.tif --outfile=result.tif --calc="(A.astype(numpy.float64) + B) / 2"

Example 2: Summing three files

gdal_calc -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="A+B+C"

Example 3: Combining three files into a 3D array and summing

gdal_calc -A input1.tif -A input2.tif -A input3.tif --outfile=result.tif --calc="numpy.sum(A,axis=0)".

Example 4: Average of three files

gdal_calc -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="(A+B+C)/3"

Example 5: Average of three files, using 3D array

gdal_calc -A input1.tif input2.tif input3.tif --outfile=result.tif --calc="numpy.average(a,axis=0)".

Example 6: Maximum of three files

gdal_calc -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="numpy.max((A,B,C),axis=0)"

Example 7: Maximum of three files, using a 3D array

gdal_calc -A input1.tif input2.tif input3.tif --outfile=result.tif --calc="numpy.max(A,axis=0)"

Example 8: Setting values of zero and below to NODATA

gdal_calc -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0

Example 9: Using logical operator to keep a range of values from input

gdal_calc -A input.tif --outfile=result.tif --calc="A*logical_and(A>100,A<150)"

Example 10: Performing two calculations and storing results in separate bands

gdal_calc -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)"

Example 11: Add a raster to each band in a 3-band raster

gdal_calc -A 3band.tif -B 1band.tif --outfile result.tif --calc "A+B" --allBands A

The result will have three bands, where each band contains the values of 1band.tif added to the corresponding band in 3band.tif.

Example 12: Add two three-band rasters

gdal_calc -A 3band_a.tif -B 3band_b.tif --outfile result.tif --calc "A+B" --allBands A --allBands B

The result will have three bands, where each band contains the values of the corresponding band of 3band_a.tif added to the corresponding band of 3band_b.tif.

Releases

6 releases since Debian 9 (Stretch); the text changed 5 times.

  1. 9
  2. 10
  3. 11
  4. 12
  5. 13
  6. Arch

Author

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

From gdal 3.13.3-6 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.