问题
How can one make a Rasterbrick
in R
from several hdf5
files? Often, data are provided in hdf5
format and one has to convert it to a more friendly format for easy handling.
At the moment I know of the rhdf5 package
but how to get a RasterBrick
is that which I am unsure about.
source("http://bioconductor.org/biocLite.R")
biocLite("rhdf5")
library("rhdf5")
library("raster")
You can access several hdf5 files on this link http://mirador.gsfc.nasa.gov/cgi-bin/mirador/cart.pl?C1=GPM_3IMERGHH&CGISESSID=fb3b45e091f081aba8823f3e3f85a7d9&LBT_THRESHOLD=4000000.
You can use two files for illustration.
Thanks!
AT.
回答1:
One option is using gdalUtils
to convert the hdf5
files into GTiff
. Once you did that you can read them in a stack. Here is an example code:
# list all the `hdf5` files
files <- list.files(path=".", pattern=paste(".*.h5",sep=""), all.files=FALSE, full.names=TRUE)
#choose the band that you want using the sds[] option and write GTiff files.
for (i in (files)) {
sds <- get_subdatasets(i)
r2 <- gdal_translate(sds[1], dst_dataset =paste(i,".tif",sep=""))}
来源:https://stackoverflow.com/questions/35323495/how-to-make-a-rasterbrick-from-hdf5-files-r