Can anybody help me to solve a problem with running gdal_calc for many rasters?
I have several multispectral images and I need a batch to perform NDVI calculation.
I started with gdal code for one raster and it works good:
> C:\Python27\python.exe "C:\Program Files\QGIS Wien\bin\gdal_calc.py" -A D:\my_dir\ras0_2.TIF --A_band=3 -B D:\my_dir\ras0_2.TIF --B_band=4 --outfile=D:\my_dir\ndvi.tif --calc=((B-A)/(B+A))
But when I tried to run code for all TiFFs in a folder the program gave an error
"nonetype object has no attribute GetRasterBand"
for %i in (*.tif) do C:\Python27\python.exe "C:\Program Files\QGIS Wien\bin\gdal_calc.py" -A $i --A_band=3 -B $i --B_band=4 --calc="((B-A)/(B+A))" %i ndvi/ndvi_%i
Best Answer
Nearly there. Couple of small problems:
$
instead of%
.--outfile
parameter isn't specified explicitly, and looks a bit jumbled.Try:
If you have osgeo4w installed you can go open the osgeo4w shell, cd to the directory and run:
If you want a batch file to do this you'll need to use two percent signs before your variables - i.e.
%%i