I'm using the gdalwarp tool to convert MODIS .hdf into GeoTiff files. I want to set the value of the nodata cells so that when I import the .tif image into Grass there is no black edge. I'm using the following command:

gdalwarp -of GTiff -t_srs EPSG:4326 -dstnodata 0 <hdf> out.tif

This is working fine but I'm concerned that by setting -dstnodata to 0 I may be losing the valid cells that happen to have a value of 0. Is this actually what is happening, or does the tool work in a different way?


  • Have you checked the man page? gdalwarp – nickves Apr 3 '13 at 21:33
  • Yes - I couldn't see a satisfactory explanation – si_2012 Apr 3 '13 at 22:17
  • Also I highly recommend MRT tool for modis products. – nickves Apr 3 '13 at 23:00

gdalwarp is to reproject, if you want to translate from one raster format to another try gdal_translate

  • Yes, gdal_translate would work too, but what I'm really interested in is how to ensure I don't lose information when setting the NoData value... – si_2012 Apr 3 '13 at 22:50
  • when you using gdal_translate, the program takes into account the N/A values from the source metadata and marks them accordingly as N/A values in the output – nickves Apr 3 '13 at 22:57
  • Thanks for this. I've gone ahead and used gdalwarp as I needed to reproject at the same time, but specified srcnodata and dstnodata in the command. What was confusing me was the very specific case where the MODIS product doesn't have a fill value (e.g. MOD09A2 QC layers), however, I've worked around this in Grass. – si_2012 Apr 5 '13 at 17:14

If you use -dstnodata 0 you will not be able to distinguish output areas for which there was no source pixel from those for which the input pixel was zero. Ideally you would first review the source data and pick a nodata value that is outside the range of valid input data. You can use "gdainfo -mm" on the source image to get the min max.

Of course the nodata value has to be "in range" for the pixel type. If the pixel type is 8bit and the full dynamic range is already in use then there is no really good nodata based solution. One option then would be to promote to 16bit. Alternatively you could use "alpha" instead of nodata pixel values to mark areas of no source imagery. This can be accomplished with -dstalpha instead of -dstnodata.

I'm a bit vague on whether GRASS understands Alpha well, but at worse you could likely run some raster modelling to clear areas where the alpha band is 0.

  • Thanks for this - the problem you describe is exactly what has been concerning me. As I mention above, I've come up with a reasonable work-around for the particular data I'm using, but using dstalpha is something I wasn't aware of and will certainly look at further. – si_2012 Apr 5 '13 at 22:41

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.