How to mosaic the same HDF files using this R function?

隐身守侯 提交于 2019-12-11 13:59:10

问题


There are more than 1,000 MODIS HDF images in a folder:

M:\join

Their names show us which files must be mosaiced together.

For example, in the below files, 2009090 means these three images must be mosaiced together:

MOD05_L2.A2009090.0420.051.2010336084010
MOD05_L2.A2009090.0555.051.2010336100338
MOD05_L2.A2009090.0600.051.2010336100514

Or these two, are for the same date, 2009091:

MOD05_L2.A2009091.0555.051.2010336162871
MOD05_L2.A2009091.0600.051.2010336842395

I am going to mosaic them using this function (source of function ):

mosaicHDF(hdfNames, filename, MRTpath, bands_subset, delete=FALSE)

How should I introduce my HDF files to hdfNames?

And what should I write in filename?

I tried to find a manual for this function, but there was not anything.

Thanks for your help.


回答1:


I did find the answer, fortunately. Thanks for your help.

hdfs <- c('MOD05_L2.A2009090.0420.051.2010336084010.hdf',
          'MOD05_L2.A2009090.0555.051.2010336100338.hdf',
          'MOD05_L2.A2009090.0600.051.2010336100514.hdf')

mosaicHDF(hdfNames=hdfs, filename='newhdf.hdf', MRTpath='C:/MRT/bin',bands_subset="1 0 0 0", delete=FALSE) 

But I have a new problem :-)

Since there are thousands of HDF files in the folder,

How could I write a loop to introduce all HDF files to the function?

FYI: I am quite new to R.




回答2:


This question is quite old but I figured I'd post up the R code Canada2015 asked for. So for a loop over years 2000 to 2016, assuming the file names still have the A < YEAR > < MONTH >< DAY >. format. This code mosaics all tiles together to produce a new file for each year present. If you had to mosaic many tiles from a single year, you could just change the pattern= argument to something general like '.hdf'

for(i in 2000:2016){
  HDFs <- list.files(path = "F:/PATHTOFILES/HDFs/", pattern = paste("A",i,sep = ""))
  mosaicHDF(hdfNames = HDFs, filename = paste('newhdf',i,'.hdf',sep = ""), MRTpath = 'C:/MRT/bin',bands_subset="1 0 0 0", delete=FALSE)
}


来源:https://stackoverflow.com/questions/30628501/how-to-mosaic-the-same-hdf-files-using-this-r-function

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