Esri ASCII GRID can be converted to esri .bil format by following way in a desktop From QGIS desktop menu-->Raster-->conversion-->Translate(convert format) How can I write a python code because I have 864 esri ascii grid data?
Sorry, you asked for PyQGIS but this is just standard Python.
Here's a script I put together:
import os, sys, subprocess # in folder and out folder arguments, if you want you can hard code # these paths instead of using arguments. InFolder = sys.argv OutFolder = sys.argv # GDAL_Translate = "C:\\YOUR\PATH\TO\GDAL_Translate.exe" # this is my path for an example GDAL_Translate = r"C:\Program Files\QGIS Dufour\bin\gdal_translate.exe" GDAL_Options = "EHDR" # output format EHDR = .bil, HFA = .img, GTIFF = GeoTiff for (pPath, pFolder, pFiles) in os.walk(InFolder): for pThisFile in pFiles: if pThisFile.lower() == "hdr.adf": GridName = os.path.basename(pPath) # set the paths for in and out files ConvertFromFile = pPath + "\\" + pThisFile ConvertToFile = OutFolder + "\\" + GridName + ".bil" # don't forget to change if you change the output format # create a blank list and then put all the words in it # in order to feed to the subprocess.call Command = list() Command.append(GDAL_Translate) Command.append("-of") Command.append(GDAL_Options) Command.append(ConvertFromFile) Command.append(ConvertToFile) # run the command to do it and wait until it finishes subprocess.call(Command)
os.walk() to go down the folder tree looking for all the files matching "hdr.adf" and executes
GDAL_Translate for each one. Note that no checking for if the file is going to be overwritten, depending on your circumstances you might want to address that.
To keep things simple I've not included any error checking so it's just the functional minimum. I tested this script on a folder with subfolders full of Esri GRIDs (3365 GRIDs) and it worked just fine converting to 3365 Esri BIL files.