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 listed
27              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, or several values (separated by space)
34              can  be provided (GDAL >= 3.3).  Since GDAL 3.5, wildcard excep‐
35              tions (using ?, *) are supported for all shells/platforms.   The
36              effect  will  be to create a 3-dim numpy array.  In such a case,
37              the calculation formula must use this input as a 3-dim array and
38              must return a 2D array (see examples below).  In case the calcu‐
39              lation does not return a 2D array an error would be generated.
40
41       --A_band=<n>
42              Number of raster band for file A (default 1).
43
44       --outfile=<filename>
45              Output file to generate or fill.
46
47       --NoDataValue=<value>
48              Output NoDataValue (default datatype specific value).  To  indi‐
49              cate  not  setting a NoDataValue use --NoDataValue=none (GDAL >=
50              3.3)
51
52              NOTE:
53                 Using the  Python  API:  None  value  will  indicate  default
54                 datatype specific value.  'none' value will indicate not set‐
55                 ting a NoDataValue.
56
57       --hideNoData
58              New in version 3.3.
59
60
61              Ignores the input bands  NoDataValue.   By  default,  the  input
62              bands  NoDataValue are not participating in the calculation.  By
63              setting this setting - no special treatment will be performed on
64              the  input  NoDataValue.  and  they will be participating in the
65              calculation as any other value.  The output will not have a  set
66              NoDataValue, unless you explicitly specified a specific value by
67              setting --NoDataValue=<value>.
68
69       --type=<datatype>
70              Output datatype, must be one  of  [Byte,  Int8,  UInt16,  Int16,
71              UInt32,  Int32, UInt64, Int64, Float64, Float32, CInt16, CInt32,
72              CFloat64, CFloat32].
73
74              NOTE:
75                 Despite the datatype set using --type, when doing  intermedi‐
76                 ate  aritmethic  operations  using operands of the same type,
77                 the operation result will honor the original  datatype.  This
78                 may lead into unexpected results in the final result.
79
80              NOTE:
81                 UInt64,  Int64,  CInt16, CInt32, CFloat32, CFloat64 have been
82                 added in GDAL 3.5.3 Int8 has been added in GDAL 3.7
83
84       --format=<gdal_format>
85              GDAL format for output file.
86
87       --color-table=<filename>
88              Allows specifying a filename of a color table (or  a  ColorTable
89              object)  (with  Palette Index interpretation) to be used for the
90              output raster.  Supported formats: txt (i.e. like  gdaldem,  but
91              color  names  are  not  supported), qlr, qml (i.e. exported from
92              QGIS)
93
94       --extent=<option>
95              New in version 3.3.
96
97
98              This option determines how to handle rasters with different  ex‐
99              tents.   This  option is mutually exclusive with the projwin op‐
100              tion, which is used for providing a custom extent.
101
102              For all the options below the pixel size  (resolution)  and  SRS
103              (Spatial  Reference System) of all the input rasters must be the
104              same.
105
106              ignore (default) - only the dimensions of the rasters  are  com‐
107              pared. if the dimensions do not agree the operation will fail.
108
109              fail  -  the  dimensions  and the extent (bounds) of the rasters
110              must agree, otherwise the operation will fail.
111
112              union - the extent (bounds) of the output will  be  the  minimal
113              rectangle that contains all the input extents.
114
115              intersect  - the extent (bounds) of the output will be the maxi‐
116              mal rectangle that is contained in all the input extents.
117
118       --projwin <ulx> <uly> <lrx> <lry>
119              New in version 3.3.
120
121
122              This option provides a custom extent for the output, it is mutu‐
123              ally exclusive with the extent option.
124
125       --projectionCheck
126              New in version 3.3.
127
128
129              By  default,  no projection checking will be performed.  By set‐
130              ting this option, if the projection is  not  the  same  for  all
131              bands then the operation will fail.
132
133       --creation-option=<option>
134              Passes  a creation option to the output format driver.  Multiple
135              options may be listed. See format specific documentation for le‐
136              gal creation options for each format.
137
138       --co=<option>
139              The same as creation-option.
140
141       --allBands=[a-z, A-Z]
142              Process  all bands of given raster (a-z, A-Z). Requires a single
143              calc for all bands.
144
145       --overwrite
146              Overwrite output file if it already exists. Overwriting must  be
147              understood  here  as  deleting  and  recreating  the  file  from
148              scratch. Note that if this option is not specified and the  out‐
149              put file already exists, it will be updated in place.
150
151       --debug
152              Print debugging information.
153
154       --quiet
155              Suppress progress messages.
156

PYTHON OPTIONS

158       New in version 3.3.
159
160
161       The following options are available by using function the python inter‐
162       face of gdal_calc.  They are not available using the command prompt.
163
164       user_namespace
165              A dictionary of custom functions or other names to be  available
166              for use in the Calc expression.
167
168       return_ds
169              If  enabled, the output dataset would be returned from the func‐
170              tion and not closed.
171
172       color_table
173              Allows specifying a ColorTable object (with Palette Index inter‐
174              pretation) to be used for the output raster.
175

EXAMPLE

177       Add two files together:
178
179          gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"
180
181       Average of two layers:
182
183          gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="(A+B)/2"
184
185       NOTE:
186          In  the  previous  example, beware that if A and B inputs are of the
187          same datatype, for example integers, you may need to force the  con‐
188          version of one of the operands before the division operation.
189
190              gdal_calc.py -A input.tif -B input2.tif --outfile=result.tif --calc="(A.astype(numpy.float64) + B) / 2"
191
192       Add three files together (two options with the same result):
193
194          gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="A+B+C"
195
196       New in version 3.3.
197
198
199          gdal_calc.py -A input1.tif -A input2.tif -A input3.tif --outfile=result.tif --calc="numpy.sum(A,axis=0)".
200
201       Average of three layers (two options with the same result):
202
203          gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="(A+B+C)/3"
204
205       New in version 3.3.
206
207
208          gdal_calc.py -A input1.tif input2.tif input3.tif --outfile=result.tif --calc="numpy.average(a,axis=0)".
209
210       Maximum of three layers  (two options with the same result):
211
212          gdal_calc.py -A input1.tif -B input2.tif -C input3.tif --outfile=result.tif --calc="numpy.max((A,B,C),axis=0)"
213
214       New in version 3.3.
215
216
217          gdal_calc.py -A input1.tif input2.tif input3.tif --outfile=result.tif --calc="numpy.max(A,axis=0)"
218
219       Set values of zero and below to null:
220
221          gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
222
223       Using logical operator to keep a range of values from input:
224
225          gdal_calc.py -A input.tif --outfile=result.tif --calc="A*logical_and(A>100,A<150)"
226
227       Work with multiple bands:
228
229          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)"
230

AUTHOR

232       Chris  Yesson <chris dot yesson at ioz dot ac dot uk>, Etienne Tourigny
233       <etourigny dot dev at gmail dot com>
234
236       1998-2023
237
238
239
240
241                                 Oct 30, 2023                     GDAL_CALC(1)
Impressum