GDAL Translate – Batch Convert asc to TIFF Using QGIS and Python

gdal-translatepythonqgis

I have 118 asc grid files, I need to convert them to TIFF. I've tried gdal translate but unfortunately GIS keeps crashing.
I was hoping I could use python to loop through all of them and save them.

Best Answer

As suggested, creating a windows batch file should be your best solution. You can try this script, just make sure the paths and your source crs are correct.

@ECHO ON
SETLOCAL EnableDelayedExpansion

 SET mypath_in=G:\Input\Folder\
 SET mypath_out=G:\Output\Folder\

 FOR /F %%i IN ('DIR /B %mypath_in%*.asc') DO (

    SET infile=%%i
    SET outfile=!infile:.asc=.tif!
    

    "C:\Program Files\QGIS 3.20"\bin\gdal_translate.exe -co WORLDFILE=YES -a_srs EPSG:3044 -of GTIF "%mypath_in%!infile!" "%mypath_out%!outfile!"
    
    )