TransWikia.com

Converting HDF to TIFF using batch processing with gdal_translate

Geographic Information Systems Asked by Gülnihal Kurt on July 13, 2021

I have a huge MODIS dataset and I need to translate them to tiff from hdf.

My input path is: C:UsersHPDesktopdenemeham_veri
and hopefully, the output path is: C:UsersHPDesktopdenemeyeni

This is what I’m trying to run for batch processing:

FORFILES /m MOD10A2.A2016321.h20v05.006.2016340133152.hdf C:UsersHPDesktopdenemeham_veri "cmd /c gdal_translate -sds -of HDF4_SDS:hdf:@file:01 C:UsersHPDesktopdenemeyeniMOD10A2.A2016321.h20v05.006.2016340133152.tif"

and this is what I got from command prompt:

ERROR 6: Too many command options '%C:UsersHPDesktopdenemeyeni%@MOD10A2.A2016321.h20v05.006.2016340133152.tiff'

Where am I doing wrong?

One Answer

First of all, make sure forfile command returns the files you want to process.

The next command prints all HDF files' name in the folder:

forfiles /p C:UsersHPDesktopdenemeham_veri /m *.hdf /c "cmd /c echo @path

You may think of using this:

FORFILES /m *.hdf /P C:UsersHPDesktopdenemeham_veri /C "cmd /C gdal_translate -sds @file C:[email protected]"

But unfortunately, @fname returns file name with double quotes like "file". So, the full output path would be like C:UsersHPDesktopdenemeyeni"file".tif and this path is incorrect because of double quotes.

Therefore, you need to get rid of them. I, finally, found a solution as follows:

FORFILES /m *.hdf /P C:UsersHPDesktopdenemeham_veri /C "cmd /Q /C for %I in (@fname) do gdal_translate -sds -of GTiff @file C:UsersHPDesktopdenemeyeni%~I.tif"

Correct answer by Kadir Şahbaz on July 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP