Skip to content

Commit

Permalink
Skip value and color fields on RAT identify
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 8, 2022
1 parent be9b864 commit 41983fa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
12 changes: 9 additions & 3 deletions python/core/auto_generated/raster/qgsrasterattributetable.sip.in
Expand Up @@ -11,7 +11,7 @@
class QgsRasterAttributeTable
{
%Docstring(signature="appended")
The :py:class:`QgsRasterAttributeTable` class represents a raster attribute table (RAT).
The :py:class:`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.
Expand Down Expand Up @@ -294,6 +294,11 @@ Returns the ``value`` for ``row`` and ``column``.
QVariantList row( const double matchValue ) const;
%Docstring
Returns a row of data for the given ``matchValue`` or and empty row if there is not match.
%End

QList<QgsRasterAttributeTable::MinMaxClass> minMaxClasses( const int classificationColumn = -1 ) const;
%Docstring
Returns the classes for a thematic RAT, classified by ``classificationColumn``, the default value of -1 makes the method guess the classification column based on the field usage.
%End

static Qgis::RasterAttributeTableFieldUsage guessFieldUsage( const QString &name, const QVariant::Type type );
Expand All @@ -306,11 +311,12 @@ Try to determine the field usage from its ``name`` and ``type``.
Returns the translated human readable name of ``fieldUsage``.
%End

QList<QgsRasterAttributeTable::MinMaxClass> minMaxClasses( const int classificationColumn = -1 ) const;
static QList<Qgis::RasterAttributeTableFieldUsage> valueAndColorFieldUsages();
%Docstring
Returns the classes for a thematic RAT, classified by ``classificationColumn``, the default value of -1 makes the method guess the classification column based on the field usage.
Returns the list of field usages for colors and values.
%End


};

/************************************************************************
Expand Down
22 changes: 22 additions & 0 deletions src/core/raster/qgsrasterattributetable.cpp
Expand Up @@ -850,6 +850,28 @@ QString QgsRasterAttributeTable::usageName( const Qgis::RasterAttributeTableFiel
return QString();
}

QList<Qgis::RasterAttributeTableFieldUsage> QgsRasterAttributeTable::valueAndColorFieldUsages()
{
static const QList<Qgis::RasterAttributeTableFieldUsage> valueColorUsages {{
Qgis::RasterAttributeTableFieldUsage::MinMax,
Qgis::RasterAttributeTableFieldUsage::Min,
Qgis::RasterAttributeTableFieldUsage::Max,
Qgis::RasterAttributeTableFieldUsage::Red,
Qgis::RasterAttributeTableFieldUsage::Green,
Qgis::RasterAttributeTableFieldUsage::Blue,
Qgis::RasterAttributeTableFieldUsage::Alpha,
Qgis::RasterAttributeTableFieldUsage::RedMin,
Qgis::RasterAttributeTableFieldUsage::GreenMin,
Qgis::RasterAttributeTableFieldUsage::BlueMin,
Qgis::RasterAttributeTableFieldUsage::AlphaMin,
Qgis::RasterAttributeTableFieldUsage::RedMax,
Qgis::RasterAttributeTableFieldUsage::GreenMax,
Qgis::RasterAttributeTableFieldUsage::BlueMax,
Qgis::RasterAttributeTableFieldUsage::AlphaMax,
}};
return valueColorUsages;
}

QList<QgsRasterAttributeTable::MinMaxClass> QgsRasterAttributeTable::minMaxClasses( const int classificationColumn ) const
{
QList<QgsRasterAttributeTable::MinMaxClass> classes;
Expand Down
12 changes: 9 additions & 3 deletions src/core/raster/qgsrasterattributetable.h
Expand Up @@ -29,7 +29,7 @@

/**
* \ingroup core
* \brief The QgsRasterAttributeTable class represents a raster attribute table (RAT).
* \brief 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.
Expand Down Expand Up @@ -282,6 +282,11 @@ class CORE_EXPORT QgsRasterAttributeTable
*/
QVariantList row( const double matchValue ) const;

/**
* Returns the classes for a thematic RAT, classified by \a classificationColumn, the default value of -1 makes the method guess the classification column based on the field usage.
*/
QList<QgsRasterAttributeTable::MinMaxClass> minMaxClasses( const int classificationColumn = -1 ) const;

/**
* Try to determine the field usage from its \a name and \a type.
*/
Expand All @@ -293,9 +298,10 @@ class CORE_EXPORT QgsRasterAttributeTable
static QString usageName( const Qgis::RasterAttributeTableFieldUsage fieldusage );

/**
* Returns the classes for a thematic RAT, classified by \a classificationColumn, the default value of -1 makes the method guess the classification column based on the field usage.
* Returns the list of field usages for colors and values.
*/
QList<QgsRasterAttributeTable::MinMaxClass> minMaxClasses( const int classificationColumn = -1 ) const;
static QList<Qgis::RasterAttributeTableFieldUsage> valueAndColorFieldUsages();


private:

Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -1091,6 +1091,13 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
for ( int colIdx = 0; colIdx < std::min( rat->fields().count( ), row.count() ); ++colIdx )
{
const QgsRasterAttributeTable::Field ratField { rat->fields().at( colIdx ) };

// Skip value and color fields
if ( QgsRasterAttributeTable::valueAndColorFieldUsages().contains( ratField.usage ) )
{
continue;
}

QString ratValue;
switch ( ratField.type )
{
Expand Down

0 comments on commit 41983fa

Please sign in to comment.