public class RasterAttributeTable extends Object implements Cloneable
The RasterAttributeTable class is a binding for the C++ GDALRasterAttributeTable class.
Raster attribute tables can be used to represent histograms, color tables, and classification information.
Each column in a raster attribute table has a name, a type (integer, floating point or string), and a GDALRATFieldUsage. The usage distinguishes columns with particular understood purposes (such as color, histogram count, name) and columns that have specific purposes not understood by the library (long label, suitability_for_growing_wheat, etc).
In the general case each row has a column indicating the minimum pixel values falling into that category, and a column indicating the maximum pixel value. These are indicated with usage values of GFU_Min, and GFU_Max. In other cases where each row is a discrete pixel value, one column of usage GFU_MinMax can be used.
In other cases all the categories are of equal size and regularly spaced and the categorization information can be determine just 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.
RATs are normally associated with Bands and be be queried using the Band.GetDefaultRAT() method.
Constructor and Description |
---|
RasterAttributeTable()
Construct empty table.
|
Modifier and Type | Method and Description |
---|---|
int |
ChangesAreWrittenToFile() |
Object |
clone() |
RasterAttributeTable |
Clone()
Copy Raster Attribute Table.
|
int |
CreateColumn(String name,
int eFieldType,
int eFieldUsage)
Create new column.
|
void |
delete() |
int |
GetColOfUsage(int eUsage)
Fetch column index for given usage.
|
int |
GetColumnCount()
Fetch table column count.
|
boolean |
GetLinearBinning(double[] pdfRow0Min,
double[] pdfBinSize)
Get linear binning information.
|
String |
GetNameOfCol(int iCol)
Fetch name of indicated column.
|
int |
GetRowCount()
Fetch row count.
|
int |
GetRowOfValue(double dfValue)
Get row for pixel value.
|
int |
GetTypeOfCol(int iCol)
Fetch color type.
|
int |
GetUsageOfCol(int iCol)
Fetch column usage value.
|
double |
GetValueAsDouble(int iRow,
int iCol)
Fetch field value as a double.
|
int |
GetValueAsInt(int iRow,
int iCol)
Fetch field value as a integer.
|
String |
GetValueAsString(int iRow,
int iCol)
Fetch field value as a string.
|
int |
SetLinearBinning(double dfRow0Min,
double dfBinSize)
Set linear binning information.
|
void |
SetRowCount(int nCount)
Set row count.
|
void |
SetValueAsDouble(int iRow,
int iCol,
double dfValue)
Set field value from double.
|
void |
SetValueAsInt(int iRow,
int iCol,
int nValue)
Set field value from integer.
|
void |
SetValueAsString(int iRow,
int iCol,
String pszValue)
Set field value from string.
|
public void delete()
public RasterAttributeTable Clone()
Creates a new copy of an existing raster attribute table.
public int GetColumnCount()
public String GetNameOfCol(int iCol)
iCol
- the column index (zero based).public int GetUsageOfCol(int iCol)
iCol
- the column index (zero based).public int GetTypeOfCol(int iCol)
iCol
- the column index (zero based).public int GetColOfUsage(int eUsage)
Returns the index of the first column of the requested usage type, or -1 if no match is found.
eUsage
- usage type to search for.public int GetRowCount()
public String GetValueAsString(int iRow, int iCol)
The value of the requested column in the requested row is returned as a string. If the field is numeric, it is formatted as a string using default rules, so some precision may be lost. except it returns a "const char *" result.
iRow
- row to fetch (zero based).iCol
- column to fetch (zero based).public int GetValueAsInt(int iRow, int iCol)
The value of the requested column in the requested row is returned as an integer. Non-integer fields will be converted to integer with the possibility of data loss.
iRow
- row to fetch (zero based).iCol
- column to fetch (zero based).public double GetValueAsDouble(int iRow, int iCol)
The value of the requested column in the requested row is returned as a double. Non double fields will be converted to double with the possibility of data loss.
iRow
- row to fetch (zero based).iCol
- column to fetch (zero based).public void SetValueAsString(int iRow, int iCol, String pszValue)
The indicated field (column) on the indicated row is set from the passed value. The value will be automatically converted for other field types, with a possible loss of precision.
iRow
- row to fetch (zero based).iCol
- column to fetch (zero based).pszValue
- the value to assign.public void SetValueAsInt(int iRow, int iCol, int nValue)
The indicated field (column) on the indicated row is set from the passed value. The value will be automatically converted for other field types, with a possible loss of precision.
iRow
- row to fetch (zero based).iCol
- column to fetch (zero based).nValue
- the value to assign.public void SetValueAsDouble(int iRow, int iCol, double dfValue)
The indicated field (column) on the indicated row is set from the passed value. The value will be automatically converted for other field types, with a possible loss of precision.
iRow
- row to fetch (zero based).iCol
- column to fetch (zero based).dfValue
- the value to assign.public void SetRowCount(int nCount)
Resizes the table to include the indicated number of rows. Newly created rows will be initialized to their default values - "" for strings, and zero for numeric fields.
nCount
- the new number of rows.public int CreateColumn(String name, int eFieldType, int eFieldUsage)
If the table already has rows, all row values for the new column will be initialized to the default value ("", or zero). The new column is always created as the last column, can will be column (field) "GetColumnCount()-1" after CreateColumn() has completed successfully.
name
- the name of the field to create.eFieldType
- the field type (integer, double or string).eFieldUsage
- the field usage, GFU_Generic if not known.public boolean GetLinearBinning(double[] pdfRow0Min, double[] pdfBinSize)
Returns linear binning information if any is associated with the RAT.
pdfRow0Min
- (out) array of 1 double that will contain the lower bound (pixel value) of the first category.pdfBinSize
- (out) array of 1 double that will contain the width of each category (in pixel value units).public int SetLinearBinning(double dfRow0Min, double dfBinSize)
For RATs with equal sized categories (in pixel value space) that are evenly spaced, this method may be used to associate the linear binning information with the table.
dfRow0Min
- the lower bound (pixel value) of the first category.dfBinSize
- the width of each category (in pixel value units).public int GetRowOfValue(double dfValue)
Given a raw pixel value, the raster attribute table is scanned to determine which row in the table applies to the pixel value. The row index is returned.
dfValue
- the pixel value.public int ChangesAreWrittenToFile()