I am new to using MODIS data and was hoping to get some help starting out. I have been able to download the hdf file but viewing it in R has been a problem for me. What I have found so far, and tried, is using the gdalUtils package. What I have done so far is this

gdal_translate('MOD11A1.A2012027.h11v04.005.2012028122822.hdf', 'test.tiff',

This gave me a tif image that I then put back into R using

data <- readTIFF('test.tiff')

This gave me a matrix in R that I could work with, which is what I ideally want. The only issue I had was that the values in the matrix were all decimals and when I did an image plot the each axis went from 0 to 1 instead of the proper lat and lon. the file I am using is LST in kelvin so these values are not correct. I know there is gdalwarp that does the reprojection but I am unsure how to use it. The inputs for s_srs and t_srs I was unsure of.

Can anyone point me in the right direction as a beginner. I have been reading the Steve Mosher blog so I have MRT and OSGeo4w installed plus all the packages he suggested.

  • You should be able to read the hdf file directly using the stack or brick functions in the raster package. You could then coerce into a matrix or array object although, I do not recommend this. – Jeffrey Evans Oct 28 '14 at 21:16
  • Jeff: well only if rgdal has also been built with HDF. – mdsumner Oct 28 '14 at 21:52
  • Hi Jeff, Thanks for the suggestion. I have the raster package but have not worked with it yet. What would you recommend if this is not the best option? – user2113499 Oct 29 '14 at 5:06
  • 1
    After loading the raster package, try rst <- raster("test.tiff") and then plot(rst). Your values should be fine then. Oh, and defining variable names that are identical to function names, e.g. data, can be quite misleading. – fdetsch Oct 29 '14 at 8:42
  • Thank you! This gave me the appropriate values for temperature. The values for lat and lon are still off but I think I can figure that out eventually. Thanks for pointing me in the right direction. – user2113499 Oct 29 '14 at 16:26

I would suggest using the MODIS reprojection tool (MRT - https://lpdaac.usgs.gov/tools/modis_reprojection_tool) to project and convert the data from HDF to TIFF. It's free (just need to create an account with NASA) and you'll be sure you're data is being transformed properly. Then you can work with your TIFF in R.

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.