[GIS] Translating .bil files in batch mode with QGIS

convertqgisraster

I have some .bil files that I would like to convert into ASCII Gridded XYZ format files.

It seems to work well with the Raster>Translate tool of QGIS when I process one file at a time. But I would like to do it by batch. So I checked the batch box but got this error message:

Processing of the following files ended with error:

C:/Users/Fall Line Tower/Desktop/Bil To Be Processed/Only Bill/PRISM_tmax_stable_4kmD1_19810101_bil.bil
ERROR 4: `C:/Users/Fall Line Tower/Desktop/Bil To Be Processed/Onli Bill/PRISM_tmax_stable_4kmD1_19810101_bil.bil' not recognised as a supported file format.
GDALOpen failed – 4

I have the same error message for each .bil file within my source directory.

Any idea where the problem comes from?

Does the batch mode take only one type of format?

Not the .bil?

I am using QGIS 2.2 on Windows 7.

Best Answer

  1. locate gdal_translate.exe on your disk (e.g. C:\programs\qgis\bin\ )
  2. write this Python code and launch it:

    import glob, subprocess
    
    pathbin = your_path_to_gdal
    pathfiles = your_path_to_files
    myfiles = glob.glob(pathfiles + "*.bil") #list of all bil files 
    for file in myfiles:
        subprocess.call([pathbin + "gdal_translate.exe", "-of", "XYZ", file, file[:-4] + ".csv"])
    

or you can also launch it from the dos command prompt

for /f %a IN ('dir /b /s "Disk:\Your\Directory\Name\*.bil"') do call "Disk:\Your\path\to_gdalbin\gdal_translate.exe" -of XYZ "%a" "%~dpna.csv"
Related Question