I have a large number of files in .hdf format. These are sadly not the hdf5 files that I know are readable in R. Is there a way to load and read hdf files in R? Or is there a way to convert .hdf to hdf5? I downloaded the C-based h4toh5 tool, but it is not useful. Are there any other ways to convert? Many thanks.
-
Looks relevant: http://everydropr.wordpress.com/2011/11/06/how-to-processing-hdf4-data-using-r/ – Thomas Jul 31 '14 at 11:10
-
What actual .hdf files are they? HDF4 is really a legacy format now, and there are several types of them. Compile GDAL with HDF4 and it can read SDS "image-like" data sets, but lower level stuff like VData won't work-though you can use the underlying library if you you want. (The image-like stuff can even be read with NetCDF4 if it has HDF4 built-in.) This is all relatively straightforward on Linux, and there are no provided binaries I know of for Windows. There are some reprocessing projects to replace HDF4 collections and there are a few options depending on your platform (Windows, Linux?). – mdsumner Jul 31 '14 at 13:25
2 Answers
I wouldn't describe hdf4 as a legacy format @mdsummer. NASA still provides a lot of its data in hdf4.
This is similar to a few posts where people (myself included) haven't been sure whether their .hdf files are hdf4 or hdf5. You can use a program called HDFView which is free to download and really easy to use to find out if you've got hdf4/5 files. Just load a file in and look under "properties".
If you've got hdf4 files then you should check out the gdal_translate
from the gdalUtils
package. There's some more info here including the code I used for my hdf files:
Reading hdf files into R and converting them to geoTIFF rasters
You can use ncdf4 or rgdal packages as we explain here:
https://hdfeos.org/software/r.php
If you don't like h4toh5, h4tonccf is another tool that you can try:

- 185
- 7