Monday, 3 October 2016

gdal - Convert batch file using GDAL_Translate.



how to convert batch file from .tif to .bil format using gdal_translate in windows CMD command line, file in the directory.


Directory path : D:\GDAL-TEST
001_mean.tif
002_mean.tif
003_mean.tif

004_mean.tif
So on....

I have one code but by this code we can convert single file at a time but i want to loop through all raster which have .tif extension in the directory and convert it to .bil format. Please want a solution


My code. I a running this code on GDAL Command window on windows 7 platform.


gdal_translate -of "ENVI" D:\GDAL-TEST\001_mean.tif D:\GDAL-TEST\001_mean.bil

Answer



From the command line you can write


for %i in (*.tif) do gdal_translate -of "ENVI" %i %i.bil


The command above will convert all tif to bil in the actual directory. The output name will be some_name.tif.bil. From a batch (.bat) file you must use double percent sign for variables.


for %%i in (*.tif) do gdal_translate -of "ENVI" %%i %%i.bil

If you would like to remove .tif from the output file name you see the following https://stackoverflow.com/questions/3215501/batch-remove-file-extension


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...