R terra tif 导入颜色图

R terra tif import colormap

当使用 terra::rast() 导入 .tif 栅格时,还会导入颜色图。有什么方法可以强制函数不导入颜色图,或者将其设置为 NULL 以使用默认绘图调色板?

您可以看到 table 颜色:

terra::coltab()

示例数据

library(terra)
r <- rast(ncols=3, nrows=2, vals=0:5)
coltb <- data.frame(t(col2rgb(rainbow(6, end=.9), alpha=TRUE)))
coltab(r) <- coltb

正常情况下应该可以做到

coltab(r) <- NULL

但是我看到CRAN版本有一个bug(现在在1.4-5版本中解决了)。要解决这个问题,您可以这样做

coltab(r, 2) <- NULL