我有一个文件夹,里面装满了我想加载栅格并从中提取值的 geotiff。.tif 是 01APR2010.tif、02APR2010.tif、01MAR2010.tif 等。我想按时间顺序(按天)阅读文件,这样我就可以按照这些值保持井井有条。我有 2000-2011 年 3 月 1 日至 30 月 30 日。
我有名为 lsa、usa 和 alp 的 SpatialPointsDataFrame,其中包含我想要相应值的坐标。我已经阅读了这些文件(感谢其他问题/答案)
library(raster)
library(plyr)
year=2010
site=list(lsa,usa,alp)
rcn.extract.swe<-function(r,site){
projection(r)=CRS('+proj=longlat +datum=NAD83')
return(mean(extract(r,coordinates(site)[,1:2])))
}
temp_geotiffs=getwd()#location of geotiffs
filenames <- list.files(temp_geotiffs, pattern="*.tif", full.names=TRUE)
ldf <- llply(filenames, raster)
res <- outer(ldf,site,Vectorize(rcn.extract.swe)) #this gives a matrix
也许有更好的方法?我也试过了mapply
,但是outer
所有的组合
这里有一些变量可以使用:
lsa=structure(c(-105.593648807562, -105.593721469436, -105.593667442221,
-105.593755471559, -105.593796239505, -105.59393253876, -105.593864787348,
-105.594020998966, -105.593758049064, 40.0538437274748, 40.0538836912761,
40.0540185900867, 40.0540081923506, 40.0541962757639, 40.0542507971756,
40.0544078670555, 40.054427734347, 40.0540699483592), .Dim = c(9L,
2L), .Dimnames = list(NULL, c("coords.x1", "coords.x2")))
usa=structure(c(-105.580580448185, -105.580661572731, -105.58071127033,
-105.580955908821, -105.580938632289, 40.0514730866613, 40.0513509958902,
40.0512184221927, 40.0513010575266, 40.0514244681361, 3437.769,
3434.92, 3431.876, 3434.075, 3436.987), .Dim = c(5L, 3L), .Dimnames = list(
NULL, c("coords.x1", "coords.x2", "coords.x3")))
alp=structure(c(-105.593648807562, -105.593721469436, -105.593667442221,
-105.593755471559, -105.593796239505, -105.59393253876, -105.593864787348,
-105.594020998966, -105.593758049064, 40.0538437274748, 40.0538836912761,
40.0540185900867, 40.0540081923506, 40.0541962757639, 40.0542507971756,
40.0544078670555, 40.054427734347, 40.0540699483592, 3538.319,
3539.285, 3541.733, 3541.962, 3545.753, 3547.899, 3550.574, 3552.051,
0), .Dim = c(9L, 3L), .Dimnames = list(NULL, c("coords.x1", "coords.x2",
"coords.x3")))
r=raster(matrix(runif(100,0,3),nrow=20),xmn=-112.25,xmx=-104.125,ymn=33,ymx=43.75)
writeRaster(r,'01APR2010.tif')
writeRaster(r,'02APR2010.tif')
writeRaster(r,'03APR2010.tif')
writeRaster(r,'04APR2010.tif')
writeRaster(r,'01MAR2010.tif')
writeRaster(r,'02MAR2010.tif')
writeRaster(r,'03MAR2010.tif')
感谢您的帮助!