QGIS API Documentation 3.37.0-Master (684a802617f)
Loading...
Searching...
No Matches
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<QMetaType::Type> allowedTypes;
82 };
83
89 class CORE_EXPORT Field
90 {
91
92 public:
93
97 Field( const QString &name, const Qgis::RasterAttributeTableFieldUsage &usage, const QMetaType::Type type ): name( name ), usage( usage ), type( type ) {}
98
103 Q_DECL_DEPRECATED Field( const QString &name, const Qgis::RasterAttributeTableFieldUsage &usage, const QVariant::Type type ) SIP_DEPRECATED: Field( name, usage, QgsVariantUtils::variantTypeToMetaType( type ) ) {}
104
108 bool isColor( ) const;
109
113 bool isRamp( ) const;
114
115 QString name;
117 QMetaType::Type type;
118 };
119
125 class CORE_EXPORT MinMaxClass
126 {
127 public:
128 QString name;
129
131 QVector< double > minMaxValues;
132 QColor color;
133 };
134
139
148 bool hasColor() const;
149
159 bool setColor( const int row, const QColor &color );
160
168 bool hasRamp() const;
169
178 bool setRamp( const int row, const QColor &colorMin, const QColor &colorMax );
179
183 QList<Qgis::RasterAttributeTableFieldUsage> usages( ) const SIP_SKIP;
184
186
190 QList<int> intUsages( ) const SIP_PYNAME( usages );
191
193
202 QColor color( int row ) const;
203
212 QgsGradientColorRamp ramp( int row ) const;
213
218 QList<QgsRasterAttributeTable::Field> fields() const;
219
224 QgsFields qgisFields() const;
225
229 QgsFeatureList qgisFeatures( ) const;
230
234 bool isDirty() const;
235
239 void setDirty( bool isDirty );
240
244 bool isValid( QString *errorMessage SIP_OUT = nullptr ) const;
245
250 bool insertField( int position, const QgsRasterAttributeTable::Field &field, QString *errorMessage SIP_OUT = nullptr );
251
255 bool insertField( int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QMetaType::Type type, QString *errorMessage SIP_OUT = nullptr );
256
261 Q_DECL_DEPRECATED bool insertField( int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage SIP_OUT = nullptr ) SIP_DEPRECATED;
262
266 bool insertColor( int position, QString *errorMessage SIP_OUT = nullptr );
267
272 bool setFieldUsage( int fieldIndex, const Qgis::RasterAttributeTableFieldUsage usage );
273
277 bool insertRamp( int position, QString *errorMessage SIP_OUT = nullptr );
278
282 bool appendField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QMetaType::Type type, QString *errorMessage SIP_OUT = nullptr );
283
287 bool appendField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage SIP_OUT = nullptr );
288
292 bool appendField( const QgsRasterAttributeTable::Field &field, QString *errorMessage SIP_OUT = nullptr );
293
297 bool removeField( const QString &name, QString *errorMessage SIP_OUT = nullptr );
298
303 bool insertRow( int position, const QVariantList &rowData, QString *errorMessage SIP_OUT = nullptr );
304
309 bool removeRow( int position = 0, QString *errorMessage SIP_OUT = nullptr );
310
314 bool appendRow( const QVariantList &data, QString *errorMessage SIP_OUT = nullptr );
315
320 bool writeToFile( const QString &path, QString *errorMessage SIP_OUT = nullptr );
321
325 bool readFromFile( const QString &path, QString *errorMessage SIP_OUT = nullptr );
326
330 const QList<QList<QVariant>> data() const;
331
338 const QgsRasterAttributeTable::Field fieldByName( const QString name, bool *ok SIP_OUT = nullptr ) const;
339
343 const QList<QgsRasterAttributeTable::Field> fieldsByUsage( const Qgis::RasterAttributeTableFieldUsage fieldUsage ) const;
344
349 bool setValue( const int row, const int column, const QVariant &value );
350
354 QVariant value( const int row, const int column ) const;
355
359 double minimumValue( ) const;
360
364 double maximumValue( ) const;
365
370 QVariantList row( const double matchValue ) const;
371
377 QList<QgsRasterAttributeTable::MinMaxClass> minMaxClasses( const int classificationColumn = -1 ) const;
378
383 QgsGradientColorRamp colorRamp( QStringList &labels SIP_OUT, const int labelColumn = -1 ) const;
384
395 QgsRasterRenderer *createRenderer( QgsRasterDataProvider *provider, const int bandNumber, const int classificationColumn = -1 ) SIP_FACTORY;
396
404 QList<QList<QVariant>> orderedRows( ) const;
405
409 static Qgis::RasterAttributeTableFieldUsage guessFieldUsage( const QString &name, const QMetaType::Type type );
410
414 static Qgis::RasterAttributeTableFieldUsage guessFieldUsage( const QString &name, const QVariant::Type type );
415
422 QString filePath() const;
423
428 static QString usageName( const Qgis::RasterAttributeTableFieldUsage fieldusage );
429
433 static QList<Qgis::RasterAttributeTableFieldUsage> valueAndColorFieldUsages();
434
441 static QgsRasterAttributeTable *createFromRaster( QgsRasterLayer *rasterLayer, int *bandNumber SIP_OUT = nullptr ) SIP_FACTORY;
442
447 static QHash<Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation> usageInformation( ) SIP_SKIP;
448
450
455 static QHash<int, QgsRasterAttributeTable::UsageInformation> usageInformationInt( ) SIP_PYNAME( usageInformation );
456
457 static QHash<Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation> sUsageInformation SIP_SKIP;
458
460
461 private:
462
463 Qgis::RasterAttributeTableType mType = Qgis::RasterAttributeTableType::Thematic;
464 QList<Field> mFields;
465 QList<QVariantList> mData;
466 bool mIsDirty;
467 QString mFilePath;
468
469 // Set type from fields.
470 void setType( );
471
472};
473
474#endif // QGSRASTERATTRIBUTETABLE_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
RasterAttributeTableType
The RasterAttributeTableType enum represents the type of RAT.
Definition qgis.h:1283
RasterAttributeTableFieldUsage
The RasterAttributeTableFieldUsage enum represents the usage of a Raster Attribute Table field.
Definition qgis.h:1254
Container of fields for a vector layer.
Definition qgsfields.h:46
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.
Q_DECL_DEPRECATED Field(const QString &name, const Qgis::RasterAttributeTableFieldUsage &usage, const QVariant::Type type)
Creates a new Field with name, type and usage.
Qgis::RasterAttributeTableFieldUsage usage
Field(const QString &name, const Qgis::RasterAttributeTableFieldUsage &usage, const QMetaType::Type type)
Creates a new Field with name, type and 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< QMetaType::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.
static QMetaType::Type variantTypeToMetaType(QVariant::Type variantType)
Converts a QVariant::Type to a QMetaType::Type.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#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