Arc*_*lon 2 gis r raster spatial r-raster
我正在使用北极海的测深图,其中包含11617*11617个细胞,每个细胞都有一个相对于海平面的高度值(从-5573到5921米).我希望编辑值大于0 m的所有像素,使其值为负10 m,然后保存此栅格.
bath=raster ('C:/Users/ls15g11/Desktop/IBCAO_V3_500m_RR_editinR.grd')
bath
class : RasterLayer
dimensions : 11617, 11617, 134954689 (nrow, ncol, ncell)
resolution : 500, 500 (x, y)
extent : -2904250, 2904250, -2904250, 2904250 (xmin, xmax, ymin, ymax)
coord. ref. : NA
data source : C:\Users\ls15g11\Desktop\IBCAO_V3_500m_RR_editinR.grd
names : z
zvar : z
Run Code Online (Sandbox Code Playgroud)
我对R非常缺乏经验,所以非常感谢任何有关实现这一目标的帮助.
首先,让我们创建一些虚拟数据作为10x10栅格(以使其成为可重现的示例)
bath <- raster(nrows=10, ncols=10, vals=rnorm(100))
Run Code Online (Sandbox Code Playgroud)
然后我们就可以做到
bath[bath>0] <- -10
Run Code Online (Sandbox Code Playgroud)
这是 dww 答案的内存安全变体:
bath <- raster(nrows=10, ncols=10, vals=rnorm(100))
rbath <- reclassify(bath, cbind(0, Inf, -10), filename='file.grd')
Run Code Online (Sandbox Code Playgroud)