My problem is that I have multi-band images (8 bands) in GEOTIFF format and I tried to use gdal_calc.py to calculate a conditional expression between those bands. However, I could not make it because of wrong syntax. The source page does not give any example about this problem.
2 Answers
To calculate a grey-scale from the same input file using different bands u can open the file multiple times and define the band which you want to use with --A_band=n
.
See my example for calculating the NDVI from a satellite image with red at band 1 and near-infrared at band 4.
gdal_calc.py -A input.tif --A_band=1 -B input.tif --B_band=4 --outfile=ndvi.tif --calc="((B-A)/(B+A))"
You can see that I used input.tif
for A
and B
. See documentation of gdal_calc.py: http://www.gdal.org/gdal_calc.html
gdal_translate
has a specific -b
switch, that allows the selection of input bands.
-b band:
Select an input band band for output. Bands are numbered from 1. Multiple -b switches may be used to select a set of input bands to write to the output file, or to reorder bands. Starting with GDAL 1.8.0, band can also be set to "mask,1" (or just "mask") to mean the mask band of the first band of the input dataset.
Contrary to your question they do actually provide an example of just that:
gdal_translate rgba.tif withmask.tif -b 1 -b 2 -b 3 -mask 4 -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR --config GDAL_TIFF_INTERNAL_MASK YES
-
4This doesn't address the question of using gdal_calc.py with multiple bands, though.– BenjaminCommented Aug 8, 2016 at 16:43