# create a color ramp for tree canopy cover percent
# band 5 of an LCP file contains canopy cover
lcp_file <- system.file("extdata/storm_lake.lcp", package="gdalraster")
ds <- new(GDALRaster, lcp_file)
ds$getDescription(band=5)
ds$getMetadata(band=5, domain="")
ds$close()
# create a GTiff file with Byte data type for the canopy cover band
# recode nodata -9999 to 255
tcc_file <- calc(expr = "ifelse(CANCOV == -9999, 255, CANCOV)",
rasterfiles = lcp_file,
bands = 5,
var.names = "CANCOV",
fmt = "GTiff",
dtName = "Byte",
nodata_value = 255,
setRasterNodataValue = TRUE)
ds_tcc <- new(GDALRaster, tcc_file, read_only=FALSE)
# create a color ramp from 0 to 100 and set as the color table
colors <- createColorRamp(start_index = 0,
start_color = c(211, 211, 211),
end_index = 100,
end_color = c(0, 100, 0))
print(colors)
ds_tcc$setColorTable(band=1, col_tbl=colors, palette_interp="RGB")
ds_tcc$setRasterColorInterp(band=1, col_interp="Palette")
# close and re-open the dataset in read_only mode
ds_tcc$open(read_only=TRUE)
plot_raster(ds_tcc, interpolate=FALSE, legend=TRUE,
main="Storm Lake Tree Canopy Cover (%)")
ds_tcc$close()
deleteDataset(tcc_file)
Run the code above in your browser using DataLab