R - Chaging specific cell values in a large raster layer

巧了我就是萌 提交于 2019-12-04 19:14:10

You can do

r <- reclassify(raster, c(-Inf, 0, 0))

This will work on rasters of any size (no memory limitation)

42-

There are several postings that discuss memory issues and it's not clear if you have attempted any of these, .... but you should. The physical constraints are not clear, so you should edit your question to include size of machine and name of OS being tortured. I don't know how to construct a toybox that lets me do any testing, but one approach that might not blow up RAM use (as much) would be to first construct a set of indices marking the locations to be "zeroed":

 idxs <- which(raster <0, arr.ind=TRUE)
 gc() # may not be necessary

Then incrementally replace some fraction of locations, say a quarter or a tenth at a time.

 raster[ idxs[ 1:(nrow(idxs)/10), ] ] <- 0

The likely problem with any of this is that R's approach to replacement is not "in place" but rather involves the creation of a temporary copy of the objects which is then reassigned to the original. Good Luck.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!