Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
GDAL-RASTER-CALC(1)		      GDAL		     GDAL-RASTER-CALC(1)

NAME
     gdal-raster-calc - Perform pixel-wise calculations on a raster

     Added in version 3.11.

SYNOPSIS
	Usage: gdal raster calc [OPTIONS] <INPUTS> <OUTPUT>

	Perform raster algebra

	Positional arguments:
	  -i, --input <INPUTS>					   Input raster datasets [1.. values] [required]
	  -o, --output <OUTPUT> 				   Output raster dataset (created by algorithm) [required]

	Common Options:
	  -h, --help						   Display help message and exit
	  --json-usage						   Display usage as JSON document and exit
	  --config <KEY>=<VALUE>				   Configuration option [may be repeated]
	  --progress						   Display progress bar

	Options:
	  -f, --of, --format, --output-format <OUTPUT-FORMAT>	   Output format ("GDALG" allowed)
	  --co, --creation-option <KEY>=<VALUE> 		   Creation option [may be repeated]
	  --overwrite						   Whether overwriting existing output is allowed
	  --ot, --datatype, --output-data-type <OUTPUT-DATA-TYPE>  Output data type. OUTPUT-DATA-TYPE=Byte|Int8|UInt16|Int16|UInt32|Int32|UInt64|Int64|CInt16|CInt32|Float16|Float32|Float64|CFloat32|CFloat64
	  --no-check-srs					   Do not check consistency of input spatial reference systems
	  --no-check-extent					   Do not check consistency of input extents
	  --calc <CALC> 					   Expression(s) to evaluate [1.. values] [required]

DESCRIPTION
     gdal raster calc performs pixel-wise calculations on one or more input GDAL
     datasets.	Calculations can be performed eagerly, writing results to a con-
     ventional raster format, or lazily, written as a set of derived bands in  a
     VRT (Virtual Dataset).

     The  list of input GDAL datasets can be specified at the end of the command
     line or put in a text file (one input per line) for very  long  lists.   If
     more  than  one input dataset is used, it should be prefixed with a name by
     which it will be referenced in the calculation, e.g. A=my_data.tif.  (If  a
     single  dataset is used, it will be referred to with the variable X in for-
     mulas.)

     The inputs should have the same spatial reference system and  should  cover
     the same spatial extent but are not required to have the same spatial reso-
     lution. The spatial extent check can be disabled with --no-check-extent, in
     which  case the inputs must have the same dimensions. The spatial reference
     system check can be disabled with --no-check-srs.

     The following options are available:

     -f, --of, --format, --output-format <OUTPUT-FORMAT>
	    Which output raster format to use. Allowed values may  be  given  by
	    gdal --formats | grep raster | grep rw | sort

     --co <NAME>=<VALUE>
	    Many  formats have one or more optional creation options that can be
	    used to control particulars about the file	created.  For  instance,
	    the GeoTIFF driver supports creation options to control compression,
	    and whether the file should be tiled.

	    May be repeated.

	    The  creation options available vary by format driver, and some sim-
	    ple formats have no creation options at all. A list of options  sup-
	    ported  for  a  format can be listed with the --formats command line
	    option but the documentation for the format is the definitive source
	    of information on driver creation options.	See Raster drivers  for-
	    mat  specific documentation for legal creation options for each for-
	    mat.

     --overwrite
	    Allow program to overwrite existing target file or dataset.   Other-
	    wise,  by default, gdal errors out if the target file or dataset al-
	    ready exists.

     -i [<name>=]<input>
	    Select an input dataset to be processed.  If  more	than  one  input
	    dataset  is  provided,  each dataset must be prefixed with a name to
	    which it will will be referenced in --calc.

     --calc
	    An expression to be evaluated using the  muparser  math  parser  li-
	    brary.   The  expression may refer to individual bands of each input
	    (e.g., X[1] + 3) or it may be applied to all bands of an input (X  +
	    3).  If the expression contains a reference to all bands of multiple
	    inputs, those inputs must either have the same the number of  bands,
	    or a single band.

	    For  example,  if  inputs A and B each have three bands, and input C
	    has a single band, then the argument --calc "A + B + C"  is  equiva-
	    lent  to  --calc  "A[1]  +	B[1] + C[1]" --calc "A[2] + B[2] + C[2]"
	    --calc "A[3] + B[3] + C[3]".

	    Multiple calculations may be specified; output band(s) will be  pro-
	    duced for each expression in the order they are provided.

	    Input rasters will be converted to 64-bit floating point numbers be-
	    fore performing calculations.

     --no-check-extent
	    Do	not  verify that the input rasters have the same spatial extent.
	    The input rasters will instead be required to have the  same  dimen-
	    sions.  The  geotransform of the first input will be assigned to the
	    output.

     --no-check-srs
	    Do not check the spatial reference systems of the inputs for consis-
	    tency. All inputs will be assumed to have the spatial reference sys-
	    tem of the first input, and this spatial reference	system	will  be
	    used for the output.

GDALG OUTPUT (ON-THE-FLY / STREAMED DATASET)
     This program supports serializing the command line as a JSON file using the
     GDALG  output  format.   The  resulting file can then be opened as a raster
     dataset using the GDALG: GDAL Streamed  Algorithm	driver,  and  apply  the
     specified pipeline in a on-the-fly / streamed way.

EXAMPLES
   Example 1: Per-band sum of three files
	gdal raster calc -i "A=file1.tif" -i "B=file2.tif" -i "C=file3.tif" --calc "A+B+C" -o out.tif

   Example 2: Per-band maximum of three files
	gdal raster calc -i "A=file1.tif" -i "B=file2.tif" -i "C=file3.tif" --calc "max(A,B,C)" -o out.tif

   Example 3: Setting values of zero and below to NaN
	gdal raster calc -i "A=input.tif" -o result.tif --calc="A > 0 ? A : NaN"

AUTHOR
     Dan Baston <dbaston@gmail.com>

COPYRIGHT
     1998-2025

				  Oct 29, 2025		     GDAL-RASTER-CALC(1)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=gdal-raster-calc&sektion=1&manpath=FreeBSD+Ports+15.1.quarterly>

home | help