简体   繁体   中英

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

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.

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.

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM