问题描述
如何从多个hdf5
文件中在R
中创建Rasterbrick
?通常,数据以hdf5
格式提供,并且必须将其转换为更友好的格式以便于处理.
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.
目前我知道rhdf5 package
,但是如何获得RasterBrick
是我不确定的事情.
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")
您可以在此链接上访问多个hdf5文件 http://mirador.gsfc.nasa.gov/cgi-bin/mirador/cart.pl?C1=GPM_3IMERGHH&CGISESSID=fb3b45e091f081aba8823f3e3f85a7d9&LBT_THRES.
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.
谢谢!
AT.
推荐答案
一个选项是使用gdalUtils
将hdf5
文件转换为GTiff
.完成后,您可以将它们读入堆栈.这是示例代码:
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=""))}
这篇关于如何用HDF5文件制作RasterBrick? [R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!