Class: QgsRasterAttributeTable¶
- class qgis.core.QgsRasterAttributeTable¶
Bases:
sip.wrapper
The
QgsRasterAttributeTable
class 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.
New in version 3.30:
Methods
Creates a new field from
name
,usage
andtype
and appends it to the fields, optionally reporting any error inerrorMessage
, returnsTrue
on success.Appends a row of
data
to the RAT, optionally reporting any error inerrorMessage
, returnsTrue
on success.Returns the color of the rat
row
or an invalid color if row does not exist or if there is no color definition.Returns the color ramp for an athematic Raster Attribute Table setting the labels in
labels
, optionally generated fromlabelColumn
.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.
Creates and returns a (possibly
None
) raster renderer for the specifiedprovider
andbandNumber
and optionally reclassified byclassificationColumn
, the default value of -1 makes the method guess the classification column based on the field usage.Returns the Raster Attribute Table rows.
Returns a field by name or a default constructed field with empty name if the field is not found.
Returns the Raster Attribute Table fields.
Returns the list of fields matching
fieldUsage
.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.
Try to determine the field usage from its
name
andtype
.Returns
True
if the Raster Attribute Table has color RGBA information.Returns
True
if the Raster Attribute Table has ramp RGBA information.Create RGBA fields and inserts them at
position
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Inserts a new
field
atposition
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Create RGBA minimum and maximum fields and inserts them at
position
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Inserts a row of
rowData
in the Raster Attribute Table atposition
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Returns
True
if the Raster Attribute Table was modified from its last reading from the storage.Returns
True
if the Raster Attribute Table is valid, optionally reporting validity checks results inerrorMessage
.Returns the maximum value of the MinMax (thematic) or Max (athematic) column, returns NaN on errors.
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.Returns the minimum value of the MinMax (thematic) or Min (athematic) column, returns NaN on errors.
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.
Returns the Raster Attribute Table rows as a list of
QgsFeature
.Returns the Raster Attribute Table fields as
QgsFields
.Returns the gradient color ramp of the rat
row
or a default constructed gradient if row does not exist or if there is no color ramp definition.Reads the Raster Attribute Table from a DBF file specified by
path
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Removes the field with
name
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Removes the row in the Raster Attribute Table at
position
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Returns a row of data for the given
matchValue
or and empty row if there is not match.Sets the color for the row at
rowIndex
tocolor
.Sets the Raster Attribute Table dirty state to
isDirty
;Change the usage of the field at index
fieldIndex
tousage
with checks for allowed types.Sets the color ramp for the row at
rowIndex
tocolorMin
andcolorMax
.Sets the
value
forrow
andcolumn
.Returns the Raster Attribute Table type.
Returns information about supported Raster Attribute Table usages.
Returns the translated human readable name of
fieldUsage
.Returns the list of field usages.
Returns the
value
forrow
andcolumn
.Returns the list of field usages for colors and values.
Writes the Raster Attribute Table to a DBF file specified by
path
, optionally reporting any error inerrorMessage
, returnsTrue
on success.- class Field¶
Bases:
sip.wrapper
The Field class represents a Raster Attribute Table field, including its name, usage and type.
New in version 3.30.
QgsRasterAttributeTable.Field(name: str, usage: Qgis.RasterAttributeTableFieldUsage, type: QVariant.Type) Creates a new Field with
name
,type
andusage
.QgsRasterAttributeTable.Field(QgsRasterAttributeTable.Field)
- isColor(self) bool ¶
Returns
True
if the field carries a color component (Red, Green, Blue and optionally Alpha) information.- Return type:
bool
- isRamp(self) bool ¶
Returns
True
if 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¶
Bases:
sip.wrapper
The Field class represents a Raster Attribute Table classification entry for a thematic Raster Attribute Table.
New in version 3.30.
- color¶
- minMaxValues¶
- name¶
- class UsageInformation¶
Bases:
sip.wrapper
The UsageInformation class represents information about a field usage.
New in version 3.30.
- allowedTypes¶
- description¶
- isColor¶
- isRamp¶
- maybeClass¶
- required¶
- supported¶
- unique¶
- appendField(self, name: str, usage: Qgis.RasterAttributeTableFieldUsage, type: QVariant.Type) Tuple[bool, str] ¶
Creates a new field from
name
,usage
andtype
and appends it to the fields, optionally reporting any error inerrorMessage
, returnsTrue
on success.appendField(self, field: QgsRasterAttributeTable.Field) -> Tuple[bool, str] Appends a new
field
, optionally reporting any error inerrorMessage
, returnsTrue
on success.- Parameters:
name (str) –
usage (Qgis.RasterAttributeTableFieldUsage) –
type (QVariant.Type) –
- Return type:
Tuple[bool, str]
- appendRow(self, data: Iterable[Any]) Tuple[bool, str] ¶
Appends a row of
data
to the RAT, optionally reporting any error inerrorMessage
, returnsTrue
on success.- Parameters:
data (Iterable[Any]) –
- Return type:
Tuple[bool, str]
- color(self, row: int) QColor ¶
Returns the color of the rat
row
or 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) Tuple[QgsGradientColorRamp, List[str]] ¶
Returns the color ramp for an athematic Raster Attribute Table setting the labels in
labels
, optionally generated fromlabelColumn
.- Parameters:
labelColumn (int = -1) –
- Return type:
Tuple[
QgsGradientColorRamp
, List[str]]
- createFromRaster(rasterLayer: QgsRasterLayer) Tuple[QgsRasterAttributeTable, int] ¶
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 (QgsRasterLayer) – raster layer
- Return type:
Tuple[
QgsRasterAttributeTable
, int]- Returns:
NULL in case of errors or unsupported renderer.
bandNumber: band number
- createRenderer(self, provider: QgsRasterDataProvider, bandNumber: int, classificationColumn: int = -1) QgsRasterRenderer ¶
Creates and returns a (possibly
None
) raster renderer for the specifiedprovider
andbandNumber
and 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
classificationColumn
for generating the class labels.- Parameters:
provider (QgsRasterDataProvider) –
bandNumber (int) –
classificationColumn (int = -1) –
- Return type:
- data(self) object ¶
Returns the Raster Attribute Table rows.
- Return type:
object
- fieldByName(self, name: str) Tuple[QgsRasterAttributeTable.Field, bool] ¶
Returns a field by name or a default constructed field with empty name if the field is not found.
- Parameters:
name (str) – of the field
- Return type:
Tuple[QgsRasterAttributeTable.Field, bool]
- Returns:
the matching field or a default constructed one.
ok: will be set to
True
if 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 ¶
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
- guessFieldUsage(name: str, type: QVariant.Type) Qgis.RasterAttributeTableFieldUsage ¶
Try to determine the field usage from its
name
andtype
.- Parameters:
name (str) –
type (QVariant.Type) –
- Return type:
- hasColor(self) bool ¶
Returns
True
if the Raster Attribute Table has color RGBA information.See also
See also
See also
See also
See also
- Return type:
bool
- hasRamp(self) bool ¶
Returns
True
if the Raster Attribute Table has ramp RGBA information.See also
See also
See also
See also
- Return type:
bool
- insertColor(self, position: int) Tuple[bool, str] ¶
Create RGBA fields and inserts them at
position
, optionally reporting any error inerrorMessage
, returnsTrue
on success.- Parameters:
position (int) –
- Return type:
Tuple[bool, str]
- insertField(self, position: int, field: QgsRasterAttributeTable.Field) Tuple[bool, str] ¶
Inserts a new
field
atposition
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Note
Out of range position is automatically clamped to a valid value.
insertField(self, position: int, name: str, usage: Qgis.RasterAttributeTableFieldUsage, type: QVariant.Type) -> Tuple[bool, str] Creates a new field from
name
,usage
andtype
and inserts it atposition
, optionally reporting any error inerrorMessage
, returnsTrue
on success.- Parameters:
position (int) –
field (QgsRasterAttributeTable.Field) –
- Return type:
Tuple[bool, str]
- insertRamp(self, position: int) Tuple[bool, str] ¶
Create RGBA minimum and maximum fields and inserts them at
position
, optionally reporting any error inerrorMessage
, returnsTrue
on success.- Parameters:
position (int) –
- Return type:
Tuple[bool, str]
- insertRow(self, position: int, rowData: Iterable[Any]) Tuple[bool, str] ¶
Inserts a row of
rowData
in the Raster Attribute Table atposition
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Note
Out of range position is automatically clamped to a valid value.
- Parameters:
position (int) –
rowData (Iterable[Any]) –
- Return type:
Tuple[bool, str]
- isDirty(self) bool ¶
Returns
True
if the Raster Attribute Table was modified from its last reading from the storage.- Return type:
bool
- isValid(self) Tuple[bool, str] ¶
Returns
True
if the Raster Attribute Table is valid, optionally reporting validity checks results inerrorMessage
.- Return type:
Tuple[bool, str]
- maximumValue(self) float ¶
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 ¶
Returns the minimum value of the MinMax (thematic) or Min (athematic) column, returns NaN on errors.
- Return type:
float
- orderedRows(self) object ¶
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:
object
- qgisFeatures(self) List[QgsFeature] ¶
Returns the Raster Attribute Table rows as a list of
QgsFeature
.- Return type:
List[QgsFeature]
- qgisFields(self) QgsFields ¶
Returns the Raster Attribute Table fields as
QgsFields
.See also
- Return type:
- ramp(self, row: int) QgsGradientColorRamp ¶
Returns the gradient color ramp of the rat
row
or 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) Tuple[bool, str] ¶
Reads the Raster Attribute Table from a DBF file specified by
path
, optionally reporting any error inerrorMessage
, returnsTrue
on success.- Parameters:
path (str) –
- Return type:
Tuple[bool, str]
- removeField(self, name: str) Tuple[bool, str] ¶
Removes the field with
name
, optionally reporting any error inerrorMessage
, returnsTrue
on success.- Parameters:
name (str) –
- Return type:
Tuple[bool, str]
- removeRow(self, position: int = 0) Tuple[bool, str] ¶
Removes the row in the Raster Attribute Table at
position
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Note
position must be a valid position.
- Parameters:
position (int = 0) –
- Return type:
Tuple[bool, str]
- row(self, matchValue: float) List[Any] ¶
Returns a row of data for the given
matchValue
or and empty row if there is not match.- Parameters:
matchValue (float) –
- Return type:
List[Any]
- setColor(self, row: int, color: QColor | Qt.GlobalColor | QGradient) bool ¶
Sets the color for the row at
rowIndex
tocolor
.returns
True
on success.See also
See also
See also
See also
See also
- Parameters:
row (int) –
color (Union[QColor) –
- Return type:
bool
- setDirty(self, isDirty: bool)¶
Sets the Raster Attribute Table dirty state to
isDirty
;- Parameters:
isDirty (bool) –
- setFieldUsage(self, fieldIndex: int, usage: Qgis.RasterAttributeTableFieldUsage) bool ¶
Change the usage of the field at index
fieldIndex
tousage
with checks for allowed types.- Return type:
bool
- Returns:
True
on success.- Parameters:
fieldIndex (int) –
usage (Qgis.RasterAttributeTableFieldUsage) –
- setRamp(self, row: int, colorMin: QColor | Qt.GlobalColor | QGradient, colorMax: QColor | Qt.GlobalColor | QGradient) bool ¶
Sets the color ramp for the row at
rowIndex
tocolorMin
andcolorMax
.returns
True
on success.See also
See also
See also
See also
- Parameters:
row (int) –
colorMin (Union[QColor) –
colorMax (Union[QColor) –
- Return type:
bool
- setValue(self, row: int, column: int, value: Any) bool ¶
Sets the
value
forrow
andcolumn
.- Return type:
bool
- Returns:
True
on success.- Parameters:
row (int) –
column (int) –
value (Any) –
- type(self) Qgis.RasterAttributeTableType ¶
Returns the Raster Attribute Table type.
- Return type:
- usageInformation() Dict[int, QgsRasterAttributeTable.UsageInformation] ¶
Returns information about supported Raster Attribute Table usages.
See also
- Return type:
Dict[int, QgsRasterAttributeTable.UsageInformation]
- usageName(fieldusage: Qgis.RasterAttributeTableFieldUsage) str ¶
Returns the translated human readable name of
fieldUsage
.See also
- Parameters:
fieldusage (Qgis.RasterAttributeTableFieldUsage) –
- Return type:
str
- usages(self) List[int] ¶
Returns the list of field usages.
- Return type:
List[int]
- value(self, row: int, column: int) Any ¶
Returns the
value
forrow
andcolumn
.- Parameters:
row (int) –
column (int) –
- Return type:
Any
- valueAndColorFieldUsages() List[Qgis.RasterAttributeTableFieldUsage] ¶
Returns the list of field usages for colors and values.
- Return type:
- writeToFile(self, path: str) Tuple[bool, str] ¶
Writes the Raster Attribute Table to a DBF file specified by
path
, optionally reporting any error inerrorMessage
, returnsTrue
on success.Note
“.vat.dbf” extension is automatically added to the file path if not present.
- Parameters:
path (str) –
- Return type:
Tuple[bool, str]