简体   繁体   中英

shrink a raster file in R

I have a large number of large image files that I would like merge together but run into memory issues. I would like to resave them all as a shrunken version. Then, merge the newer smaller versions together.

How can I shrink a raster object? Say I want to work with volcano :

library(raster)

vol  <- raster(volcano)

object.size(volcano)
# 42672 bytes

# I would expect to be able to use a function to shrink it here 
# to retain the CRS and have it represent a matrix of a smaller size. 

You cannot do it without losing information. Each cell has a value, which takes memory. You can free memory only by lowering the number of cells. if this approach is feasible to you, you can aggregate() each raster using several methods (eg bilinear interpolation). This gives a raster that has less cells with averaged values.

/E

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM