A GDAL Raster Attribute Table (or RAT) provides attribute information about
pixel values. Raster attribute tables can be used to represent histograms,
color tables, and classification information. Each row in the table applies
to either a single pixel value or a range of values, and might have
attributes such as the histogram count for that value (or range), the color
that pixels of that value (or range) should be displayed, names of classes,
or various other information.
Each column in a raster attribute table has a name, a type (integer,
double, or string), and a GDALRATFieldUsage
. The usage
distinguishes columns with particular understood purposes (such as color,
histogram count, class name), and columns that have other purposes not
understood by the library (long labels, ancillary attributes, etc).
In the general case, each row has a field indicating the minimum pixel
value falling into that category, and a field indicating the maximum pixel
value. In the GDAL API, these are indicated with usage values of GFU_Min
and GFU_Max
. In the common case where each row is a discrete pixel value,
a single column with usage GFU_MinMax
would be used instead.
In R, the table is represented as a data frame with column attribute "GFU"
containing the field usage as a string, e.g., "Max"
, "Min"
or "MinMax"
(case-sensitive).
The full set of possible field usage descriptors is:
GFU attr | GDAL enum | Description |
"Generic" | GFU_Generic | General purpose field |
"PixelCount" | GFU_PixelCount | Histogram pixel count |
"Name" | GFU_Name | Class name |
"Min" | GFU_Min | Class range minimum |
"Max" | GFU_Max | Class range maximum |
"MinMax" | GFU_MinMax | Class value (min=max) |
"Red" | GFU_Red | Red class color (0-255) |
"Green" | GFU_Green | Green class color (0-255) |
"Blue" | GFU_Blue | Blue class color (0-255) |
"Alpha" | GFU_Alpha | Alpha transparency (0-255) |
"RedMin" | GFU_RedMin | Color range red minimum |
"GreenMin" | GFU_GreenMin | Color range green minimum |
"BlueMin" | GFU_BlueMin | Color range blue minimum |
"AlphaMin" | GFU_AlphaMin | Color range alpha minimum |
"RedMax" | GFU_RedMax | Color range red maximum |
"GreenMax" | GFU_GreenMax | Color range green maximum |
"BlueMax" | GFU_BlueMax | Color range blue maximum |
"AlphaMax" | GFU_AlphaMax | Color range alpha maximum |
buildRAT()
assigns GFU "MinMax"
on the column of pixel values (named
"VALUE"
by default) and GFU "PixelCount"
on the column of counts (named
"COUNT"
by default).
If join_df
is given, the additional columns that result from joining will
have GFU assigned automatically based on the column names (ignoring case).
First, the additional column names are checked for containing
the string "name"
(e.g., "classname"
, "TypeName"
, "EVT_NAME"
, etc).
The first matching column (if any) will be assigned a GFU of "Name"
(=GFU_Name
, the field usage descriptor for class names). Next, columns
named "R"
or "Red"
will be assigned GFU "Red"
, columns named "G"
or
"Green"
will be assigned GFU "Green"
, columns named "B"
or "Blue"
will be assigned GFU "Blue"
, and columns named "A"
or "Alpha"
will be
assigned GFU "Alpha"
. Finally, any remaining columns that have not been
assigned a GFU will be assigned "Generic"
.
In a variation of RAT, all the categories are of equal size and regularly
spaced, and the categorization can be determined by knowing the value at
which the categories start and the size of a category. This is called
"Linear Binning" and the information is kept specially on the raster
attribute table as a whole. In R, a RAT that uses linear binning would
have the following attributes set on the data frame:
attribute "Row0Min"
= the numeric lower bound (pixel value) of the first
category, and attribute "BinSize"
= the numeric width of each category (in
pixel value units). buildRAT()
does not create tables with linear binning,
but one could be created manually based on the specifications above, and
applied to a raster with the class method GDALRaster$setDefaultRAT()
.
A raster attribute table is thematic or athematic (continuous). In R, this
is defined by an attribute on the data frame named "GDALRATTableType"
with
value of either "thematic"
or "athematic"
.