Description
When I crop a file with a color table of 256 RGB entries, the new raster have no colortable.
require(raster)
#> Le chargement a nécessité le package : raster
#> Le chargement a nécessité le package : sp
temp <- setwd(tempdir())
on.exit(setwd(temp))
rasterFic <- sprintf("OCS_2017_CESBIO.tif");
print(sprintf("rasterFic: %s", rasterFic))
#> [1] "rasterFic: OCS_2017_CESBIO.tif"
if( !file.exists(rasterFic) ) {
dsn <- "http://osr-cesbio.ups-tlse.fr/echangeswww/TheiaOSO/OCS_2017_CESBIO.tif"
download.file(dsn, rasterFic, mode="wb")
}
img <- brick(rasterFic)
print(sprintf('dataType: %s', dataType(img)))
#> [1] "dataType: INT1U"
head(img@legend@colortable, 255)
#> [1] "#FFFFFF" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [8] "#000000" "#000000" "#000000" "#FF5500" "#FF5500" "#FFFF7F" "#000000"
#> [15] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [22] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [29] "#000000" "#000000" "#000000" "#009C00" "#003200" "#00FF00" "#AAFF00"
#> [36] "#AAFF7F" "#55AA7F" "#000000" "#000000" "#000000" "#000000" "#FF00FF"
#> [43] "#FF55FF" "#FFAAFF" "#00FFFF" "#FF0000" "#FFB802" "#000000" "#000000"
#> [50] "#000000" "#000000" "#0000FF" "#00007F" "#BEBEBE" "#000000" "#000000"
#> [57] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [64] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [71] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [78] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [85] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [92] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [99] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [106] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [113] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [120] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [127] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [134] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [141] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [148] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [155] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [162] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [169] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [176] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [183] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [190] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [197] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [204] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [211] "#000000" "#AAAA00" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [218] "#000000" "#000000" "#000000" "#000000" "#AAAAFF" "#550000" "#AA5500"
#> [225] "#240000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [232] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [239] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [246] "#000000" "#000000" "#000000" "#000000" "#000000" "#000000" "#000000"
#> [253] "#000000" "#000000" "#000000"
e <- extent(367382.583985, 368146.734166484, 6810487.95078925, 6811631.66159055)
img <- crop(img, e)
print(sprintf('dataType: %s', dataType(img)))
#> [1] "dataType: INT2S"
head(img@legend@colortable, 255)
#> logical(0)
Created on 2020-04-03 by the reprex package (v0.3.0)