[英]R Assigning x or y coordinate to cells of a raster to perform calculations
是否有任何解决方案可以使用 R 为光栅图像的所有单元分配 X 或 Y 坐标?
例如,假设我有一个包含 3x3 像元的栅格。 左下坐标为 X=7,Y=15(米),X 和 Y 方向的分辨率均为 +10 m(X 向右增加,Y 向上)。 然后,我想生成栅格表面,其中每个单元格都有 X 和 Y 值,如下所示:
X raster
7 17 27
7 17 27
7 17 27
Y surface
35 35 35
25 25 25
15 15 15
更新: 这是实际的光栅对象。
有没有办法做到这一点?
我尝试了“光栅”包,但找不到解决方案。
任何帮助,将不胜感激。
这是我找到的解决方案,灵感来自@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"
我还显示了光栅,看看结果是否正常......
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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.