[R-sig-Geo] Processing HDF4 data files with R / GeospatialData Abstraction Library (GDAL)
Rick Reeves
reeves at nceas.ucsb.edu
Fri Jan 26 18:54:53 CET 2007
Greetings:
Recently I augmented my installation of R ver 2.4.0 on Dapper Drake Linux
to read data files in Hierarchical Data Format Version 4 (HDF4) format. I
thought that the steps that I took might be useful to other R users who have
not yet had to modify one of the R packages to include a new capability.
Why did I need to have HDF4 support in R?
The rgdal package provides HDF image I/O support is however, the default
rgdal version downloaded from the archives supports only the HDF5 format,
which is not backwards-compatible with HDF4. Many spatial datasets
(for example, SeaWIFS digital ocean color imagery) distributed by
US government agencies are stored in HDF4 format.
Here is the procedure that I worked out:
To include HDF4, you have to download the HDF4 library
and then build a version of the GDAL library that links
in the HDF4 support.
1) I downloaded and unpacked the hdf4,jpeg6 and szip libraries from:
ftp.ncsa.uiuc.edu archives:
/HDF: 4.2.rl-linux.tar.gz
/szip :/szip2.0-linux.noenc.tar.gz
/jpeg6b-linux-gcc3.4.3.tar.gz
I did not need to build these libraries from source; instead, I just
extracted
the archive (.a) files included with each distribution, and put them
in a folder
accessible to the GDAL library build process. Call this library
/opt/libs4GDAL
for this discussion I put the following files into this folder:
libdf.a, libjpeg.a, libmfhdf.a, libsz.a,and libz.a
2) I built the GDAL library from source, linkin in the HDF file support.
to do this: I ran the GDAL 'configure' script included with the distribution
Note: To get a successful compilation, I had to modify the configure script
to include the correct location of the HDF source code include files:
I added a line : HDF4_INCLUDE="-I/usr/include/hdf" at the place
where the script tests for the existence of the include/hdf folder.Command
used to run configure: ./configure --with-hdf4=/opt/libs4GDAL
This built GDAL 1.4.0 library with HDF4 support
To test the installation, I ran the GDAL gdalinfo and gdal_translate commands
from the command line to read several HDF4 SeaWIFSfiles. This succeeded
3) I started R from the command line, and installed GDAL support using the
install.packages('rgdal') command, which builds the library from
source on
linux machines.
4)I tested HDF support within R:
library("rgdal")
GDALinfo("an.hdf.file")
hdfImage = readGDAL("an.hdf.file) // hdfImage is SpatialGridDataFrame
image(hdfImage) // displays the bitmap.
These commands correctly read HDF files containing a single spectral
band; however, The rgdal routines do not appear to correctly read
HDF files containing multiple bands of imagery.
The workaround here is to use the GDAL routines at the command
line to extract the 'included' image planes into individual HDF4 files;
as noted above, rgdal routines correctly read the single band images.
Has anyone addressed the issue of processing multiple-band HDF4 files
with R / rgdal?
Cheers,
--
Rick Reeves
Scientific Programmer / Analyst
National Center for Ecological Analysis and Synthesis
UC Santa Barbara
reeves at nceas.ucsb.edu
www.nceas.ucsb.edu
805 892 2533
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reeves.vcf
Type: text/x-vcard
Size: 339 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20070126/1ccb77ba/attachment.vcf>
More information about the R-sig-Geo
mailing list