-1

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?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Vilen
  • 139
  • 1
  • 6

1 Answers1

-1

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).

lynxlynxlynx
  • 4,247
  • 3
  • 29
  • 45