这是我在@Carl 提交的评论中找到的解决方案。
假设我的栅格名为d,具有以下特征:
class : RasterLayer
dimensions : 59, 67, 3953 (nrow, ncol, ncell)
resolution : 90, 90 (x, y)
extent : 482855.6, 488885.6, 4763517, 4768827 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=tmerc +lat_0=0 +lon_0=-3 +k=1 +x_0=500000 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : subset
values : 328, 1120 (min, max)
我首先用 x 坐标值生成了一个矩阵:
xm<-matrix(xFromCell(d,c(1:3953)),nrow=59,byrow=TRUE)
然后用矩阵创建一个栅格:
x<-raster(xm,xmn=482855.6, xmx=488885.6,ymn=4763517,ymx=4768827)
最后,分配它的投影:
projection(x)<-"+proj=tmerc +lat_0=0 +lon_0=-3 +k=1 +x_0=500000 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"
我还显示了光栅,看看结果是否OK...
plot(x)
...并阅读光栅描述
x
class : RasterLayer
dimensions : 59, 67, 3953 (nrow, ncol, ncell)
resolution : 90, 90 (x, y)
extent : 482855.6, 488885.6, 4763517, 4768827 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=tmerc +lat_0=0 +lon_0=-3 +k=1 +x_0=500000 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : layer
values : 482900.6, 488840.6 (min, max)
我重复了这些步骤,但在第一步中使用了yFromCell。