【问题标题】:Writing Multiple GeoTiff File in R在 R 中编写多个 GeoTiff 文件
【发布时间】:2015-01-17 05:22:13
【问题描述】:

我是新的 R 用户,在 R 中阅读了 18 个 Geotiff 文件,并根据我感兴趣的区域屏蔽了 tiff。我现在无法编写 18 个蒙面的 Geotiff 文件。

require(raster)
raster_data <- list.files(path=getwd())
s <- stack(raster_data)
spf<-readShapePoly("basin.shp")
rc<-crop(s, extent(spf))
rm<-mask(rc, spf)
rf <- writeRaster(rm, filename=outputFile, overwrite=TRUE)

我想从我的 shapefile 中屏蔽 18 个 Geotiff 文件,但输出只有一个 tif 文件并且它没有打开。我在互联网上使用搜索选项,但找不到适合我的查询的答案。

谢谢

【问题讨论】:

  • 您能描述一下您的方法遇到的错误吗?
  • 你可以尝试在rf &lt;- writeRaster(u, filename=outputFile, overwrite=TRUE)之前添加一个额外的步骤u &lt;- unstack(rm)
  • 或只是或只是writeRaster(rm, filename=outputFile, overwrite=TRUE, bylayer = T)
  • 我试过了,但出现的错误消息是 Error in .local(x, filename, ...) : 文件名的数量 > 1 但不等于层数

标签: r raster geotiff


【解决方案1】:

您一定会在 SO 上找到问题的答案。在herehere 之前提出过问题,herehere 提供了答案,bylayer 选项由writeRaster 提供。

如果您不需要将它们取消堆叠到列表中,请尝试 bylayer = T

类似

library(raster)
r1 <- raster(ncol=10, nrow=10)
r1[] <- 1:100
s <- stack(r1, r1)
writeRaster(s, '~:/r.tif', bylayer = T)

【讨论】:

  • 如果您知道之前有人问过,您应该将帖子标记为重复。
  • 错误信息是 Error in .local(x, filename, ...) : the number of filenames is > 1 but not equal to the number of layers
  • @user3356873 - 使用writeRaster(s, names(s), bylayer=T, format='GTiff') 可能更简单。
  • @jbaums 我们会在 SO 上找到几个重复的问题。
  • 当然,有很多重复的,但我们会努力将它们标记为这样。如果您知道答案在 SO 上,最好标记它而不是重新回答它。
猜你喜欢
  • 2019-05-15
  • 2013-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-18
  • 2011-04-12
  • 2021-01-31
  • 2022-11-03
相关资源
最近更新 更多