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

PYTHON OPTIONS

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

EXAMPLE

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

AUTHOR

227       Chris  Yesson <chris dot yesson at ioz dot ac dot uk>, Etienne Tourigny
228       <etourigny dot dev at gmail dot com>
229
231       1998-2022
232
233
234
235
236                                 Sep 02, 2022                     GDAL_CALC(1)
Impressum