如何在R中更改栅格时间序列的输出文件名?

时间:2017-09-05 16:51:25

标签: r

我有一个很大的时间序列(> 2000个文件),但作为示例,我将仅使用10个tif文件的列表:

> # list of tif files
> setwd("...raster/daily/")
> l <- list.files(getwd(), pattern=".tif")

我得到了这个结果:

> l
> [1] "ws_1.tif"  "ws_10.tif" "ws_2.tif"  "ws_3.tif"  "ws_4.tif"  "ws_5.tif"  "ws_6.tif"  "ws_7.tif"  "ws_8.tif"  "ws_9.tif

我需要将每个文件邮件更改为以下内容:

new_Year - 月 - Day.tif

new_2009-01-01.tif

new_2009-01-02.tif

new_2009-01-03.tif

...

我正在尝试使用以下命令执行此操作,但没有成功:

# command for to rewrite the set of raster files with the new filenames
for (i in 1:length(l)){
  r <- raster(l[i])
  tempo <- seq(as.Date("2009/01/02"), by = "day", length.out = 10)
  filename = paste0("new_",tempo)
  writeRaster(r, extension(filename, 'tif'))
}

当我使用此命令时,R只会创建第一个文件( new_2009-01-01.tif )并返回以下错误:

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file.
In addition: There were 22 warnings (use warnings() to see them)

我已尝试使用其他命令,如堆栈光栅文件名称来设置新名称,但仍然不成功。

有谁知道如何做到这一点或者至少指出了另一种方法来解决这个问题?

谢谢!

0 个答案:

没有答案