- bullseye 3.2.2+dfsg-2+deb11u2
- testing 3.6.2+dfsg-1+b2
- unstable 3.6.2+dfsg-1+b2
- experimental 3.7.0+dfsg-1~exp1
GDAL_CALC(1) | GDAL | GDAL_CALC(1) |
NAME¶
gdal_calc - Command line raster calculator with numpy syntax.
SYNOPSIS¶
gdal_calc.py --calc=expression --outfile=out_filename [-A filename]
[--A_band=n] [-B...-Z filename] [other_options]
DESCRIPTION
Command line raster calculator with numpy syntax. Use any basic arithmetic supported by numpy arrays such as +, -, *, and \ along with logical operators such as >. Note that all files must have the same dimensions, but no projection checking is performed.
- --help
- Show this help message and exit
- -h
- The same as --help.
- --calc=expression
- Calculation in gdalnumeric syntax using +, -, /, *, or any numpy array functions (i.e. log10()). Multiple --calc options can be listed to produce a multiband file (GDAL >= 3.2).
- -A <filename>
- Input gdal raster file, you can use any letter (A-Z).
- --A_band=<n>
- Number of raster band for file A (default 1).
- --outfile=<filename>
- Output file to generate or fill.
- --NoDataValue=<value>
- Output nodata value (default datatype specific value).
- --type=<datatype>
- Output datatype, must be one of [Int32, Int16,
Float64, UInt16, Byte, UInt32,
Float32].
NOTE:
- --format=<gdal_format>
- GDAL format for output file.
- --creation-option=<option>
- Passes a creation option to the output format driver. Multiple options may be listed. See format specific documentation for legal creation options for each format.
- --co=<option>
- The same as creation-option.
- --allBands=[A-Z]
- Process all bands of given raster (A-Z). Requires a single calc for all bands.
- --overwrite
- Overwrite output file if it already exists.
- --debug
- Print debugging information.
- --quiet
- Suppress progress messages.
EXAMPLE¶
Add two files together:
gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"
Average of two layers:
gdal_calc.py -A input.tif -B input2.tif --outfile=result.tif --calc="(A+B)/2"
NOTE:
gdal_calc.py -A input.tif -B input2.tif --outfile=result.tif --calc="(A.astype(numpy.float64) + B) / 2"
Set values of zero and below to null:
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
Using logical operator to keep a range of values from input:
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*logical_and(A>100,A<150)"
Work with multiple bands:
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)"
AUTHOR¶
Chris Yesson <chris dot yesson at ioz dot ac dot uk>, Etienne Tourigny <etourigny dot dev at gmail dot com>
COPYRIGHT¶
1998-2021
March 5, 2021 |