0
從this file我想提取某些座標的所有值。從RasterBrick提取某些座標的數據
所以我創建了一個RasterBrick:
library(raster)
library(R.utils)
rr <- gunzip("rr_0.25deg_reg_v12.0.nc.gz")
rr <- brick(rr)
> rr
class : RasterBrick
dimensions : 201, 464, 93264, 23922 (nrow, ncol, ncell, nlayers)
resolution : 0.25, 0.25 (x, y)
extent : -40.5, 75.5, 25.25, 75.5 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : C:\...\rr_0.25deg_reg_v12.0.nc
names : X1950.01.01, X1950.01.02, X1950.01.03, X1950.01.04, X1950.01.05, X1950.01.06, X1950.01.07, X1950.01.08, X1950.01.09, X1950.01.10, X1950.01.11, X1950.01.12, X1950.01.13, X1950.01.14, X1950.01.15, ...
Date : 1950-01-01, 2015-06-30 (min, max)
varname : rr
現在我想提取所有值(每日precipiation從1950年1月1日至2015年6月30日)爲某個座標,例如LON 9.258157 LAT 47.70842
我試圖extract
像這樣:
raster::extract(rr, cbind(9.258157, 47.70842), df = TRUE)
在所得:
'data.frame': 1 obs. of 23923 variables:
$ ID : num 1
$ X1950.01.01: num 0
$ X1950.01.02: num 9.3
$ X1950.01.03: num 4.2
$ X1950.01.04: num 11.2
$ X1950.01.05: num 0
$ X1950.01.06: num 0
$ X1950.01.07: num 0
$ X1950.01.08: num 0
$ X1950.01.09: num 0
$ X1950.01.10: num 0
...
但我想與兩列(日期和值)作爲輸出的數據幀,所以我做了:
rr.plot <- t(raster::extract(rr, cbind(9.258157, 47.70842), df = TRUE))
rr.plot <- data.frame(Date = as.Date(substr(rownames(rr.plot), 2, 11), format = "%Y.%m.%d"), Prcp = rr.plot[,1])[-1,]
rownames(rr.plot) <- 1:nrow(rr.plot)
> head(rr.plot)
Date Prcp
1 1950-01-01 0.0
2 1950-01-02 9.3
3 1950-01-03 4.2
4 1950-01-04 11.2
5 1950-01-05 0.0
6 1950-01-06 0.0
但我懷疑這是最好的方式去,必須有解決方案離子更直接?