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 (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              New in version 3.3.
57
58
59              Ignores the input bands  NoDataValue.   By  default,  the  input
60              bands  NoDataValue are not participating in the calculation.  By
61              setting this setting - no special treatment will be performed on
62              the  input  NoDataValue.  and  they will be participating in the
63              calculation as any other value.  The output will not have a  set
64              NoDataValue, unless you explicitly specified a specific value by
65              setting --NoDataValue=<value>.
66
67       --type=<datatype>
68              Output datatype, must be one of [Int32, Int16, Float64,  UInt16,
69              Byte, UInt32, Float32].
70
71              NOTE:
72                 Despite  the datatype set using --type, when doing intermedi‐
73                 ate aritmethic operations using operands of  the  same  type,
74                 the  operation  result will honor the original datatype. This
75                 may lead into unexpected results in the final result.
76
77       --format=<gdal_format>
78              GDAL format for output file.
79
80       color-table=<filename>
81              Allows specifying a filename of a color table (or  a  ColorTable
82              object)  (with  Palette Index interpretation) to be used for the
83              output raster.  Supported formats: txt (i.e. like  gdaldem,  but
84              color  names  are  not  supported), qlr, qml (i.e. exported from
85              QGIS)
86
87       --extent=<option>
88              New in version 3.3.
89
90
91              this option determines how to handle rasters with different  ex‐
92              tents.   this  option is mutually exclusive with the projwin op‐
93              tion, which is used for providing a custom extent.  for all  the
94              options  below the pixel size (resolution) and SRS (Spatial Ref‐
95              erence System) of all the input rasters must be the  same.   ig‐
96              nore  (default)  -  only  the dimensions of the rasters are com‐
97              pared. if the dimensions do not agree the operation  will  fail.
98              fail  -  the  dimensions  and the extent (bounds) of the rasters
99              must agree, otherwise the operation will fail.  union - the  ex‐
100              tent  (bounds)  of the output will be the minimal rectangle that
101              contains all the input extents.  intersect - the extent (bounds)
102              of the output will be the maximal rectangle that is contained in
103              all the input extents.
104
105       --projwin <ulx> <uly> <lrx> <lry>
106              New in version 3.3.
107
108
109              this option provides a custom extent for the output, it is mutu‐
110              ally exclusive with the extent option.
111
112       --projectionCheck
113              New in version 3.3.
114
115
116              By  default,  no projection checking will be performed.  By set‐
117              ting this option, if the projection is  not  the  same  for  all
118              bands then the operation will fail.
119
120       --creation-option=<option>
121              Passes  a creation option to the output format driver.  Multiple
122              options may be listed. See format specific documentation for le‐
123              gal creation options for each format.
124
125       --co=<option>
126              The same as creation-option.
127
128       --allBands=[a-z, A-Z]
129              Process  all bands of given raster (a-z, A-Z). Requires a single
130              calc for all bands.
131
132       --overwrite
133              Overwrite output file if it already exists. Overwriting must  be
134              understood  here  as  deleting  and  recreating  the  file  from
135              scratch. Note that if this option is not specified and the  out‐
136              put file already exists, it will be updated in place.
137
138       --debug
139              Print debugging information.
140
141       --quiet
142              Suppress progress messages.
143

PYTHON OPTIONS

145       New in version 3.3.
146
147
148       The following options are available by using function the python inter‐
149       face of gdal_calc.  They are not available using the command prompt.
150
151       user_namespace
152              A dictionary of custom functions or other names to be  available
153              for use in the Calc expression.
154
155       return_ds
156              If  enabled, the output dataset would be returned from the func‐
157              tion and not closed.
158
159       color_table
160              Allows specifying a ColorTable object (with Palette Index inter‐
161              pretation) to be used for the output raster.
162

EXAMPLE

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

AUTHOR

219       Chris  Yesson <chris dot yesson at ioz dot ac dot uk>, Etienne Tourigny
220       <etourigny dot dev at gmail dot com>
221
223       1998-2022
224
225
226
227
228                                 May 04, 2022                     GDAL_CALC(1)
Impressum