QGIS API Documentation 3.41.0-Master (45a0abf3bec)
|
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT). More...
#include <qgsrasterattributetable.h>
Classes | |
class | Field |
The Field class represents a Raster Attribute Table field, including its name, usage and type. More... | |
class | MinMaxClass |
The Field class represents a Raster Attribute Table classification entry for a thematic Raster Attribute Table. More... | |
class | UsageInformation |
The UsageInformation class represents information about a field usage. More... | |
Public Member Functions | |
bool | appendField (const QgsRasterAttributeTable::Field &field, QString *errorMessage=nullptr) |
Appends a new field, optionally reporting any error in errorMessage, returns true on success. | |
bool | appendField (const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QMetaType::Type type, QString *errorMessage=nullptr) |
Creates a new field from name, usage and type and appends it to the fields, optionally reporting any error in errorMessage, returns true on success. | |
bool | appendField (const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage=nullptr) |
Creates a new field from name, usage and type and appends it to the fields, optionally reporting any error in errorMessage, returns true on success. | |
bool | appendRow (const QVariantList &data, QString *errorMessage=nullptr) |
Appends a row of data to the RAT, optionally reporting any error in errorMessage, returns true on success. | |
PRIVATE QColor | color (int row) const |
Returns the color of the rat row or an invalid color if row does not exist or if there is no color definition. | |
QgsGradientColorRamp | colorRamp (QStringList &labels, const int labelColumn=-1) const |
Returns the color ramp for an athematic Raster Attribute Table setting the labels in labels, optionally generated from labelColumn. | |
QgsRasterRenderer * | createRenderer (QgsRasterDataProvider *provider, const int bandNumber, const int classificationColumn=-1) |
Creates and returns a (possibly nullptr ) raster renderer for the specified provider and bandNumber and optionally reclassified by classificationColumn, the default value of -1 makes the method guess the classification column based on the field usage. | |
const QList< QList< QVariant > > | data () const |
Returns the Raster Attribute Table rows. | |
const QgsRasterAttributeTable::Field | fieldByName (const QString name, bool *ok=nullptr) const |
Returns a field by name or a default constructed field with empty name if the field is not found. | |
QList< QgsRasterAttributeTable::Field > | fields () const |
Returns the Raster Attribute Table fields. | |
const QList< QgsRasterAttributeTable::Field > | fieldsByUsage (const Qgis::RasterAttributeTableFieldUsage fieldUsage) const |
Returns the list of fields matching fieldUsage. | |
QString | filePath () const |
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. | |
bool | hasColor () const |
Returns true if the Raster Attribute Table has color RGBA information. | |
bool | hasRamp () const |
Returns true if the Raster Attribute Table has ramp RGBA information. | |
bool | insertColor (int position, QString *errorMessage=nullptr) |
Create RGBA fields and inserts them at position, optionally reporting any error in errorMessage, returns true on success. | |
bool | insertField (int position, const QgsRasterAttributeTable::Field &field, QString *errorMessage=nullptr) |
Inserts a new field at position, optionally reporting any error in errorMessage, returns true on success. | |
bool | insertField (int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QMetaType::Type type, QString *errorMessage=nullptr) |
Creates a new field from name, usage and type and inserts it at position, optionally reporting any error in errorMessage, returns true on success. | |
Q_DECL_DEPRECATED bool | insertField (int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage=nullptr) |
Creates a new field from name, usage and type and inserts it at position, optionally reporting any error in errorMessage, returns true on success. | |
bool | insertRamp (int position, QString *errorMessage=nullptr) |
Create RGBA minimum and maximum fields and inserts them at position, optionally reporting any error in errorMessage, returns true on success. | |
bool | insertRow (int position, const QVariantList &rowData, QString *errorMessage=nullptr) |
Inserts a row of rowData in the Raster Attribute Table at position, optionally reporting any error in errorMessage, returns true on success. | |
bool | isDirty () const |
Returns true if the Raster Attribute Table was modified from its last reading from the storage. | |
bool | isValid (QString *errorMessage=nullptr) const |
Returns true if the Raster Attribute Table is valid, optionally reporting validity checks results in errorMessage. | |
double | maximumValue () const |
Returns the maximum value of the MinMax (thematic) or Max (athematic) column, returns NaN on errors. | |
double | minimumValue () const |
Returns the minimum value of the MinMax (thematic) or Min (athematic) column, returns NaN on errors. | |
QList< QgsRasterAttributeTable::MinMaxClass > | minMaxClasses (const int classificationColumn=-1) const |
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. | |
QList< QList< QVariant > > | orderedRows () const |
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. | |
QgsFeatureList | qgisFeatures () const |
Returns the Raster Attribute Table rows as a list of QgsFeature. | |
QgsFields | qgisFields () const |
Returns the Raster Attribute Table fields as QgsFields. | |
QgsGradientColorRamp | ramp (int row) const |
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. | |
bool | readFromFile (const QString &path, QString *errorMessage=nullptr) |
Reads the Raster Attribute Table from a DBF file specified by path, optionally reporting any error in errorMessage, returns true on success. | |
bool | removeField (const QString &name, QString *errorMessage=nullptr) |
Removes the field with name, optionally reporting any error in errorMessage, returns true on success. | |
bool | removeRow (int position=0, QString *errorMessage=nullptr) |
Removes the row in the Raster Attribute Table at position, optionally reporting any error in errorMessage, returns true on success. | |
QVariantList | row (const double matchValue) const |
Returns a row of data for the given matchValue or and empty row if there is not match. | |
bool | setColor (const int row, const QColor &color) |
Sets the color for the row at rowIndex to color. | |
void | setDirty (bool isDirty) |
Sets the Raster Attribute Table dirty state to isDirty;. | |
bool | setFieldUsage (int fieldIndex, const Qgis::RasterAttributeTableFieldUsage usage) |
Change the usage of the field at index fieldIndex to usage with checks for allowed types. | |
bool | setRamp (const int row, const QColor &colorMin, const QColor &colorMax) |
Sets the color ramp for the row at rowIndex to colorMin and colorMax. | |
bool | setValue (const int row, const int column, const QVariant &value) |
Sets the value for row and column. | |
Qgis::RasterAttributeTableType | type () const |
Returns the Raster Attribute Table type. | |
QList< Qgis::RasterAttributeTableFieldUsage > | usages () const |
Returns the list of field usages. | |
QVariant | value (const int row, const int column) const |
Returns the value for row and column. | |
bool | writeToFile (const QString &path, QString *errorMessage=nullptr) |
Writes the Raster Attribute Table to a DBF file specified by path, optionally reporting any error in errorMessage, returns true on success. | |
Static Public Member Functions | |
static QgsRasterAttributeTable * | createFromRaster (QgsRasterLayer *rasterLayer, int *bandNumber=nullptr) |
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. | |
static Qgis::RasterAttributeTableFieldUsage | guessFieldUsage (const QString &name, const QMetaType::Type type) |
Try to determine the field usage from its name and type. | |
static Qgis::RasterAttributeTableFieldUsage | guessFieldUsage (const QString &name, const QVariant::Type type) |
Try to determine the field usage from its name and type. | |
static QHash< Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation > | usageInformation () |
Returns information about supported Raster Attribute Table usages. | |
static QString | usageName (const Qgis::RasterAttributeTableFieldUsage fieldusage) |
Returns the translated human readable name of fieldUsage. | |
static QList< Qgis::RasterAttributeTableFieldUsage > | valueAndColorFieldUsages () |
Returns the list of field usages for colors and values. | |
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.
Definition at line 43 of file qgsrasterattributetable.h.
bool QgsRasterAttributeTable::appendField | ( | const QgsRasterAttributeTable::Field & | field, |
QString * | errorMessage = nullptr |
||
) |
Appends a new field, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 416 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::appendField | ( | const QString & | name, |
const Qgis::RasterAttributeTableFieldUsage | usage, | ||
const QMetaType::Type | type, | ||
QString * | errorMessage = nullptr |
||
) |
Creates a new field from name, usage and type and appends it to the fields, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 406 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::appendField | ( | const QString & | name, |
const Qgis::RasterAttributeTableFieldUsage | usage, | ||
const QVariant::Type | type, | ||
QString * | errorMessage = nullptr |
||
) |
Creates a new field from name, usage and type and appends it to the fields, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 411 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::appendRow | ( | const QVariantList & | data, |
QString * | errorMessage = nullptr |
||
) |
Appends a row of data to the RAT, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 500 of file qgsrasterattributetable.cpp.
QColor QgsRasterAttributeTable::color | ( | int | row | ) | const |
Returns the color of the rat row or an invalid color if row does not exist or if there is no color definition.
Definition at line 155 of file qgsrasterattributetable.cpp.
QgsGradientColorRamp QgsRasterAttributeTable::colorRamp | ( | QStringList & | labels, |
const int | labelColumn = -1 |
||
) | const |
Returns the color ramp for an athematic Raster Attribute Table setting the labels in labels, optionally generated from labelColumn.
Definition at line 1349 of file qgsrasterattributetable.cpp.
|
static |
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.
rasterLayer | raster layer |
bandNumber | band number |
nullptr
in case of errors or unsupported renderer. Definition at line 1061 of file qgsrasterattributetable.cpp.
QgsRasterRenderer * QgsRasterAttributeTable::createRenderer | ( | QgsRasterDataProvider * | provider, |
const int | bandNumber, | ||
const int | classificationColumn = -1 |
||
) |
Creates and returns a (possibly nullptr
) raster renderer for the specified provider and bandNumber and optionally reclassified by classificationColumn, the default value of -1 makes the method guess the classification column based on the field usage.
Definition at line 1504 of file qgsrasterattributetable.cpp.
const QList< QList< QVariant > > QgsRasterAttributeTable::data | ( | ) | const |
Returns the Raster Attribute Table rows.
Definition at line 691 of file qgsrasterattributetable.cpp.
const QgsRasterAttributeTable::Field QgsRasterAttributeTable::fieldByName | ( | const QString | name, |
bool * | ok = nullptr |
||
) | const |
Returns a field by name or a default constructed field with empty name if the field is not found.
name | of the field |
ok | if specified, will be set to true if the field was found. |
Definition at line 696 of file qgsrasterattributetable.cpp.
QList< QgsRasterAttributeTable::Field > QgsRasterAttributeTable::fields | ( | ) | const |
Returns the Raster Attribute Table fields.
Definition at line 202 of file qgsrasterattributetable.cpp.
const QList< QgsRasterAttributeTable::Field > QgsRasterAttributeTable::fieldsByUsage | ( | const Qgis::RasterAttributeTableFieldUsage | fieldUsage | ) | const |
Returns the list of fields matching fieldUsage.
Definition at line 716 of file qgsrasterattributetable.cpp.
PRIVATE QString QgsRasterAttributeTable::filePath | ( | ) | const |
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.
Definition at line 1261 of file qgsrasterattributetable.cpp.
|
static |
Try to determine the field usage from its name and type.
Definition at line 872 of file qgsrasterattributetable.cpp.
|
static |
Try to determine the field usage from its name and type.
Definition at line 988 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::hasColor | ( | ) | const |
Returns true
if the Raster Attribute Table has color RGBA information.
Definition at line 44 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::hasRamp | ( | ) | const |
Returns true
if the Raster Attribute Table has ramp RGBA information.
Definition at line 126 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::insertColor | ( | int | position, |
QString * | errorMessage = nullptr |
||
) |
Create RGBA fields and inserts them at position, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 350 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::insertField | ( | int | position, |
const QgsRasterAttributeTable::Field & | field, | ||
QString * | errorMessage = nullptr |
||
) |
Inserts a new field at position, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 245 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::insertField | ( | int | position, |
const QString & | name, | ||
const Qgis::RasterAttributeTableFieldUsage | usage, | ||
const QMetaType::Type | type, | ||
QString * | errorMessage = nullptr |
||
) |
Creates a new field from name, usage and type and inserts it at position, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 340 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::insertField | ( | int | position, |
const QString & | name, | ||
const Qgis::RasterAttributeTableFieldUsage | usage, | ||
const QVariant::Type | type, | ||
QString * | errorMessage = nullptr |
||
) |
Creates a new field from name, usage and type and inserts it at position, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 345 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::insertRamp | ( | int | position, |
QString * | errorMessage = nullptr |
||
) |
Create RGBA minimum and maximum fields and inserts them at position, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 384 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::insertRow | ( | int | position, |
const QVariantList & | rowData, | ||
QString * | errorMessage = nullptr |
||
) |
Inserts a row of rowData in the Raster Attribute Table at position, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 447 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::isDirty | ( | ) | const |
Returns true
if the Raster Attribute Table was modified from its last reading from the storage.
Definition at line 235 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::isValid | ( | QString * | errorMessage = nullptr | ) | const |
Returns true
if the Raster Attribute Table is valid, optionally reporting validity checks results in errorMessage.
Definition at line 639 of file qgsrasterattributetable.cpp.
double QgsRasterAttributeTable::maximumValue | ( | ) | const |
Returns the maximum value of the MinMax (thematic) or Max (athematic) column, returns NaN on errors.
Definition at line 797 of file qgsrasterattributetable.cpp.
double QgsRasterAttributeTable::minimumValue | ( | ) | const |
Returns the minimum value of the MinMax (thematic) or Min (athematic) column, returns NaN on errors.
Definition at line 762 of file qgsrasterattributetable.cpp.
QList< QgsRasterAttributeTable::MinMaxClass > QgsRasterAttributeTable::minMaxClasses | ( | const int | classificationColumn = -1 | ) | const |
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.
Definition at line 1266 of file qgsrasterattributetable.cpp.
QList< QList< QVariant > > QgsRasterAttributeTable::orderedRows | ( | ) | const |
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.
Definition at line 1589 of file qgsrasterattributetable.cpp.
QgsFeatureList QgsRasterAttributeTable::qgisFeatures | ( | ) | const |
Returns the Raster Attribute Table rows as a list of QgsFeature.
Definition at line 218 of file qgsrasterattributetable.cpp.
QgsFields QgsRasterAttributeTable::qgisFields | ( | ) | const |
Returns the Raster Attribute Table fields as QgsFields.
Definition at line 207 of file qgsrasterattributetable.cpp.
QgsGradientColorRamp QgsRasterAttributeTable::ramp | ( | int | row | ) | const |
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.
Definition at line 177 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::readFromFile | ( | const QString & | path, |
QString * | errorMessage = nullptr |
||
) |
Reads the Raster Attribute Table from a DBF file specified by path, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 561 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::removeField | ( | const QString & | name, |
QString * | errorMessage = nullptr |
||
) |
Removes the field with name, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 421 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::removeRow | ( | int | position = 0 , |
QString * | errorMessage = nullptr |
||
) |
Removes the row in the Raster Attribute Table at position, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 485 of file qgsrasterattributetable.cpp.
QVariantList QgsRasterAttributeTable::row | ( | const double | matchValue | ) | const |
Returns a row of data for the given matchValue or and empty row if there is not match.
Definition at line 832 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::setColor | ( | const int | row, |
const QColor & | color | ||
) |
Sets the color for the row at rowIndex to color.
returns true
on success.
Definition at line 50 of file qgsrasterattributetable.cpp.
void QgsRasterAttributeTable::setDirty | ( | bool | isDirty | ) |
Sets the Raster Attribute Table dirty state to isDirty;.
Definition at line 240 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::setFieldUsage | ( | int | fieldIndex, |
const Qgis::RasterAttributeTableFieldUsage | usage | ||
) |
Change the usage of the field at index fieldIndex to usage with checks for allowed types.
true
on success. Definition at line 365 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::setRamp | ( | const int | row, |
const QColor & | colorMin, | ||
const QColor & | colorMax | ||
) |
Sets the color ramp for the row at rowIndex to colorMin and colorMax.
returns true
on success.
Definition at line 82 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::setValue | ( | const int | row, |
const int | column, | ||
const QVariant & | value | ||
) |
Sets the value for row and column.
true
on success. Definition at line 729 of file qgsrasterattributetable.cpp.
Qgis::RasterAttributeTableType QgsRasterAttributeTable::type | ( | ) | const |
Returns the Raster Attribute Table type.
Definition at line 38 of file qgsrasterattributetable.cpp.
|
static |
Returns information about supported Raster Attribute Table usages.
Definition at line 1213 of file qgsrasterattributetable.cpp.
|
static |
Returns the translated human readable name of fieldUsage.
Definition at line 993 of file qgsrasterattributetable.cpp.
QList< Qgis::RasterAttributeTableFieldUsage > QgsRasterAttributeTable::usages | ( | ) | const |
Returns the list of field usages.
Definition at line 133 of file qgsrasterattributetable.cpp.
QVariant QgsRasterAttributeTable::value | ( | const int | row, |
const int | column | ||
) | const |
Returns the value for row and column.
Definition at line 753 of file qgsrasterattributetable.cpp.
|
static |
Returns the list of field usages for colors and values.
Definition at line 1039 of file qgsrasterattributetable.cpp.
bool QgsRasterAttributeTable::writeToFile | ( | const QString & | path, |
QString * | errorMessage = nullptr |
||
) |
Writes the Raster Attribute Table to a DBF file specified by path, optionally reporting any error in errorMessage, returns true
on success.
Definition at line 505 of file qgsrasterattributetable.cpp.