5

I am trying to process MODIS files in R, which are in HDF4 format (link to data). I have experience reading in HDF5 and netCDF files in R, but HDF4 seems to be a common problem in R. I am using a MAC (Mountain Lion OS X 10.8.5), and have found the following webpages (link1, link2) helpful in setting up GDAL and the r package, rgdal. My problem is that is doesn't look like I have any HDF4 drivers, and I'm wondering what step I have missed?

library(rgdal)
gdalDrivers()

...
...
44              GTX                                 NOAA Vertical Datum .GTX   TRUE FALSE
45              GXF                             GeoSoft Grid Exchange Format  FALSE FALSE
46             HDF5                       Hierarchical Data Format Release 5  FALSE FALSE
47        HDF5Image                                             HDF5 Dataset  FALSE FALSE
48              HF2                               HF2/HFZ heightfield raster  FALSE  TRUE
49              HFA                              Erdas Imagine Images (.img)   TRUE  TRUE
...
...

So, nothing listed for HDF4 as shown in point 6.2 of the example. Does anyone know what my problem might be? The issue of reading HDF4 data into R seems to be a common one. I would have no problem doing some sort of batch conversion to HDF5 or netCDF if someone has a suggestion for this.

2
  • Welcome to GIS.SE. It looks (from gdal.org/frmt_hdf4.html) like HDF4 has specific dependencies on GDAL. Perhaps you didn't have the NCSA HDF library (or the wrong version, or it wasn't in a found location) installed at GDAL build time? Perhaps you didn't build it, but the same dependency would be needed.
    – BradHards
    Commented Feb 13, 2014 at 9:51
  • 1
    HDF4 can be built into rgdal by building it into GDAL, it's not straightforward: scigeo.org/articles/…
    – mdsumner
    Commented Jun 26, 2014 at 12:46

4 Answers 4

2

I developed gdalUtils specifically for this issue. On a Mac, install the GDAL frameworks which include HDF4/5 and NetCDF drivers, and then use gdalUtils to interface with it.

2
1

I've no experience with HDF4 but, may you work with the MODIS R Package and follow the Modis R: Package tutorial. Or use a conversation tool like h4toh5 or NCL. The last link gives you also some advises to deal with the difficulties of conversation.

2
  • Unfortunately, this package is depreciated and not available at R >= v3. Do not waist your time trying to get it to work, some dependencies do not exist any longer and the code itself is broken. An alternative is to work with the MODIS subsets using the MODISTools package (cran.r-project.org/web/packages/MODISTools). You could however, follow the tutorial by reverting your R version to v2.15 Commented Feb 20, 2014 at 20:59
  • @JeffreyEvans, the MODIS package is available for current R versions, isn't it? In fact, I am working with it almost every day (R version 3.1.1) because I needed to download a lot of data lately. The only problem is that it is not on CRAN, but the development version was updated from 0.10-11 to 0.10-13 only recently, and for my purposes, some functions come in quite handy.
    – fdetsch
    Commented Jul 21, 2014 at 9:31
0

I am using package gdalUtils which uses gdal binary (for example osgeo4w). This combination works with most of GIS formats.

-2

I think this has already been answered on another site

https://geoscripting-wur.github.io/IntroToRaster/hdf.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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