简体   繁体   English

如何使用此R函数拼接相同的HDF文件?

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

There are more than 1,000 MODIS HDF images in a folder: 文件夹中有1,000多个MODIS HDF图像:

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: 例如,在以下文件中, 2009090表示这三个图像必须镶嵌在一起:

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 : 或这两个日期是同一日期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 ? 如何将我的HDF文件引入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, 由于该文件夹中有数千个HDF文件,

How could I write a loop to introduce all HDF files to the function? 如何编写循环以将所有HDF文件引入该函数?

FYI: I am quite new to R. 仅供参考:我对R很陌生。

This question is quite old but I figured I'd post up the R code Canada2015 asked for. 这个问题已经很老了,但我认为我会张贴要求的R代码Canada2015。 So for a loop over years 2000 to 2016, assuming the file names still have the A < YEAR > < MONTH >< DAY >. 因此,对于2000年至2016年的循环,假设文件名仍为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' 如果您必须在一年中拼接许多图块,则可以将pattern =参数更改为类似“ .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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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