1

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.

Vince
  • 20,017
  • 15
  • 45
  • 64

1 Answers1

1

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!"

)

sn1ks
  • 2,982
  • 12
  • 28
  • Hello, I have tried your script however, although it is reading the asc it is unable to convert them. I get the error "filename, directory name or volume label syntax is incorrect. I have made sure that all the paths are correct and the crs too. – Amrie Singh Oct 19 '21 at 12:56
  • Fixed it thank you so much for this. – Amrie Singh Oct 19 '21 at 13:42
  • Is there a way to amend this to use grass r.stats on all those files too to get the statistics for each category? I need them to be saved to a csv which I will use to analyse further. – Amrie Singh Oct 19 '21 at 20:53
  • i m not familiar with r.stats - maybe you ask a new question for that? – sn1ks Oct 20 '21 at 08:49