Skip to content

reading and reformatting hdf files within raster

2 messages · Barry Rowlingson, Loïc Dutrieux

#
On Sat, May 25, 2013 at 2:17 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
Have you tried searching for HDF on CRAN?

http://cran.r-project.org/web/packages/h5r/index.html

I don't fancy downloading a 196MB MODIS file to find out...

Barry
#
Hi Joseph,

There is a MODIS package that has many useful utilities for downloading, reading, reprojecting, ... MODIS (HDF4) data.

library(raster)
library(MODIS)
sds <- getSds('filename.hdf') # Make sure to use full path
evi <- raster(sds$SDS4gdal[2]) # REad SDS 2 of the hdf file (EVI)

# Or eventually
evi <- raster(readGDAL(sds$SDS4gdal[2], as.is = TRUE))

The second option allows to have control over the otherwise by default scaling of the data. It can be useful when the scaling factor provided by the metadata is incorrect, which I think is the case for this particular MODIS product.

Cheers,

--
Lo?c Dutrieux
Laboratory of Geo Information Science and Remote Sensing
Wageningen University
The Netherlands