How to Make a RasterBrick from HDF5 Files? R

左心房为你撑大大i 提交于 2019-12-24 13:03:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!