5

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
  • 1
    Please edit your Question to include what you input and the actual error messages you received
    – Midavalo
    Jul 24, 2016 at 9:50
  • It's a valid question, check link. Only tiffs with 1 band are supported.
    – Gert
    Nov 24, 2016 at 15:56

2 Answers 2

9

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

0

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
1
  • 3
    This doesn't address the question of using gdal_calc.py with multiple bands, though.
    – Benjamin
    Aug 8, 2016 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.