QGIS API Documentation 3.29.0-Master (19d7edcfed)
qgsrasterattributetable.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterattributetable.h - QgsRasterAttributeTable
3
4 ---------------------
5 begin : 3.12.2021
6 copyright : (C) 2021 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSRASTERATTRIBUTETABLE_H
17#define QGSRASTERATTRIBUTETABLE_H
18
19#include "qgsfields.h"
20#include "qgsfeature.h"
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgis.h"
24#include "qgscolorrampimpl.h"
25
26#include <QObject>
27#include <QLinearGradient>
28#include <QCoreApplication>
29
30class QgsRasterLayer;
33
43class CORE_EXPORT QgsRasterAttributeTable
44{
45
46 Q_DECLARE_TR_FUNCTIONS( QgsRasterAttributeTable )
47
48 public:
49
55 class CORE_EXPORT UsageInformation
56 {
57 public:
58
60 QString description;
61
63 bool unique = false;
64
66 bool required = false;
67
69 bool isColor = false;
70
72 bool isRamp = false;
73
75 bool supported = false;
76
78 bool maybeClass = false;
79
81 QList<QVariant::Type> allowedTypes;
82 };
83
89 class CORE_EXPORT Field
90 {
91
92 public:
93
97 Field( const QString &name, const Qgis::RasterAttributeTableFieldUsage &usage, const QVariant::Type type ): name( name ), usage( usage ), type( type ) {}
98
102 bool isColor( ) const;
103
107 bool isRamp( ) const;
108
109 QString name;
111 QVariant::Type type;
112 };
113
119 class CORE_EXPORT MinMaxClass
120 {
121 public:
122 QString name;
123
125 QVector< double > minMaxValues;
126 QColor color;
127 };
128
133
142 bool hasColor() const;
143
153 bool setColor( const int row, const QColor &color );
154
162 bool hasRamp() const;
163
172 bool setRamp( const int row, const QColor &colorMin, const QColor &colorMax );
173
177 QList<Qgis::RasterAttributeTableFieldUsage> usages( ) const SIP_SKIP;
178
180
184 QList<int> intUsages( ) const SIP_PYNAME( usages );
185
187
196 QColor color( int row ) const;
197
206 QgsGradientColorRamp ramp( int row ) const;
207
212 QList<QgsRasterAttributeTable::Field> fields() const;
213
218 QgsFields qgisFields() const;
219
223 QgsFeatureList qgisFeatures( ) const;
224
228 bool isDirty() const;
229
233 void setDirty( bool isDirty );
234
238 bool isValid( QString *errorMessage SIP_OUT = nullptr ) const;
239
244 bool insertField( int position, const QgsRasterAttributeTable::Field &field, QString *errorMessage SIP_OUT = nullptr );
245
249 bool insertField( int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage SIP_OUT = nullptr );
250
254 bool insertColor( int position, QString *errorMessage SIP_OUT = nullptr );
255
260 bool setFieldUsage( int fieldIndex, const Qgis::RasterAttributeTableFieldUsage usage );
261
265 bool insertRamp( int position, QString *errorMessage SIP_OUT = nullptr );
266
270 bool appendField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage SIP_OUT = nullptr );
271
275 bool appendField( const QgsRasterAttributeTable::Field &field, QString *errorMessage SIP_OUT = nullptr );
276
280 bool removeField( const QString &name, QString *errorMessage SIP_OUT = nullptr );
281
286 bool insertRow( int position, const QVariantList &rowData, QString *errorMessage SIP_OUT = nullptr );
287
292 bool removeRow( int position = 0, QString *errorMessage SIP_OUT = nullptr );
293
297 bool appendRow( const QVariantList &data, QString *errorMessage SIP_OUT = nullptr );
298
303 bool writeToFile( const QString &path, QString *errorMessage SIP_OUT = nullptr );
304
308 bool readFromFile( const QString &path, QString *errorMessage SIP_OUT = nullptr );
309
313 const QList<QList<QVariant>> data() const;
314
321 const QgsRasterAttributeTable::Field fieldByName( const QString name, bool *ok SIP_OUT = nullptr ) const;
322
326 const QList<QgsRasterAttributeTable::Field> fieldsByUsage( const Qgis::RasterAttributeTableFieldUsage fieldUsage ) const;
327
332 bool setValue( const int row, const int column, const QVariant &value );
333
337 QVariant value( const int row, const int column ) const;
338
342 double minimumValue( ) const;
343
347 double maximumValue( ) const;
348
353 QVariantList row( const double matchValue ) const;
354
360 QList<QgsRasterAttributeTable::MinMaxClass> minMaxClasses( const int classificationColumn = -1 ) const;
361
366 QgsGradientColorRamp colorRamp( QStringList &labels SIP_OUT, const int labelColumn = -1 ) const;
367
378 QgsRasterRenderer *createRenderer( QgsRasterDataProvider *provider, const int bandNumber, const int classificationColumn = -1 ) SIP_FACTORY;
379
387 QList<QList<QVariant>> orderedRows( ) const;
388
392 static Qgis::RasterAttributeTableFieldUsage guessFieldUsage( const QString &name, const QVariant::Type type );
393
400 QString filePath() const;
401
406 static QString usageName( const Qgis::RasterAttributeTableFieldUsage fieldusage );
407
411 static QList<Qgis::RasterAttributeTableFieldUsage> valueAndColorFieldUsages();
412
419 static QgsRasterAttributeTable *createFromRaster( QgsRasterLayer *rasterLayer, int *bandNumber SIP_OUT = nullptr ) SIP_FACTORY;
420
425 static QHash<Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation> usageInformation( ) SIP_SKIP;
426
428
433 static QHash<int, QgsRasterAttributeTable::UsageInformation> usageInformationInt( ) SIP_PYNAME( usageInformation );
434
435 static QHash<Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation> sUsageInformation SIP_SKIP;
436
438
439 private:
440
441 Qgis::RasterAttributeTableType mType = Qgis::RasterAttributeTableType::Thematic;
442 QList<Field> mFields;
443 QList<QVariantList> mData;
444 bool mIsDirty;
445 QString mFilePath;
446
447 // Set type from fields.
448 void setType( );
449
450};
451
452#endif // QGSRASTERATTRIBUTETABLE_H
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:72
RasterAttributeTableType
The RasterAttributeTableType enum represents the type of RAT.
Definition: qgis.h:815
RasterAttributeTableFieldUsage
Flags which control behavior of raster renderers.
Definition: qgis.h:786
Container of fields for a vector layer.
Definition: qgsfields.h:45
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
The Field class represents a Raster Attribute Table field, including its name, usage and type.
Field(const QString &name, const Qgis::RasterAttributeTableFieldUsage &usage, const QVariant::Type type)
Creates a new Field with name, type and usage.
Qgis::RasterAttributeTableFieldUsage usage
The Field class represents a Raster Attribute Table classification entry for a thematic Raster Attrib...
QVector< double > minMaxValues
List of values for the class.
The UsageInformation class represents information about a field usage.
QList< QVariant::Type > allowedTypes
Usage allowed types.
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT).
Base class for raster data providers.
Represents a raster layer.
Raster renderer pipe that applies colors to a raster.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:920
const QgsField & field
Definition: qgsfield.h:463