Skip to content

Read HDF files

6 messages · Arnaud Mosnier, Alexandre Castagna, Paul Hiemstra +1 more

#
On 09/01/2011 05:20 PM, Arnaud Mosnier wrote:
The answer can be found by googling for "R read hdf". That leads to the
HDF5 package or building GDAL with HDF support. Alternatively, find a
(command)-line tool which can translate HDF5 to geotiff or netCDF (e.g.
gdal_translate or ) and then use readGDAL or the ncdf package.

Paul
#
You can try something like this;

# check out the raster and rgdal packages
library(raster)
library(rgdal)
# have the files in your current wd()
# for MODIS data MOD13C1 I do the following
fl <- list.files(pattern="\\.hdf$", recursive = TRUE) # without directories
GDALinfo(modis) # check out the name using this function
fndvi <- paste("HDF4_EOS:EOS_GRID:",fl[1],":MODIS_Grid_16Day_VI_CMG:CMG 0.05
Deg 16 days NDVI",sep='')

# then extract raster info and data and much more
system.time(data <- readGDAL(fndvi, offset=c(0,0), region.dim=c(1, 1))) #
centre is at (0,0)
parameters <- gridparameters(data)
res <- parameters$cellsize[1]
res

good luck.
Jan
http://www.grs.wur.nl/UK/Staff/Jan+Verbesselt/
http://bfast.r-forge.r-project.org/


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Read-HDF-files-tp6750856p6753611.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Please have a look at the example I provided, it should work for your HDF4 files. The MODIS data I am dealing with comes in HDF4 format. I did not need to build a specific GDAL version that supports HDF4 format.
I am using GDAL available via http://www.kyngchaos.com/software/frameworks for Mac OSx, and the latest version of rgdal for R2.13.1. In which environment are your working?
Best,
Jan
On 02/09/2011, at 3:36 PM, Arnaud Mosnier [via R-sig-geo] wrote:

            
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Read-HDF-files-tp6750856p6753935.html
Sent from the R-sig-geo mailing list archive at Nabble.com.