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 (unless extent option is used), but  no  projection  checking  is
18       performed (unless projectionCheck option is used).
19
20       --help Show this help message and exit
21
22       -h     The same as --help.
23
24       --calc=expression
25              Calculation in numpy syntax using +, -, /, *, or any numpy array
26              functions (i.e. log10()`).  Multiple  ``--calc  options  can  be
27              listed to produce a multiband file (GDAL >= 3.2).
28
29       -A <filename>
30              Input  gdal  raster  file,  you  can  use any letter (a-z, A-Z).
31              (lower case supported since GDAL 3.3)
32
33              A letter may be repeated (GDAL >= 3.3). The effect  will  be  to
34              create  a  3-dim  numpy  array.  In such a case, the calculation
35              formula must use this input as a 3-dim array and must  return  a
36              2D array (see examples below).  In case the calculation does not
37              return a 2D array an error would be generated.
38
39       --A_band=<n>
40              Number of raster band for file A (default 1).
41
42       --outfile=<filename>
43              Output file to generate or fill.
44
45       --NoDataValue=<value>
46              Output NoDataValue (default datatype specific value).  To  indi‐
47              cate  not  setting a NoDataValue use --NoDataValue=none (GDAL >=
48              3.3)
49
50              NOTE:
51                 Using the  Python  API:  None  value  will  indicate  default
52                 datatype specific value.  'none' value will indicate not set‐
53                 ting a NoDataValue.
54
55       --hideNoData
56              ..versionadded:: 3.3
57
58              Ignores the input bands  NoDataValue.   By  default,  the  input
59              bands  NoDataValue are not participating in the calculation.  By
60              setting this setting - no special treatment will be performed on
61              the  input  NoDataValue.  and  they will be participating in the
62              calculation as any other value.  The output will not have a  set
63              NoDataValue, unless you explicitly specified a specific value by
64              setting --NoDataValue=<value>.
65
66       --type=<datatype>
67              Output datatype, must be one of [Int32, Int16, Float64,  UInt16,
68              Byte, UInt32, Float32].
69
70              NOTE:
71                 Despite  the datatype set using --type, when doing intermedi‐
72                 ate aritmethic operations using operands of  the  same  type,
73                 the  operation  result will honor the original datatype. This
74                 may lead into unexpected results in the final result.
75
76       --format=<gdal_format>
77              GDAL format for output file.
78
79       color-table=<filename>
80              Allows specifying a filename of a color table (or  a  ColorTable
81              object)  (with  Palette Index interpretation) to be used for the
82              output raster.  Supported formats: txt (i.e. like  gdaldem,  but
83              color  names  are  not  supported), qlr, qml (i.e. exported from
84              QGIS)
85
86       --extent=<option>
87              ..versionadded:: 3.3
88
89              this option determines how to handle rasters with different  ex‐
90              tents.   this  option is mutually exclusive with the projwin op‐
91              tion, which is used for providing a custom extent.  for all  the
92              options  below the pixel size (resolution) and SRS (Spatial Ref‐
93              erence System) of all the input rasters must be the  same.   ig‐
94              nore  (default)  -  only  the dimensions of the rasters are com‐
95              pared. if the dimensions do not agree the operation  will  fail.
96              fail  -  the  dimensions  and the extent (bounds) of the rasters
97              must agree, otherwise the operation will fail.  union - the  ex‐
98              tent  (bounds)  of the output will be the minimal rectangle that
99              contains all the input extents.  intersect - the extent (bounds)
100              of the output will be the maximal rectangle that is contained in
101              all the input extents.
102
103       --projwin <ulx> <uly> <lrx> <lry>
104              ..versionadded:: 3.3
105
106              this option provides a custom extent for the output, it is mutu‐
107              ally exclusive with the extent option.
108
109       --projectionCheck
110              ..versionadded:: 3.3
111
112              By  default,  no projection checking will be performed.  By set‐
113              ting this option, if the projection is  not  the  same  for  all
114              bands then the operation will fail.
115
116       --creation-option=<option>
117              Passes  a creation option to the output format driver.  Multiple
118              options may be listed. See format specific documentation for le‐
119              gal creation options for each format.
120
121       --co=<option>
122              The same as creation-option.
123
124       --allBands=[a-z, A-Z]
125              Process  all bands of given raster (a-z, A-Z). Requires a single
126              calc for all bands.
127
128       --overwrite
129              Overwrite output file if it already exists.
130
131       --debug
132              Print debugging information.
133
134       --quiet
135              Suppress progress messages.
136

PYTHON OPTIONS

138       ..versionadded:: 3.3
139
140       The following options are available by using function the python inter‐
141       face of gdal_calc.  They are not available using the command prompt.
142
143       user_namespace
144              A  dictionary of custom functions or other names to be available
145              for use in the Calc expression.
146
147       return_ds
148              If enabled, the output dataset would be returned from the  func‐
149              tion and not closed.
150
151       color_table
152              Allows specifying a ColorTable object (with Palette Index inter‐
153              pretation) to be used for the output raster.
154

EXAMPLE

156       Add two files together:
157
158          gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"
159
160       Average of two layers:
161
162          gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="(A+B)/2"
163
164       NOTE:
165          In the previous example, beware that if A and B inputs  are  of  the
166          same  datatype, for example integers, you may need to force the con‐
167          version of one of the operands before the division operation.
168
169              gdal_calc.py -A input.tif -B input2.tif --outfile=result.tif --calc="(A.astype(numpy.float64) + B) / 2"
170
171       Add three files together (two options with the same result):
172
173          gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="A+B+C"
174
175       ..versionadded:: 3.3
176
177          gdal_calc.py -A input1.tif -A input2.tif -A input3.tif --outfile=result.tif --calc="numpy.sum(A,axis=0)".
178
179       Average of three layers (two options with the same result):
180
181          gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="(A+B+C)/3"
182
183       ..versionadded:: 3.3
184
185          gdal_calc.py -A input1.tif -A input2.tif -A input3.tif --outfile=result.tif --calc="numpy.average(a,axis=0)".
186
187       Maximum of three layers  (two options with the same result):
188
189          gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="numpy.max((A,B,C),axis=0)"
190
191       ..versionadded:: 3.3
192
193          gdal_calc.py -A input1.tif -A input2.tif -A input3.tif --outfile=result.tif --calc="numpy.max(A,axis=0)"
194
195       Set values of zero and below to null:
196
197          gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
198
199       Using logical operator to keep a range of values from input:
200
201          gdal_calc.py -A input.tif --outfile=result.tif --calc="A*logical_and(A>100,A<150)"
202
203       Work with multiple bands:
204
205          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)"
206

AUTHOR

208       Chris Yesson <chris dot yesson at ioz dot ac dot uk>, Etienne  Tourigny
209       <etourigny dot dev at gmail dot com>
210
212       1998-2021
213
214
215
216
217                                 Sep 07, 2021                     GDAL_CALC(1)
Impressum