我几乎没有表示双月数据的光栅图像。我想转换成每月两个月的数据采取两个图像的平均值。
如果我使用list.files中的stack()堆叠图像,总共有23个图像(单波段或单层),由于某种原因,它读取46个层,但如果我使用光栅函数单独打开所有光栅图像,然后堆叠,它只读取23个层。
我单独打开图像,然后将其堆叠起来,但当我转换双月儒略日时,它在4个月后无法正确读取。
library(raster)
setwd("F:/LANDSAT-NDVI/testAverage")
x1<-raster("landsatNDVISC05SLC2000001.tif")
x2<-raster("landsatNDVISC05SLC2000017.tif")
x3<-raster("landsatNDVISC05SLC2000033.tif")
x4<-raster("landsatNDVISC05SLC2000049.tif")
x5<-raster("landsatNDVISC05SLC2000065.tif")
x6<-raster("landsatNDVISC05SLC2000081.tif")
x7<-raster("landsatNDVISC05SLC2000097.tif")
x8<-raster("landsatNDVISC05SLC2000113.tif")
x9<-raster("landsatNDVISC05SLC2000129.tif")
x10<-raster("landsatNDVISC05SLC2000145.tif")
x11<-raster("landsatNDVISC05SLC2000161.tif")
x12<-raster("landsatNDVISC05SLC2000177.tif")
x13<-raster("landsatNDVISC05SLC2000193.tif")
x14<-raster("landsatNDVISC05SLC2000209.tif")
x15<-raster("landsatNDVISC05SLC2000225.tif")
x16<-raster("landsatNDVISC05SLC2000241.tif")
x17<-raster("landsatNDVISC05SLC2000257.tif")
x18<-raster("landsatNDVISC05SLC2000273.tif")
x19<-raster("landsatNDVISC05SLC2000289.tif")
x20<-raster("landsatNDVISC05SLC2000305.tif")
x21<-raster("landsatNDVISC05SLC2000321.tif")
x22<-raster("landsatNDVISC05SLC2000337.tif")
x23<-raster("landsatNDVISC05SLC2000353.tif")
data<stack(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23)
julday <-c("landsatNDVISC05SLC2000001.tif","landsatNDVISC05SLC2000017.tif","landsatNDVISC05SLC2000033.tif",
"landsatNDVISC05SLC2000049.tif","landsatNDVISC05SLC2000065.tif","landsatNDVISC05SLC2000081.tif",
"landsatNDVISC05SLC2000097.tif","landsatNDVISC05SLC2000113.tif","landsatNDVISC05SLC2000129.tif",
"landsatNDVISC05SLC2000145.tif","landsatNDVISC05SLC2000161.tif","landsatNDVISC05SLC2000177.tif",
"landsatNDVISC05SLC2000193.tif","landsatNDVISC05SLC2000209.tif","landsatNDVISC05SLC2000225.tif",
"landsatNDVISC05SLC2000241.tif","landsatNDVISC05SLC2000257.tif","landsatNDVISC05SLC2000273.tif",
"landsatNDVISC05SLC2000289.tif","landsatNDVISC05SLC2000305.tif","landsatNDVISC05SLC2000321.tif",
"landsatNDVISC05SLC2000337.tif","landsatNDVISC05SLC2000353.tif")
julday <- as.numeric(substr(julday, 24,26)) #24 to 26th digit in the file name represents Julian days#
dates <- as.Date(julday, origin=as.Date("2000-01-01"))
combinddat <- setZ(data, dates)
monthly <- zApply(combinddat, by = format(dates,"%Y-%m"), fun = mean, na.rm = T)使用该数据生成的日期是错误的;结果如下
> dates
[1] "2000-01-02" "2000-01-18" "2000-02-03" "2000-02-19" "2000-03-06"
[6] "2000-03-22" "2000-04-07" "2000-01-14" "2000-01-30" "2000-02-15"
[11] "2000-03-02" "2000-03-18" "2000-04-03" "2000-01-10" "2000-01-26"
[16] "2000-02-11" "2000-02-27" "2000-03-14" "2000-03-30" "2000-01-06"
[21] "2000-01-22" "2000-02-07" "2000-02-23"但我希望日期是12个月,以我的儒略日为基础。
发布于 2019-08-07 13:20:00
这并没有回答您的问题,但是您可以使用以下命令来改进您的代码:
setwd("F:/LANDSAT-NDVI/testAverage")
library(raster)
f <- list.files(pattern="\\.tif$")
f <- sort(f)
data <- stack(f)https://stackoverflow.com/questions/57386683
复制相似问题