GDAL
Public Member Functions | Static Public Member Functions | List of all members
GDALDefaultRasterAttributeTable Class Reference

Raster Attribute Table container. More...

#include <gdal_rat.h>

Inheritance diagram for GDALDefaultRasterAttributeTable:
GDALRasterAttributeTable

Public Member Functions

 GDALDefaultRasterAttributeTable ()
 Construct empty table.
 
GDALDefaultRasterAttributeTableClone () const override
 Copy Raster Attribute Table. More...
 
int GetColumnCount () const override
 Fetch table column count. More...
 
const char * GetNameOfCol (int) const override
 Fetch name of indicated column. More...
 
GDALRATFieldUsage GetUsageOfCol (int) const override
 Fetch column usage value. More...
 
GDALRATFieldType GetTypeOfCol (int) const override
 Fetch column type. More...
 
int GetColOfUsage (GDALRATFieldUsage) const override
 Return the index of the column that corresponds to the passed usage. More...
 
int GetRowCount () const override
 Fetch row count. More...
 
const char * GetValueAsString (int iRow, int iField) const override
 Fetch field value as a string. More...
 
int GetValueAsInt (int iRow, int iField) const override
 Fetch field value as a integer. More...
 
double GetValueAsDouble (int iRow, int iField) const override
 Fetch field value as a double. More...
 
void SetValue (int iRow, int iField, const char *pszValue) override
 Set value. More...
 
void SetValue (int iRow, int iField, double dfValue) override
 Set field value from double. More...
 
void SetValue (int iRow, int iField, int nValue) override
 Set field value from integer. More...
 
int ChangesAreWrittenToFile () override
 Determine whether changes made to this RAT are reflected directly in the dataset. More...
 
void SetRowCount (int iCount) override
 Set row count. More...
 
int GetRowOfValue (double dfValue) const override
 Get row for pixel value. More...
 
int GetRowOfValue (int nValue) const override
 Get row for pixel value. More...
 
CPLErr CreateColumn (const char *pszFieldName, GDALRATFieldType eFieldType, GDALRATFieldUsage eFieldUsage) override
 If the table already has rows, all row values for the new column will be initialized to the default value ("", or zero). More...
 
CPLErr SetLinearBinning (double dfRow0Min, double dfBinSize) override
 Set linear binning information. More...
 
int GetLinearBinning (double *pdfRow0Min, double *pdfBinSize) const override
 Get linear binning information. More...
 
CPLErr SetTableType (const GDALRATTableType eInTableType) override
 Set RAT Table Type. More...
 
GDALRATTableType GetTableType () const override
 Get RAT Table Type. More...
 
void RemoveStatistics () override
 Remove Statistics from RAT. More...
 
virtual CPLErr ValuesIO (GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, double *pdfData)
 Read or Write a block of doubles to/from the Attribute Table. More...
 
virtual CPLErr ValuesIO (GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, int *pnData)
 Read or Write a block of integers to/from the Attribute Table. More...
 
virtual CPLErr ValuesIO (GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, char **papszStrList)
 Read or Write a block of strings to/from the Attribute Table. More...
 
virtual CPLXMLNodeSerialize () const
 Serialize. More...
 
virtual void * SerializeJSON () const
 Serialize as a JSON object. More...
 
virtual CPLErr XMLInit (const CPLXMLNode *, const char *)
 Deserialize from XML. More...
 
virtual CPLErr InitializeFromColorTable (const GDALColorTable *)
 Initialize from color table. More...
 
virtual GDALColorTableTranslateToColorTable (int nEntryCount=-1)
 Translate to a color table. More...
 
virtual void DumpReadable (FILE *=nullptr)
 Dump RAT in readable form. More...
 

Static Public Member Functions

static GDALRasterAttributeTableH ToHandle (GDALRasterAttributeTable *poRAT)
 Convert a GDALRasterAttributeTable* to a GDALRasterAttributeTableH. More...
 
static GDALRasterAttributeTableFromHandle (GDALRasterAttributeTableH hRAT)
 Convert a GDALRasterAttributeTableH to a GDALRasterAttributeTable*. More...
 

Detailed Description

Raster Attribute Table container.

Member Function Documentation

◆ ChangesAreWrittenToFile()

int GDALDefaultRasterAttributeTable::ChangesAreWrittenToFile ( )
overridevirtual

Determine whether changes made to this RAT are reflected directly in the dataset.

If this returns FALSE then GDALRasterBand.SetDefaultRAT() should be called. Otherwise this is unnecessary since changes to this object are reflected in the dataset.

This method is the same as the C function GDALRATChangesAreWrittenToFile().

Implements GDALRasterAttributeTable.

◆ Clone()

GDALDefaultRasterAttributeTable * GDALDefaultRasterAttributeTable::Clone ( ) const
overridevirtual

Copy Raster Attribute Table.

Creates a new copy of an existing raster attribute table. The new copy becomes the responsibility of the caller to destroy. May fail (return nullptr) if the attribute table is too large to clone (GetRowCount() * GetColCount() > RAT_MAX_ELEM_FOR_CLONE)

This method is the same as the C function GDALRATClone().

Returns
new copy of the RAT as an in-memory implementation.

Implements GDALRasterAttributeTable.

◆ CreateColumn()

CPLErr GDALDefaultRasterAttributeTable::CreateColumn ( const char *  pszFieldName,
GDALRATFieldType  eFieldType,
GDALRATFieldUsage  eFieldUsage 
)
overridevirtual

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.

This method is the same as the C function GDALRATCreateColumn().

Parameters
pszFieldNamethe name of the field to create.
eFieldTypethe field type (integer, double or string).
eFieldUsagethe field usage, GFU_Generic if not known.
Returns
CE_None on success or CE_Failure if something goes wrong.

Reimplemented from GDALRasterAttributeTable.

◆ DumpReadable()

void GDALRasterAttributeTable::DumpReadable ( FILE *  fp = nullptr)
virtualinherited

Dump RAT in readable form.

Currently the readable form is the XML encoding ... only barely readable.

This method is the same as the C function GDALRATDumpReadable().

Parameters
fpfile to dump to or NULL for stdout.

◆ FromHandle()

static GDALRasterAttributeTable * GDALRasterAttributeTable::FromHandle ( GDALRasterAttributeTableH  hRAT)
inlinestaticinherited

Convert a GDALRasterAttributeTableH to a GDALRasterAttributeTable*.

Since
GDAL 2.3

◆ GetColOfUsage()

int GDALDefaultRasterAttributeTable::GetColOfUsage ( GDALRATFieldUsage  eUsage) const
overridevirtual

Return the index of the column that corresponds to the passed usage.

Parameters
eUsageusage.
Returns
column index, or -1 in case of error.

Implements GDALRasterAttributeTable.

◆ GetColumnCount()

int GDALDefaultRasterAttributeTable::GetColumnCount ( ) const
overridevirtual

Fetch table column count.

This method is the same as the C function GDALRATGetColumnCount().

Returns
the number of columns.

Implements GDALRasterAttributeTable.

◆ GetLinearBinning()

int GDALDefaultRasterAttributeTable::GetLinearBinning ( double *  pdfRow0Min,
double *  pdfBinSize 
) const
overridevirtual

Get linear binning information.

Returns linear binning information if any is associated with the RAT.

This method is the same as the C function GDALRATGetLinearBinning().

Parameters
pdfRow0Min(out) the lower bound (pixel value) of the first category.
pdfBinSize(out) the width of each category (in pixel value units).
Returns
TRUE if linear binning information exists or FALSE if there is none.

Reimplemented from GDALRasterAttributeTable.

◆ GetNameOfCol()

const char * GDALDefaultRasterAttributeTable::GetNameOfCol ( int  iCol) const
overridevirtual

Fetch name of indicated column.

Parameters
iColcolumn index.
Returns
name.

Implements GDALRasterAttributeTable.

◆ GetRowCount()

int GDALDefaultRasterAttributeTable::GetRowCount ( ) const
overridevirtual

Fetch row count.

This method is the same as the C function GDALRATGetRowCount().

Returns
the number of rows.

Implements GDALRasterAttributeTable.

◆ GetRowOfValue() [1/2]

int GDALDefaultRasterAttributeTable::GetRowOfValue ( double  dfValue) const
overridevirtual

Get row for pixel value.

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.

This method is the same as the C function GDALRATGetRowOfValue().

Parameters
dfValuethe pixel value.
Returns
the row index or -1 if no row is appropriate.

Reimplemented from GDALRasterAttributeTable.

◆ GetRowOfValue() [2/2]

int GDALDefaultRasterAttributeTable::GetRowOfValue ( int  nValue) const
overridevirtual

Get row for pixel value.

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.

Int arg for now just converted to double. Perhaps we will handle this in a special way some day?

This method is the same as the C function GDALRATGetRowOfValue().

Parameters
nValuethe pixel value.
Returns
the row index or -1 if no row is appropriate.

Reimplemented from GDALRasterAttributeTable.

◆ GetTableType()

GDALRATTableType GDALDefaultRasterAttributeTable::GetTableType ( ) const
overridevirtual

Get RAT Table Type.

Returns whether table type is thematic or athematic

This method is the same as the C function GDALRATGetTableType().

Since
GDAL 2.4
Returns
GRTT_THEMATIC or GRTT_ATHEMATIC

Implements GDALRasterAttributeTable.

◆ GetTypeOfCol()

GDALRATFieldType GDALDefaultRasterAttributeTable::GetTypeOfCol ( int  iCol) const
overridevirtual

Fetch column type.

Parameters
iColcolumn index.
Returns
type.

Implements GDALRasterAttributeTable.

◆ GetUsageOfCol()

GDALRATFieldUsage GDALDefaultRasterAttributeTable::GetUsageOfCol ( int  iCol) const
overridevirtual

Fetch column usage value.

Parameters
iColcolumn index.
Returns
usage.

Implements GDALRasterAttributeTable.

◆ GetValueAsDouble()

double GDALDefaultRasterAttributeTable::GetValueAsDouble ( int  iRow,
int  iField 
) const
overridevirtual

Fetch field value as a double.

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.

This method is the same as the C function GDALRATGetValueAsDouble().

Parameters
iRowrow to fetch (zero based).
iFieldcolumn to fetch (zero based).
Returns
field value

Implements GDALRasterAttributeTable.

◆ GetValueAsInt()

int GDALDefaultRasterAttributeTable::GetValueAsInt ( int  iRow,
int  iField 
) const
overridevirtual

Fetch field value as a integer.

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.

This method is the same as the C function GDALRATGetValueAsInt().

Parameters
iRowrow to fetch (zero based).
iFieldcolumn to fetch (zero based).
Returns
field value

Implements GDALRasterAttributeTable.

◆ GetValueAsString()

const char * GDALDefaultRasterAttributeTable::GetValueAsString ( int  iRow,
int  iField 
) const
overridevirtual

Fetch field value as a string.

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.

The returned string is temporary and cannot be expected to be available after the next GDAL call.

This method is the same as the C function GDALRATGetValueAsString().

Parameters
iRowrow to fetch (zero based).
iFieldcolumn to fetch (zero based).
Returns
field value.

Implements GDALRasterAttributeTable.

◆ InitializeFromColorTable()

CPLErr GDALRasterAttributeTable::InitializeFromColorTable ( const GDALColorTable poTable)
virtualinherited

Initialize from color table.

This method will setup a whole raster attribute table based on the contents of the passed color table. The Value (GFU_MinMax), Red (GFU_Red), Green (GFU_Green), Blue (GFU_Blue), and Alpha (GFU_Alpha) fields are created, and a row is set for each entry in the color table.

The raster attribute table must be empty before calling InitializeFromColorTable().

The Value fields are set based on the implicit assumption with color tables that entry 0 applies to pixel value 0, 1 to 1, etc.

This method is the same as the C function GDALRATInitializeFromColorTable().

Parameters
poTablethe color table to copy from.
Returns
CE_None on success or CE_Failure if something goes wrong.

◆ RemoveStatistics()

void GDALDefaultRasterAttributeTable::RemoveStatistics ( )
overridevirtual

Remove Statistics from RAT.

Remove statistics (such as histogram) from the RAT. This is important if these have been invalidated, for example by cropping the image.

This method is the same as the C function GDALRATRemoveStatistics().

Since
GDAL 2.4

Implements GDALRasterAttributeTable.

◆ Serialize()

CPLXMLNode * GDALRasterAttributeTable::Serialize ( ) const
virtualinherited

Serialize.

Serialize as a XML tree.

May fail (return nullptr) if the attribute table is too large to serialize (GetRowCount() * GetColCount() > RAT_MAX_ELEM_FOR_CLONE)

Returns
XML tree.

◆ SerializeJSON()

void * GDALRasterAttributeTable::SerializeJSON ( ) const
virtualinherited

Serialize as a JSON object.

Returns
JSON object (of type json_object*)

◆ SetLinearBinning()

CPLErr GDALDefaultRasterAttributeTable::SetLinearBinning ( double  dfRow0MinIn,
double  dfBinSizeIn 
)
overridevirtual

Set linear binning information.

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.

This method is the same as the C function GDALRATSetLinearBinning().

Parameters
dfRow0MinInthe lower bound (pixel value) of the first category.
dfBinSizeInthe width of each category (in pixel value units).
Returns
CE_None on success or CE_Failure on failure.

Reimplemented from GDALRasterAttributeTable.

◆ SetRowCount()

void GDALDefaultRasterAttributeTable::SetRowCount ( int  nNewCount)
overridevirtual

Set row count.

Parameters
nNewCountnew count.

Reimplemented from GDALRasterAttributeTable.

◆ SetTableType()

CPLErr GDALDefaultRasterAttributeTable::SetTableType ( const GDALRATTableType  eInTableType)
overridevirtual

Set RAT Table Type.

Set whether table type is thematic or athematic

This method is the same as the C function GDALRATSetTableType().

Parameters
eInTableTypethe new RAT table type (GRTT_THEMATIC or GRTT_ATHEMATIC)
Since
GDAL 2.4
Returns
CE_None on success or CE_Failure on failure.

Implements GDALRasterAttributeTable.

◆ SetValue() [1/3]

void GDALDefaultRasterAttributeTable::SetValue ( int  iRow,
int  iField,
const char *  pszValue 
)
overridevirtual

Set value.

Parameters
iRowrow index.
iFieldfield index.
pszValuevalue.

Implements GDALRasterAttributeTable.

◆ SetValue() [2/3]

void GDALDefaultRasterAttributeTable::SetValue ( int  iRow,
int  iField,
double  dfValue 
)
overridevirtual

Set field value from double.

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.

This method is the same as the C function GDALRATSetValueAsDouble().

Parameters
iRowrow to fetch (zero based).
iFieldcolumn to fetch (zero based).
dfValuethe value to assign.

Implements GDALRasterAttributeTable.

◆ SetValue() [3/3]

void GDALDefaultRasterAttributeTable::SetValue ( int  iRow,
int  iField,
int  nValue 
)
overridevirtual

Set field value from integer.

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.

This method is the same as the C function GDALRATSetValueAsInteger().

Parameters
iRowrow to fetch (zero based).
iFieldcolumn to fetch (zero based).
nValuethe value to assign.

Implements GDALRasterAttributeTable.

◆ ToHandle()

static GDALRasterAttributeTableH GDALRasterAttributeTable::ToHandle ( GDALRasterAttributeTable poRAT)
inlinestaticinherited

Convert a GDALRasterAttributeTable* to a GDALRasterAttributeTableH.

Since
GDAL 2.3

◆ TranslateToColorTable()

GDALColorTable * GDALRasterAttributeTable::TranslateToColorTable ( int  nEntryCount = -1)
virtualinherited

Translate to a color table.

This method will attempt to create a corresponding GDALColorTable from this raster attribute table.

This method is the same as the C function GDALRATTranslateToColorTable().

Parameters
nEntryCountThe number of entries to produce (0 to nEntryCount-1), or -1 to auto-determine the number of entries.
Returns
the generated color table or NULL on failure.

◆ ValuesIO() [1/3]

CPLErr GDALRasterAttributeTable::ValuesIO ( GDALRWFlag  eRWFlag,
int  iField,
int  iStartRow,
int  iLength,
char **  papszStrList 
)
virtualinherited

Read or Write a block of strings to/from the Attribute Table.

This method is the same as the C function GDALRATValuesIOAsString(). When reading, papszStrList must be already allocated to the correct size. The caller is expected to call CPLFree on each read string.

Parameters
eRWFlagEither GF_Read or GF_Write
iFieldcolumn of the Attribute Table
iStartRowstart row to start reading/writing (zero based)
iLengthnumber of rows to read or write
papszStrListpointer to array of strings to read/write. Should be at least iLength long.
Returns
CE_None or CE_Failure if iStartRow + iLength greater than number of rows in table.

◆ ValuesIO() [2/3]

CPLErr GDALRasterAttributeTable::ValuesIO ( GDALRWFlag  eRWFlag,
int  iField,
int  iStartRow,
int  iLength,
double *  pdfData 
)
virtualinherited

Read or Write a block of doubles to/from the Attribute Table.

This method is the same as the C function GDALRATValuesIOAsDouble().

Parameters
eRWFlagEither GF_Read or GF_Write
iFieldcolumn of the Attribute Table
iStartRowstart row to start reading/writing (zero based)
iLengthnumber of rows to read or write
pdfDatapointer to array of doubles to read/write. Should be at least iLength long.
Returns
CE_None or CE_Failure if iStartRow + iLength greater than number of rows in table.

◆ ValuesIO() [3/3]

CPLErr GDALRasterAttributeTable::ValuesIO ( GDALRWFlag  eRWFlag,
int  iField,
int  iStartRow,
int  iLength,
int *  pnData 
)
virtualinherited

Read or Write a block of integers to/from the Attribute Table.

This method is the same as the C function GDALRATValuesIOAsInteger().

Parameters
eRWFlagEither GF_Read or GF_Write
iFieldcolumn of the Attribute Table
iStartRowstart row to start reading/writing (zero based)
iLengthnumber of rows to read or write
pnDatapointer to array of ints to read/write. Should be at least iLength long.
Returns
CE_None or CE_Failure if iStartRow + iLength greater than number of rows in table.

◆ XMLInit()

CPLErr GDALRasterAttributeTable::XMLInit ( const CPLXMLNode psTree,
const char *   
)
virtualinherited

Deserialize from XML.

Parameters
psTreeXML tree
Returns
error code.

The documentation for this class was generated from the following files: