Skip to content

Commit

Permalink
Handle other rat types
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 8, 2022
1 parent 62dff87 commit 3479a66
Show file tree
Hide file tree
Showing 21 changed files with 622 additions and 302 deletions.
32 changes: 24 additions & 8 deletions python/core/auto_generated/raster/qgsrasterattributetable.sip.in
Expand Up @@ -70,11 +70,6 @@ Returns ``True`` if the field carries a color ramp component information (RedMin
Qgis::RasterAttributeTableType type() const;
%Docstring
Returns the Raster Attribute Table type.
%End

void setType( const Qgis::RasterAttributeTableType type );
%Docstring
Sets the Raster Attribute Table ``type``
%End

bool hasColor() const;
Expand Down Expand Up @@ -223,6 +218,13 @@ Creates a new field from ``name``, ``usage`` and ``type`` and inserts it at ``po
bool insertColor( int position, QString *errorMessage /Out/ = 0 );
%Docstring
Create RGBA fields and inserts them at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool setFieldUsage( int fieldIndex, const Qgis::RasterAttributeTableFieldUsage usage );
%Docstring
Change the usage of the field at index ``fieldIndex`` to ``usage`` with checks for allowed types.

:return: ``True`` on success.
%End

bool insertRamp( int position, QString *errorMessage /Out/ = 0 );
Expand Down Expand Up @@ -336,15 +338,30 @@ the classification column based on the field usage.
QgsGradientColorRamp colorRamp( QStringList &labels /Out/, const int labelColumn = -1 ) const;
%Docstring
Returns the color ramp for an athematic Raster Attribute Table
returning the ``labels``, optionally generated from ``labelColumn``.
setting the labels in ``labels``, optionally generated from ``labelColumn``.
%End

QgsRasterRenderer *createRenderer( QgsRasterDataProvider *provider, const int bandNumber, const int classificationColumn = -1 ) /Factory/;
%Docstring
Creates and returns a (possibly ``None``) raster renderer for the
specified ``provider`` and ``bandNumber`` and optionally classified
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.

.. note::

athematic attribute tables with color ramps cannot be reclassified,
the renderer will still use the ``classificationColumn`` for
generating the class labels.
%End

QList<QList<QVariant>> orderedRows( ) const;
%Docstring
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.
%End

static Qgis::RasterAttributeTableFieldUsage guessFieldUsage( const QString &name, const QVariant::Type type );
Expand Down Expand Up @@ -389,7 +406,6 @@ Returns information about supported Raster Attribute Table usages.
.. seealso:: :py:func:`usageName`
%End

static QHash<Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation> sUsageInformation;


};
Expand Down
Expand Up @@ -748,7 +748,7 @@ Loads the filesystem-based attribute table for the specified ``bandNumber`` from
.. versionadded:: 3.30
%End

virtual bool writeNativeAttributeTable( QString *errorMessage /Out/ = 0 ) const; //#spellok
virtual bool writeNativeAttributeTable( QString *errorMessage /Out/ = 0 ); //#spellok

virtual bool readNativeAttributeTable( QString *errorMessage /Out/ = 0 );
%Docstring
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -12061,10 +12061,11 @@ void QgisApp::createRasterAttributeTable()
layer->dataProvider()->setAttributeTable( bandNumber, rat );

// Save it
const QString filePath { dlg.filePath() };
if ( ! filePath.isEmpty() )
const bool saveToFile { dlg.saveToFile() };
if ( saveToFile )
{
if ( QMessageBox::question( nullptr, tr( "Confirm Overwrite" ), tr( "Are you sure you want to overwrite the existing attribute table at '%1'?" ).arg( filePath ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
const QString filePath { dlg.filePath() };
if ( QFile::exists( filePath ) && QMessageBox::question( nullptr, tr( "Confirm Overwrite" ), tr( "Are you sure you want to overwrite the existing attribute table at '%1'?" ).arg( filePath ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
{
return;
}
Expand Down

0 comments on commit 3479a66

Please sign in to comment.