ラスターを読み込んで値を抽出したいジオティフで満たされたフォルダーがあります。.tif は 01APR2010.tif、02APR2010.tif、01MAR2010.tif などです。ファイルを時系列 (日ごと) に読みたいので、値を整理しておくことができます。2000 年から 2011 年までは、3 月 1 日から 8 月 30 日まであります。
lsa、usa、alp という名前の SpatialPointsDataFrame があり、対応する値が必要な座標があります。私はファイルを読むためにこれまでに得ました(SOに関する他の質問/回答に感謝します)
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')
あなたの助けに感謝します!