0

I would like to be able to merge, mosaic, or stack several .hdf files. Does anyone know the package or library i should be looking for the tool to do this?

  • Check out gdalUtils package and you need to know whether hdf4 or hdf5 and install other tools for the package to call – mdsumner Jan 28 '14 at 20:06
  • will this isn't R either, there's also h5py. h5py.org. – Roland Jan 28 '14 at 21:45
  • This does work pretty well if you can compile HDF 4 and Netcdf in to GDAL and in turn to rgdal and ncdf4. Straightforward more or less in Linux. – mdsumner Aug 2 '14 at 9:14
4

First, you are using R. R Studio is just an IDE for R so in the future please make this an R question. I will warn you that working with HDF files in R is a pain. In theory GDAL supports HDF5 so one could use readGDAL in the rgdal package. Depending on the source of the data readGDAL has a high fail rate making it less than reliable.

Historically, there is a "hdf5" package available but it has some odd dependencies, is a bit clunky and not available for the current version of R. You would have to back version R and then download a supported version of the package.

I would recommend using "rhdf5" which is available on Bioconductor. There is some slight overhead in installing it but is quite easy with a few lines of code. The bioLite script allows for access to Bioconductor and management of packages.

If in windows, run R as administrator. This installs bioLite and rhdf5

source("http://bioconductor.org/biocLite.R")
biocLite("rhdf5")    

Once you have the data read into R you can coerce into your preferred spatial class and perform whatever operation you wish. I do have to say that R does not seem like the ideal software for this task. For a mosaic operation on a number of HDF files I would use a utility to convert the data into a different image format and the use a GIS software (e.g., GRASS, QGIS...) to mosaic the images. GRASS does support HDF and seems like a sensible alternative. You may be able to do this in QGIS using the GRASS utilities.

Here is an example of working with HDF files in R. http://www.r-bloggers.com/working-with-hdf-files-in-r-example-pathfinder-sst-data/

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.