writeRaster输出文件大小 [英] writeRaster output file size

查看:2857
本文介绍了writeRaster输出文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,它以光栅砖对象的形式读取多波段图像,迭代执行各种计算的波段,然后将光栅写为新的.tif。所有这一切都很好,但新图像文件的文件大小大约是其四倍(我假设因为原始图像有4个波段)。我想知道writeRaster()函数中是否有一个我不知道的参数,或者是否有其他方法我可以确保输出图像与输入的文件大小基本相同。

I have a function that reads a multi-band image in as a raster brick object, iterates through the bands doing various calculations, and then writes the raster out as a new .tif. All of this works fine, but the file size of the new image file is roughly four times greater (I assume because the original image has 4 bands). I'm wondering if there's a parameter in the writeRaster() function that I'm unaware of, or if there's some other way I can ensure that the output image is basically the same file size as the input.

原始文件大小为134 MB;输出范围从471到530 MB左右,具体取决于格式。

Original file size is 134 MB; output ranges from 471 to 530 MB or so, depending on format.

简化代码:

library(rgdal)
library(raster)

path = "/Volumes/ENVI Standard Files/"
img = "qb_tile.img"

imageCorrection = function(path, img){
  raster = brick(paste0(path, img))   
  raster = reclassify(raster, cbind(0, NA))  

  for(i in 1:nlayers(raster)){   
    raster[[i]] = raster[[i]] - minValue(raster[[i]]) 
  }
  writeRaster(raster, paste0(path,img,"_process.tif"), format = "GTiff", overwrite=TRUE)
}


推荐答案

您可以设置使用 rasterOptions()编写栅格的默认数据类型,如下所示:

You can set the default datatype for writing rasters with the rasterOptions() as follows:

rasterOptions(datatype="INT2U")

或直接在writeRaster调用中:

Or directly in the writeRaster call:

writeRaster(yourRas, "path/to/raster/", dataType="INT2U", options="COMPRESS=LZW")

另请注意该选项s参数,你可以指定压缩。

Also notice the options argument where you can specify compression.

通常当我从R导出整数栅格时,我确保我真的有整数而不是浮点数,因为这可能导致空光栅。在导出之前尝试以下操作:

Usually when I export integer rasters from R, I make sure that I really have integers and not floats, since this can result in an empty raster. Try the following before exporting:

ras <- as.integer(ras)

请注意:
同时检查栅格中的负值。如果您的值低于零,请尝试 INT2S

这篇关于writeRaster输出文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆