1GDAL_CALC(1)                         GDAL                         GDAL_CALC(1)
2
3
4

NAME

6       gdal_calc - Command line raster calculator with numpy syntax.
7

SYNOPSIS

9          gdal_calc.py --calc=expression --outfile=out_filename [-A filename]
10                       [--A_band=n] [-B...-Z filename] [other_options]
11
12       DESCRIPTION
13
14       Command  line raster calculator with numpy syntax. Use any basic arith‐
15       metic supported by numpy arrays such as +, -, *, and \ along with logi‐
16       cal  operators such as >. Note that all files must have the same dimen‐
17       sions, but no projection checking is performed.
18
19       --help Show this help message and exit
20
21       -h     The same as --help.
22
23       --calc=expression
24              Calculation in gdalnumeric syntax using +, -, /, *, or any numpy
25              array  functions (i.e. log10()).  Multiple --calc options can be
26              listed to produce a multiband file (GDAL >= 3.2).
27
28       -A <filename>
29              Input gdal raster file, you can use any letter (A-Z).
30
31       --A_band=<n>
32              Number of raster band for file A (default 1).
33
34       --outfile=<filename>
35              Output file to generate or fill.
36
37       --NoDataValue=<value>
38              Output nodata value (default datatype specific value).
39
40       --type=<datatype>
41              Output datatype, must be one of [Int32, Int16, Float64,  UInt16,
42              Byte, UInt32, Float32].
43
44              NOTE:
45                 Despite  the datatype set using --type, when doing intermedi‐
46                 ate aritmethic operations using operands of  the  same  type,
47                 the  operation  result will honor the original datatype. This
48                 may lead into unexpected results in the final result.
49
50       --format=<gdal_format>
51              GDAL format for output file.
52
53       --creation-option=<option>
54              Passes a creation option to the output format driver.   Multiple
55              options may be listed. See format specific documentation for le‐
56              gal creation options for each format.
57
58       --co=<option>
59              The same as creation-option.
60
61       --allBands=[A-Z]
62              Process all bands of given raster (A-Z). Requires a single  calc
63              for all bands.
64
65       --overwrite
66              Overwrite output file if it already exists.
67
68       --debug
69              Print debugging information.
70
71       --quiet
72              Suppress progress messages.
73

EXAMPLE

75       Add two files together:
76
77          gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"
78
79       Average of two layers:
80
81          gdal_calc.py -A input.tif -B input2.tif --outfile=result.tif --calc="(A+B)/2"
82
83       NOTE:
84          In  the  previous  example, beware that if A and B inputs are of the
85          same datatype, for example integers, you may need to force the  con‐
86          version of one of the operands before the division operation.
87
88              gdal_calc.py -A input.tif -B input2.tif --outfile=result.tif --calc="(A.astype(numpy.float64) + B) / 2"
89
90       Set values of zero and below to null:
91
92          gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
93
94       Using logical operator to keep a range of values from input:
95
96          gdal_calc.py -A input.tif --outfile=result.tif --calc="A*logical_and(A>100,A<150)"
97
98       Work with multiple bands:
99
100          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)"
101

AUTHOR

103       Chris  Yesson <chris dot yesson at ioz dot ac dot uk>, Etienne Tourigny
104       <etourigny dot dev at gmail dot com>
105
107       1998-2021
108
109
110
111
112                                 Mar 24, 2021                     GDAL_CALC(1)
Impressum