Skip to content
Prev 20671 / 29559 Next

reading .hdf files

Ok, I actually think you probably got it working somewhat correctly
(if it returns something in the previous step) -- I think the issue
you are having is a few things:

1) Don't use the system.file for your own file -- the system.file()
call is specifically for demo files within a package.  Set the working
directory to where your HDF file is located and do:
setwd("path/to/your/hdf/files")
hdf_file <- "GVIX_NL_G16_C07_NVI_Y2005_P26.hdf"

Note you should be able to now do:
gdalinfo(hdf_file)

2) You are using an oddly formatted hdf file -- the get_subdatasets()
routine and the sd_index= parameter only work when the subdatasets are
named following a generally agreed-upon standard, the
"SUBDATASET_n_NAME" format (common to e.g. MODIS, Landsat LEDAPS, and
a lot of other products).  In your case, since it doesn't follow these
conventions, you can instead use the sds=TRUE parameter which will
extract ALL subdatasets it finds.  The one annoying part about this is
that GDAL won't append the correct suffix (at least, not with version
1.10.0 and earlier), so you will need to rename the output:
outfile="testout"
gdal_translate(hdf_file,outfile,sds=TRUE,verbose=TRUE)
# Notice you now have a file named "testout" with no extension.  Let's
rename it:
file.rename(outfile,paste(outfile,".tif",sep="")) # Only if a tif.
Mod this if a different output format.

Hope this helps!  I'll make it more clear in future documentation when
the sd_index parameter works.

--j
On Tue, Mar 25, 2014 at 1:52 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote: