如何从带有xy坐标的rasterstack中提取值? [英] How to extract values from rasterstack with xy coordinates?
本文介绍了如何从带有xy坐标的rasterstack中提取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个栅格堆栈(5个栅格图层),它实际上是一个时间序列栅格.
I have a rasterstack (5 raster layers) that actually is a time series raster.
r <- raster(nrow=20, ncol=200)
s <- stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )
s
class : RasterStack
dimensions : 20, 200, 4000, 5 (nrow, ncol, ncell, nlayers)
resolution : 1.8, 9 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
names : layer.1, layer.2, layer.3, layer.4, layer.5
min values : -9.012146, -9.165947, -9.707269, -7.829763, -5.332007
max values : 11.32811, 11.97328, 15.99459, 15.66769, 16.72236
我的目标是绘制每个像素并探索其随时间的行为.
My objective is to plot each pixel and explore their behavior over time.
我如何提取每个像素及其x,y坐标并绘制时间序列曲线?
推荐答案
非常感谢@ SimonO101!
Thanks a lot @SimonO101 !
此代码有效.
r <- raster(nrow=10, ncol=10)
s <- stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )
s[1:3]<-NA
vals <- values(s)
coord <- xyFromCell(s,1:ncell(s))
combine <- cbind(coord,vals)
write.table(combine,"xyvalues.txt")
这篇关于如何从带有xy坐标的rasterstack中提取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文