Skip to content

What is the latest re: reading HDF files with R?

7 messages · Scott Mitchell, Rick Reeves, Roger Bivand +3 more

#
Greetings:

This week I am working with HDF format files containing ocean color 
imagery (CZCS, SeaWIFS) secured from NASA GSFC,
and would like to bring the image maps into the R environment.

One way I have done this is to use the SeaDAS software to extract a 
2-dim binary floating point matrix (from the HDF file)
and write it to disk, then use R pixmap() to read it in to a vector. 
This works, but one loses all of the image attributes
contained in the HDF header. Now, it would be good to read the HDF file 
directly into R, capturing the header attributes.

I have tried the R HDF5 library routine hdf5load(), which seems to read 
the new .hdf5 format
but NOT the older .hdf format (I tried, unsuccessfully)

Question is: Has anyone developed a technique to read HDF files with R?

Thanks in advance, Rick R
#
I have never done this, so may be missing something obvious, but can  
you not use rgdal ?  GDAL lists HDF4 as a supported format.

Cheers,
Scott
On 10-Jan-07, at 14:49, Rick Reeves wrote:

            
#
Good idea, Scott. I had forgotten about rgdal. Doesen't come up in the R 
topic search. RR
Scott W Mitchell wrote:

  
    
#
On Wed, 10 Jan 2007, Rick Reeves wrote:

            
You'll need a build of the GDAL library against HDF - which platform are
you using? I believe these formats can be accessed from GDAL, but
confirmation would be welcome. If not Windows, you will be installing a
source rgdal package anyway, if Windows, there are ways round using the
DLLs in FWTools - ask if you need guidance.

Roger

  
    
#
Rick Reeves wrote:
I have had success using rgdal compiled on Windows against FWTools.  I 
have read data from MCSST, GISST, Quikscat, Pathfinder 4 and 5 
SeaWiFSand Modis files.  I've not tried CZCS. 

Usually you need to supply your own metadata, in order to read subsets 
etc. but it works.

Cheers, Mike.
#
Hi Rick,

We've had success building an "hdfdump"--which is just ncdump from  
the standard netcdf package, configured to link with the hdf4 libs,  
then:

hdfdump foo.hdf|ncgen -b -o foo.nc

Then, of course, the excellent ncdf package can read it all in.

Best of luck,

Andy