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.

  • Last time I used bil files in GDAL it was the .hdr that was considered the image and not the bil. Perhaps this is the case. Commented Apr 15, 2014 at 2:02
  • Have you created .hdr files? If so, you can point the command to the .hdr files and not .bil files. Commented Apr 18, 2014 at 7:08
  • Thank you. It seems like the data are stored in the .bil not the .hdr according to the size of the files and this description provided with the dataset: "This format contains raster data with floating-point numbers. It is the native output format of the PRISM Climate Model. Each BIL zipfile includes multiple components, with different file extensions: .xml (metadata for this dataset); .bil (dataset), .hdr (header info required for most BIL uses); .prj, .aux.xml (grid statistics), and .stx (required by some software)."
    – Bap
    Commented Apr 18, 2014 at 23:22
  • 1
    Don't be afraid of the command line, it's very useful. The tool documents online give examples of how they're used. BIL (Band Interleaved by Line) are just raw data - a very old format which supports only RLE compression but I've never seen it applied. If you know the data type, cell size and origin you can read it as straight binary... done that before! You would need some python/c/VB skill though. Commented Apr 22, 2014 at 2:01
  • 1
    When you use the translate tool from QGIS the command line is shown in the bottom window. I was unable to get it to create gridded XYZ though without editing the command line. The batch translate fails because of the two-part file structure of the bil with header and data having the same base name. This is a problem in QGIS, not in GDAL_Translate which it calls: calling translate once for each part. The only way to do it in QGIS is to write your own add-in. If you want to know how to do it in command I'm happy to offer assistance. Commented Apr 22, 2014 at 2:19

2 Answers 2

  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"

To supplement this thread, apart from using the Command Line to specify the advanced parameter setting in Translate (Convert Format), one other option is the QGIS Processing Modeler. Simply customize the Translate (Convert Format) tool with the data type conversion (e.g. float to uint16), save the model, and run it as a batch process (by right-clicking it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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