Class: QgsRasterAttributeTable¶
Represents a Raster Attribute Table (RAT).
This class is modeled after the GDAL Raster Attribute Table implementation, it adds some convenience methods to handle data from QGIS and to import/export a Raster Attribute Table from/to a DBF VAT file.
Added in version 3.30.
- class qgis.core.QgsRasterAttributeTable[source]¶
Bases:
object- class Field[source]¶
Bases:
objectThe Field class represents a Raster Attribute Table field, including its name, usage and type.
Added in version 3.30.
QgsRasterAttributeTable.Field(name: Optional[str], usage: Qgis.RasterAttributeTableFieldUsage, type: QMetaType.Type) Creates a new Field with
name,typeandusage.QgsRasterAttributeTable.Field(name: Optional[str], usage: Qgis.RasterAttributeTableFieldUsage, type: QVariant.Type) Creates a new Field with
name,typeandusage.Deprecated since version 3.38: Use the method with a QMetaType.Type argument instead.
QgsRasterAttributeTable.Field(a0: QgsRasterAttributeTable.Field)
- isColor(self) bool[source]¶
Returns
Trueif the field carries a color component (Red, Green, Blue and optionally Alpha) information.- Return type:
bool
- isRamp(self) bool[source]¶
Returns
Trueif the field carries a color ramp component information (RedMin/RedMax, GreenMin/GreenMax, BlueMin/BlueMax and optionally AlphaMin/AlphaMax) information.- Return type:
bool
- name¶
- type¶
- usage¶
- class MinMaxClass[source]¶
Bases:
objectThe Field class represents a Raster Attribute Table classification entry for a thematic Raster Attribute Table.
Added in version 3.30.
- color¶
- name¶
- class UsageInformation[source]¶
Bases:
objectThe UsageInformation class represents information about a field usage.
Added in version 3.30.
- description: str¶
- isColor: bool¶
- isRamp: bool¶
- maybeClass: bool¶
- required: bool¶
- supported: bool¶
- unique: bool¶
- appendField(self, name: str | None, usage: Qgis.RasterAttributeTableFieldUsage, type: QMetaType.Type)[source]¶
Creates a new field from
name,usageandtypeand appends it to the fields, optionally reporting any error inerrorMessage, returnsTrueon success.appendField(self, name: Optional[str], usage: Qgis.RasterAttributeTableFieldUsage, type: QVariant.Type) -> (bool, Optional[str]) Creates a new field from
name,usageandtypeand appends it to the fields, optionally reporting any error inerrorMessage, returnsTrueon success.appendField(self, field: QgsRasterAttributeTable.Field) -> (bool, Optional[str]) Appends a new
field, optionally reporting any error inerrorMessage, returnsTrueon success.- Parameters:
name (Optional[str])
type (QMetaType.Type) -> (bool)
- appendRow(self, data: Iterable[Any])[source]¶
Appends a row of
datato the RAT, optionally reporting any error inerrorMessage, returnsTrueon success.- Parameters:
data (Iterable[Any]) -> (bool)
- color(self, row: int) QColor[source]¶
Returns the color of the rat
rowor an invalid color if row does not exist or if there is no color definition.See also
See also
See also
See also
See also
- Parameters:
row (int)
- Return type:
QColor
- colorRamp(self, labelColumn: int = -1)[source]¶
Returns the color ramp for an athematic Raster Attribute Table setting the labels in
labels, optionally generated fromlabelColumn.- Parameters:
labelColumn (int = -1) -> (QgsGradientColorRamp)
- static createFromRaster(rasterLayer: QgsRasterLayer | None)[source]¶
Creates a new Raster Attribute Table from a raster layer, the renderer must be Paletted or SingleBandPseudoColor, optionally reporting the raster band from which the attribute table was created.
- Parameters:
rasterLayer (Optional[QgsRasterLayer]) -> (Optional[QgsRasterAttributeTable]) – raster layer
- Returns:
Nonein case of errors or unsupported renderer.bandNumber: band number
- createRenderer(self, provider: QgsRasterDataProvider | None, bandNumber: int, classificationColumn: int = -1) QgsRasterRenderer | None[source]¶
Creates and returns a (possibly
None) raster renderer for the specifiedproviderandbandNumberand optionally reclassified byclassificationColumn, the default value of -1 makes the method guess the classification column based on the field usage.Note
athematic attribute tables with color ramps cannot be reclassified, the renderer will still use the
classificationColumnfor generating the class labels.- Parameters:
provider (Optional[QgsRasterDataProvider])
bandNumber (int)
classificationColumn (int = -1)
- Return type:
Optional[QgsRasterRenderer]
- fieldByName(self, name: str | None)[source]¶
Returns a field by name or a default constructed field with empty name if the field is not found.
- Parameters:
name (Optional[str]) -> (QgsRasterAttributeTable.Field) – of the field
- Returns:
the matching field or a default constructed one.
ok:
Trueif the field was found.
- fields(self) List[QgsRasterAttributeTable.Field]¶
Returns the Raster Attribute Table fields.
See also
- Return type:
- fieldsByUsage(self, fieldUsage: Qgis.RasterAttributeTableFieldUsage) List[QgsRasterAttributeTable.Field]¶
Returns the list of fields matching
fieldUsage.- Parameters:
fieldUsage (Qgis.RasterAttributeTableFieldUsage)
- Return type:
- filePath(self) str[source]¶
Returns the (possibly empty) path of the file-based RAT, the path is set when a RAT is read or written from/to a file.
See also
See also
- Return type:
str
- static guessFieldUsage(name: str | None, type: QMetaType.Type) Qgis.RasterAttributeTableFieldUsage[source]¶
Try to determine the field usage from its
nameandtype.guessFieldUsage(name: Optional[str], type: QVariant.Type) -> Qgis.RasterAttributeTableFieldUsage Try to determine the field usage from its
nameandtype.- Parameters:
name (Optional[str])
type (QMetaType.Type)
- Return type:
- hasColor(self) bool[source]¶
Returns
Trueif the Raster Attribute Table has color RGBA information.See also
See also
See also
See also
See also
- Return type:
bool
- hasRamp(self) bool[source]¶
Returns
Trueif the Raster Attribute Table has ramp RGBA information.See also
See also
See also
See also
- Return type:
bool
- insertColor(self, position: int)[source]¶
Create RGBA fields and inserts them at
position, optionally reporting any error inerrorMessage, returnsTrueon success.- Parameters:
position (int) -> (bool)
- insertField(self, position: int, field: QgsRasterAttributeTable.Field)[source]¶
Inserts a new
fieldatposition, optionally reporting any error inerrorMessage, returnsTrueon success.Note
Out of range position is automatically clamped to a valid value.
insertField(self, position: int, name: Optional[str], usage: Qgis.RasterAttributeTableFieldUsage, type: QMetaType.Type) -> (bool, Optional[str]) Creates a new field from
name,usageandtypeand inserts it atposition, optionally reporting any error inerrorMessage, returnsTrueon success.insertField(self, position: int, name: Optional[str], usage: Qgis.RasterAttributeTableFieldUsage, type: QVariant.Type) -> (bool, Optional[str]) Creates a new field from
name,usageandtypeand inserts it atposition, optionally reporting any error inerrorMessage, returnsTrueon success.Deprecated since version 3.38: Use the method with a QMetaType.Type argument instead.
- Parameters:
position (int)
field (QgsRasterAttributeTable.Field) -> (bool)
- insertRamp(self, position: int)[source]¶
Create RGBA minimum and maximum fields and inserts them at
position, optionally reporting any error inerrorMessage, returnsTrueon success.- Parameters:
position (int) -> (bool)
- insertRow(self, position: int, rowData: Iterable[Any])[source]¶
Inserts a row of
rowDatain the Raster Attribute Table atposition, optionally reporting any error inerrorMessage, returnsTrueon success.Note
Out of range position is automatically clamped to a valid value.
- Parameters:
position (int)
rowData (Iterable[Any]) -> (bool)
- isDirty(self) bool[source]¶
Returns
Trueif the Raster Attribute Table was modified from its last reading from the storage.- Return type:
bool
- isValid(self)[source]¶
Returns
Trueif the Raster Attribute Table is valid, optionally reporting validity checks results inerrorMessage.
- maximumValue(self) float[source]¶
Returns the maximum value of the MinMax (thematic) or Max (athematic) column, returns NaN on errors.
- Return type:
float
- minMaxClasses(self, classificationColumn: int = -1) List[QgsRasterAttributeTable.MinMaxClass]¶
Returns the classes for a thematic Raster Attribute Table, classified by
classificationColumn, the default value of -1 makes the method guess the classification column based on the field usage.- Parameters:
classificationColumn (int = -1)
- Return type:
- minimumValue(self) float[source]¶
Returns the minimum value of the MinMax (thematic) or Min (athematic) column, returns NaN on errors.
- Return type:
float
- orderedRows(self) Any¶
Returns the data rows ordered by the value column(s) in ascending order, if the attribute table type is athematic the middle value for each row range is considered for ordering. If the attribute table does not have any value field (and hence is not valid), the current data are returned without any change.
- Return type:
- qgisFeatures(self) List[QgsFeature][source]¶
Returns the Raster Attribute Table rows as a list of
QgsFeature.- Return type:
- qgisFields(self) QgsFields[source]¶
Returns the Raster Attribute Table fields as
QgsFields.See also
- Return type:
- ramp(self, row: int) QgsGradientColorRamp[source]¶
Returns the gradient color ramp of the rat
rowor a default constructed gradient if row does not exist or if there is no color ramp definition.See also
See also
See also
See also
See also
- Parameters:
row (int)
- Return type:
- readFromFile(self, path: str | None)[source]¶
Reads the Raster Attribute Table from a DBF file specified by
path, optionally reporting any error inerrorMessage, returnsTrueon success.- Parameters:
path (Optional[str]) -> (bool)
- removeField(self, name: str | None)[source]¶
Removes the field with
name, optionally reporting any error inerrorMessage, returnsTrueon success.- Parameters:
name (Optional[str]) -> (bool)
- removeRow(self, position: int = 0)[source]¶
Removes the row in the Raster Attribute Table at
position, optionally reporting any error inerrorMessage, returnsTrueon success.Note
position must be a valid position.
- Parameters:
position (int = 0) -> (bool)
- row(self, matchValue: float) List[Any][source]¶
Returns a row of data for the given
matchValueor and empty row if there is not match.
- setColor(self, row: int, color: QColor | Qt.GlobalColor) bool[source]¶
Sets the color for the row at
rowIndextocolor.returnsTrueon success.See also
See also
See also
See also
See also
- Parameters:
row (int)
color (Union[QColor, Qt.GlobalColor])
- Return type:
bool
- setDirty(self, isDirty: bool)[source]¶
Sets the Raster Attribute Table dirty state to
isDirty;- Parameters:
isDirty (bool)
- setFieldUsage(self, fieldIndex: int, usage: Qgis.RasterAttributeTableFieldUsage) bool[source]¶
Change the usage of the field at index
fieldIndextousagewith checks for allowed types.- Return type:
bool
- Returns:
Trueon success.- Parameters:
fieldIndex (int)
- setRamp(self, row: int, colorMin: QColor | Qt.GlobalColor, colorMax: QColor | Qt.GlobalColor) bool[source]¶
Sets the color ramp for the row at
rowIndextocolorMinandcolorMax.returnsTrueon success.See also
See also
See also
See also
- Parameters:
row (int)
colorMin (Union[QColor, Qt.GlobalColor])
colorMax (Union[QColor, Qt.GlobalColor])
- Return type:
bool
- setValue(self, row: int, column: int, value: Any) bool[source]¶
Sets the
valueforrowandcolumn.- Return type:
bool
- Returns:
Trueon success.- Parameters:
row (int)
column (int)
value (Any)
- type(self) Qgis.RasterAttributeTableType[source]¶
Returns the Raster Attribute Table type.
- Return type:
- static usageInformation() Dict[int, QgsRasterAttributeTable.UsageInformation]¶
Returns information about supported Raster Attribute Table usages.
See also
- Return type:
Dict[int, QgsRasterAttributeTable.UsageInformation]
- static usageName(fieldusage: Qgis.RasterAttributeTableFieldUsage) str[source]¶
Returns the translated human readable name of
fieldUsage.See also
- Parameters:
fieldusage (Qgis.RasterAttributeTableFieldUsage)
- Return type:
str
- value(self, row: int, column: int) Any[source]¶
Returns the
valueforrowandcolumn.- Parameters:
row (int)
column (int)
- Return type:
- static valueAndColorFieldUsages() List[Qgis.RasterAttributeTableFieldUsage]¶
Returns the list of field usages for colors and values.
- Return type:
- writeToFile(self, path: str | None)[source]¶
Writes the Raster Attribute Table to a DBF file specified by
path, optionally reporting any error inerrorMessage, returnsTrueon success.Note
“.vat.dbf” extension is automatically added to the file path if not present.
- Parameters:
path (Optional[str]) -> (bool)