在 R 中读取和使用 FireModis HDF 文件
Reading and working with FireModis HDF files in R
我正在尝试使用 hdfeos 信息中心 (https://hdfeos.org/software/r.php) 提供的说明读取 Modis Fire HDF 文件,这是代码:
sds<-get_subdatasets("modis_file")
#Modis_fire/MCD64A1.A2000306.h12v11.006.2017012010432.hdf"
d5<-readGDAL(sds[1],options=c("RASTERXDIM=4","RASTERYDIM=3","RASTERBDIM=2","RASTER4DIM=1","RASTER5DIM=0"))
#"HDF4_EOS:EOS_GRID:/Modis_fire/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Burn Date"
但是,我得到这个错误:
option 0: RASTERXDIM=4
option 1: RASTERYDIM=3
option 2: RASTERBDIM=2
option 3: RASTER4DIM=1
option 4: RASTER5DIM=0
Error in .local(.Object, ...) :
我不想翻译和编写其他格式的 HDF,因为我希望在编写转换之前执行合并和裁剪等操作:
r<-raster(d5)
有什么建议吗?
阅读提供的 link 中的文档,您正在尝试创建一个 5 维数据集。
我最好的猜测是,您使用的是普通 GDAL(而不是这个 GEE?),这似乎是您出错的原因(根据 link):
The RASTERXDIM, ..., RASTER4DIM options allow you to access 5-dimensional dataset and they are available only in GEE. If you use regular GDAL, you cannot access the dataset correctly.
但如果您只想读取和处理 HDF 文件,这就可以了:
library(MODIS)
## Note: I'm using the MODIS package to download the HDF file (not necessary if you have it on disk.
# the hdf variable will be the path to the file
hdf <- getHdf(HdfName = 'MCD64A1.A2000306.h12v11.006.2017012010432.hdf',forceDownload=T)
# print the subdatasets
gdalUtils::get_subdatasets(hdf)
# [1] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Burn Date"
# [2] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Burn Date Uncertainty"
# [3] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:QA"
# [4] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:First Day"
# [5] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Last Day"
sds <- gdalUtils::get_subdatasets(hdf)
r <- raster(sds[1])
# check raster output
r
# class : RasterLayer
# dimensions : 2400, 2400, 5760000 (nrow, ncol, ncell)
# resolution : 463.3127, 463.3127 (x, y)
# extent : -6671703, -5559753, -3335852, -2223901 (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs
# data source : HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Burn Date
# names : MCD64A1.A2000306.h12v11.006.2017012010432.hdf.MOD_Grid_Monthly_500m_DB_BA.Burn_Date
# values : -32768, 32767 (min, max)
我正在尝试使用 hdfeos 信息中心 (https://hdfeos.org/software/r.php) 提供的说明读取 Modis Fire HDF 文件,这是代码:
sds<-get_subdatasets("modis_file")
#Modis_fire/MCD64A1.A2000306.h12v11.006.2017012010432.hdf"
d5<-readGDAL(sds[1],options=c("RASTERXDIM=4","RASTERYDIM=3","RASTERBDIM=2","RASTER4DIM=1","RASTER5DIM=0"))
#"HDF4_EOS:EOS_GRID:/Modis_fire/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Burn Date"
但是,我得到这个错误:
option 0: RASTERXDIM=4
option 1: RASTERYDIM=3
option 2: RASTERBDIM=2
option 3: RASTER4DIM=1
option 4: RASTER5DIM=0
Error in .local(.Object, ...) :
我不想翻译和编写其他格式的 HDF,因为我希望在编写转换之前执行合并和裁剪等操作:
r<-raster(d5)
有什么建议吗?
阅读提供的 link 中的文档,您正在尝试创建一个 5 维数据集。
我最好的猜测是,您使用的是普通 GDAL(而不是这个 GEE?),这似乎是您出错的原因(根据 link):
The RASTERXDIM, ..., RASTER4DIM options allow you to access 5-dimensional dataset and they are available only in GEE. If you use regular GDAL, you cannot access the dataset correctly.
但如果您只想读取和处理 HDF 文件,这就可以了:
library(MODIS)
## Note: I'm using the MODIS package to download the HDF file (not necessary if you have it on disk.
# the hdf variable will be the path to the file
hdf <- getHdf(HdfName = 'MCD64A1.A2000306.h12v11.006.2017012010432.hdf',forceDownload=T)
# print the subdatasets
gdalUtils::get_subdatasets(hdf)
# [1] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Burn Date"
# [2] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Burn Date Uncertainty"
# [3] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:QA"
# [4] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:First Day"
# [5] "HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Last Day"
sds <- gdalUtils::get_subdatasets(hdf)
r <- raster(sds[1])
# check raster output
r
# class : RasterLayer
# dimensions : 2400, 2400, 5760000 (nrow, ncol, ncell)
# resolution : 463.3127, 463.3127 (x, y)
# extent : -6671703, -5559753, -3335852, -2223901 (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs
# data source : HDF4_EOS:EOS_GRID:/tmp/Rtmp9QhqAG/MODIS_ARC/MODIS/MCD64A1.006/2000.11.01/MCD64A1.A2000306.h12v11.006.2017012010432.hdf:MOD_Grid_Monthly_500m_DB_BA:Burn Date
# names : MCD64A1.A2000306.h12v11.006.2017012010432.hdf.MOD_Grid_Monthly_500m_DB_BA.Burn_Date
# values : -32768, 32767 (min, max)