0

I have quite a few geotiff files that I need to process with gdal_translate to remove the 4th (alpha) band. They are all in the same directory (for example, /imagery).

The original names are in the format m_3607604_ne_18_1_20160723_20160928b.tif, and after processing multiple files, output the new name in the same directory but with *c.tif. The examples I've tried keep throwing errors. I can run one file at a time successfully, using the below from a command prompt:

gdal_translate -b 1 -b 2 -b 3 m_3607604_ne_18_1_20160723_20160928b.tif m_3607604_ne_18_1_20160723_20160928c.tif

0

1 Answer 1

1

Your problem is not GIS specific but if you are on Windows try something like this:

for %i in (*.tif) DO gdal_translate -b 1 -b 2 -b 3 %~ni.tif %~ni_c.tif

If does not work exactly as you want because is takes

m_3607604_ne_18_1_20160723_20160928b.tif

and outputs

m_3607604_ne_18_1_20160723_20160928b_c.tif

You can rename the files afterwards. Myself I would write the result into a virtual VRT file, or if i would create new TIFF files I would create them as tiled and compressed, but you did not ask that.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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