addColorTable: Create a virtual raster file with a color table

View source: R/addColorTable.R

addColorTableR Documentation

Create a virtual raster file with a color table

Description

addColorTable() creates a virtual raster file (.vrt) alongside a byte encoded raster that references the raster and includes the color table. The .vrt is a GDAL file that describes a dataset to be composed of other datasets. it can be read directly by some GIS software or can be passed to makeNiceTif() or GDAL translate directly to combine the data and color table in a single TIFF file.

Usage

addColorTable(x, table)

Arguments

x

The path to raster file containing categorical data, must be a single band byte encoded file.

table

a data.frame with two or three columns:

value

(numeric) raster cell values.

color

(character) the color to assign each value. Typically a hexadecimal color in #rrggbb format. It will be passed to grDevices::col2rgb() so any format that function accepts will work.

category

(optional, character) text describing the class. If present this will be used in the map legend.

Details

Note: The color table will include all values between 0 and the maximum value in the raster. If your raster doesn't use some values in the sequence the missing values will appear in the key with white as the associated color and an empty string as the category label. Generally it works best if you recode your raster to have values 0 to N-1, or 1 to N.

The suggested workflow is:

  1. addColorTable() create .vrt alongside existing TIFF

  2. makeNiceTif() called directly on the .vrt to create a TIFF with embedded color table, tiled data, stats, and overviews.

  3. optionally call addVat() to build a value attribute table.

Value

addColorTable creates a .vrt file but returns nothing.


ethanplunkett/rasterPrep documentation built on Sept. 17, 2024, 1:05 p.m.