3

For example i have a dataset of images in *.cub format like

$path: /work/120614/mg_1164/
f01.img.cub_E.cub
f02.img.cub_E.cub
'
'
f0n.img.cub_E.cub

for converting a single image I use gdal_translate f01.img.cub_E.cub fo1.tif for whole the datasets.HOW? batch file?

6

I suggest a batch file using OSGEO4W shell or the latest GDAL binaries from gisinternals.

Using Windows:

for %%N in (/work/120614/mg_1164/*.cub) DO gdal_translate %%N /work/temp/%%~nN.tif

Note: Use %%N in a batch file and %N when typing manually on the command line.

  • "%%N" what exactly it is.. – Kepler128 Jun 13 '14 at 10:54
  • It may look funny but i m very new to this stuff help me – Kepler128 Jun 13 '14 at 10:54
  • %%N is the DOS variable that runs through all files in the directory matching .cub extension. Just type it the same way. %%~nN is the file name without extension. – AndreJ Jun 13 '14 at 11:10
  • but when i execute this in OSGEO4W shell reflecting an errot and it is "%%N was unexpected at this time". What doese this mean? – Kepler128 Jun 13 '14 at 12:08
  • 2
    Use %%N in a batch file and %N on the command line. – user2856 Jun 5 '17 at 1:16
4

If using a linux OS, you can use a for loop in your shell:

for f in *.cub; do
     gdal_translate "$f" "${f%.*}.tif"
done

For more information on what this is doing, see the accepted answer to this question https://stackoverflow.com/q/965053/737471

  • This is not working for directories that contain more than a single input file. – eclipsed_by_the_moon Jun 4 '17 at 12:09
  • Sorry for the noise, the issue was caused by spaces in the file name: myraster (copy).jpg – eclipsed_by_the_moon Jun 4 '17 at 16:15
  • @eclipsed_by_the_moon use double quotes, see edited answer. – user2856 Jun 4 '17 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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