本文介绍了堆叠后如何编写栅格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想操作几个光栅文件,然后再次写入它们.

There are several raster files that I want to manipulate and then write them again.

rasterfiles   <- list.files("C:\\data", "*.envi", full.names = TRUE)
d1 <-  overlay(stack(rasterfiles ), 
               fun=function(x) movingFun(x, fun=mean, n=3, na.rm=TRUE))
d2=unstack(d1)

我很感激任何关于我们如何编写 d2(光栅)的想法

I am grateful to any idea on how we write d2 (rasters)

推荐答案

 writeRaster(d1, file="d1.nc") #other file formats such as .envi work as well

有效,因为 d1 是一个单一的栅格而不是一个栅格列表:实际上 overlay 的结果是一个单一的栅格(请参阅 ?overlay>).
另外stack的概念就是把多个一层的栅格,生成一个多层的栅格.
最后,如果您真的想单独保存每个图层,您可以在写入之前unstack您的栅格.
在这种情况下:

works since d1 is one single raster and not a list of rasters: indeed the result of overlay is one single raster (see ?overlay).
Additionally the concept of stack is precisely to take several rasters having one layer and produce one raster with several layer.
Eventually if you really want to save each layer separately, you can unstack your raster prior to writing.
In which case:

d2 <- unstack(d1)
outputnames <- paste(seq_along(d2), ".nc",sep="")
for(i in seq_along(d2)){writeRaster(d2[[i]], file=outputnames[i])}

这篇关于堆叠后如何编写栅格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:52