Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Possible Duplicate:
gdalwarp in a bash shell for loop

I have several modis images (.hdf) from which I want to use only the one band (NDVI) and create a ".tif" image. I have already finished all the preprocessing and I ended on the command below:

gdal_translate -of GTiff $input documents/test.tif

When I run it, I got the answer: "Too many command options"

BUT when I use the command "echo" and run the model by copy/pasting the result of the "echo" command:

gdal_translate -of GTiff "HDF4_EOS:EOS_GRID:"documents/modis_images/PullDir/0302579596islumc/MOD13Q1.A2011289.h19v04.005.2011307201911.hdf":MODIS_Grid_16DAY_250m_500m_VI:250m 16 days NDVI" documents/test.tif

it works fine.

What am I doing wrong???

Thank you!

share|improve this question

marked as duplicate by iant, matt wilkie, whuber Aug 30 '12 at 17:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

Do not worry, you only have a syntax problem, but not like the one in the possible duplicate. It works with echo, since it strips a layer of quotation marks, but when calling gdal_translate, it gets the raw contents of the variable. As a proof, if I echo your echoed result, all the quotation marks are gone:

$ echo "HDF4_EOS:EOS_GRID:"documents/modis_images/PullDir/0302579596islumc/MOD13Q1.A2011289.h19v04.005.2011307201911.hdf":MODIS_Grid_16DAY_250m_500m_VI:250m 16 days NDVI"
HDF4_EOS:EOS_GRID:documents/modis_images/PullDir/0302579596islumc/MOD13Q1.A2011289.h19v04.005.2011307201911.hdf:MODIS_Grid_16DAY_250m_500m_VI:250m 16 days NDVI

Since we don't see the value of your input variable, it is hard to say where exactly the problem lies. The first thing you should do is quote input - "$input", which will ensure there will be no word splitting (causing additional arguments to appear to gdal). If that's not enough, change how you construct $input and use a mix of single/double quotes and escape characters to make it robust (unlike the echoed line).

share|improve this answer
    
Thanks for the answer! I tried with double quote, simple quote, combination of them but still nothing... The main problem for me is that I can't use the command -b of the gdal_translate in order to select the band I want to insert in the output file –  Vilen Aug 31 '12 at 8:13
    
Then just run it with "$(echo $input)" instead. –  lynxlynxlynx Aug 31 '12 at 8:26
    
I just tried it but the outcome is: "it is not recognised as a supported dataset name" Normally by typing [gdal_translate -of GTiff -b 1 input.hdf output.tif] shouldn't I get as a result one tiff with the desired band??? Thanks –  Vilen Aug 31 '12 at 8:40
    
eh, try without the quotes then, you don't seem to have any whitespace anyway. –  lynxlynxlynx Aug 31 '12 at 8:59

Why don't you just use a simple loop, like: for i in *.hdf; do something [e.g. gdal_translate -of GTiff $i out/$1]; done

share|improve this answer
    
That would be easy but I only want to use one subdataset from the .hdf files. When I type [e.g. gdal_translate -of GTiff -b 1 input_file output_file] the answer I get is: "Input file contains subdatasets. Please, select one of them for reading." –  Vilen Aug 31 '12 at 8:06

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