Skip to content

Commit

Permalink
Merge pull request #4308 from nyalldawson/raster_unique
Browse files Browse the repository at this point in the history
[FEATURE] Allow easy styling of discrete rasters
  • Loading branch information
nyalldawson committed Apr 3, 2017
2 parents 541ecc5 + 3d5a039 commit 97611fe
Show file tree
Hide file tree
Showing 31 changed files with 6,346 additions and 417 deletions.
13 changes: 11 additions & 2 deletions doc/api_break.dox
Expand Up @@ -1536,7 +1536,10 @@ QgsPaintEffectRegistry {#qgis_api_break_3_0_QgsPaintEffectRegistry}
QgsPalettedRasterRenderer {#qgis_api_break_3_0_QgsPalettedRasterRenderer}
-------------------------

- The rgbArray() method was made private
- The rgbArray() method was removed
- colors() has been removed, use classes() instead.
- The constructor has a different signature and requires a list of classes instead of an array


QgsPalLabeling {#qgis_api_break_3_0_QgsPalLabeling}
--------------
Expand Down Expand Up @@ -1660,14 +1663,16 @@ QgsRasterDataProvider {#qgis_api_break_3_0_QgsRasterDataProvider}
- setUseSrcNoDataValue() has been renamed to setUseSourceNoDataValue()
- srcNoDataValue() has been renamed to sourceNoDataValue()
- draw() has been removed from the interface as it was not used anywhere.

- The progress and progressUpdate signals were removed. Methods which previously emitted these
signals now accept a QgsRasterBlockFeedback argument for reporting progress updates.

QgsRasterInterface {#qgis_api_break_3_0_QgsRasterInterface}
------------------

- srcDataType() has been renamed to sourceDataType()
- srcInput() has been renamed to sourceInput()
- block() has new "feedback" argument.
- The signature of histogram() and bandStatistics() now takes a QgsRasterBlockFeedback pointer argument.


QgsRasterLayer {#qgis_api_break_3_0_QgsRasterLayer}
Expand All @@ -1681,6 +1686,10 @@ constructor variant which accepts a data provider string and loadDefaultStyleFla
- updateProgress() had no effect and was removed.
- CUMULATIVE_CUT_LOWER and CUMULATIVE_CUT_UPPER have been moved to QgsRasterMinMaxOrigin
- the second parameter of setContrastEnhancement() has changed type. It is now QgsRasterMinMaxOrigin::Limits
- showProgress() and onProgress() were removed
- The progressUpdate() signal was removed. Methods which previously emitted these
signals now accept a QgsRasterBlockFeedback argument for reporting progress updates.


QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}
------------------
Expand Down
37 changes: 24 additions & 13 deletions python/core/raster/qgspalettedrasterrenderer.sip
Expand Up @@ -4,8 +4,19 @@ class QgsPalettedRasterRenderer : QgsRasterRenderer
#include "qgspalettedrasterrenderer.h"
%End
public:
/** Renderer owns color array*/
QgsPalettedRasterRenderer( QgsRasterInterface* input, int bandNumber, QColor* colorArray /Array,Transfer/, int nColors /ArraySize/, const QVector<QString>& labels = QVector<QString>() );

struct Class
{

Class( int value, const QColor &color = QColor(), const QString &label = QString() );
int value;
QColor color;
QString label;
};

typedef QList< QgsPalettedRasterRenderer::Class > ClassData;

QgsPalettedRasterRenderer( QgsRasterInterface *input, int bandNumber, const ClassData &classes );
~QgsPalettedRasterRenderer();
virtual QgsPalettedRasterRenderer * clone() const /Factory/;
static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterInterface* input ) /Factory/;
Expand All @@ -14,22 +25,22 @@ class QgsPalettedRasterRenderer : QgsRasterRenderer

/** Returns number of colors*/
int nColors() const;
/** Returns copy of color array (caller takes ownership)*/
QColor* colors() const /Factory/;

/** Return optional category label
* @note added in 2.1 */
ClassData classes() const;
QString label( int idx ) const;
void setLabel( int idx, const QString &label );

/** Set category label
* @note added in 2.1 */
void setLabel( int idx, const QString& label );

void writeXml( QDomDocument& doc, QDomElement& parentElem ) const;
void writeXml( QDomDocument &doc, QDomElement &parentElem ) const;

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems /Out/ ) const;
void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems /Out/ ) const;

QList<int> usesBands() const;
void setSourceColorRamp( QgsColorRamp *ramp /Transfer/ );
QgsColorRamp *sourceColorRamp() const;
static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );
static QgsPalettedRasterRenderer::ClassData classDataFromString( const QString &string );
static QgsPalettedRasterRenderer::ClassData classDataFromFile( const QString &path );
static QString classDataToString( const QgsPalettedRasterRenderer::ClassData &classes );
static QgsPalettedRasterRenderer::ClassData classDataFromRaster( QgsRasterInterface *raster, int bandNumber, QgsColorRamp *ramp = 0 );

private:

Expand Down
7 changes: 2 additions & 5 deletions python/core/raster/qgsrasterdataprovider.sip
Expand Up @@ -150,7 +150,8 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
virtual QString buildPyramids( const QList<QgsRasterPyramid> & pyramidList,
const QString & resamplingMethod = "NEAREST",
QgsRaster::RasterPyramidsFormat format = QgsRaster::PyramidsGTiff,
const QStringList & configOptions = QStringList() );
const QStringList & configOptions = QStringList(),
QgsRasterBlockFeedback *feedback = 0 );

/** \brief Accessor for the raster layers pyramid list.
* @param overviewList used to construct the pyramid list (optional), when empty the list is defined by the provider.
Expand Down Expand Up @@ -317,10 +318,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
virtual int stepHeight() const;

signals:
/** Emit a signal to notify of the progress event.
* Emitted progress is in percents (0.0-100.0) */
void progress( int type, double progress, const QString& message );
void progressUpdate( int progress );

/** Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
* @note added in 2.14
Expand Down
3 changes: 0 additions & 3 deletions python/core/raster/qgsrasterhistogram.sip
Expand Up @@ -24,9 +24,6 @@ class QgsRasterHistogram
/** \brief Whether histogram includes out of range values (in first and last bin) */
bool includeOutOfRange;

/** \brief Store the histogram for a given layer
* @note added in version 3.0
*/
HistogramVector histogramVector;

/** \brief The maximum histogram value. */
Expand Down
31 changes: 6 additions & 25 deletions python/core/raster/qgsrasterinterface.sip
Expand Up @@ -198,39 +198,20 @@ class QgsRasterInterface
*/
virtual QgsRasterBandStats bandStatistics( int bandNo,
int stats = QgsRasterBandStats::All,
const QgsRectangle & extent = QgsRectangle(),
int sampleSize = 0 );

/** \brief Returns true if histogram is available (cached, already calculated). * The parameters are the same as in bandStatistics()
* @return true if statistics are available (ready to use)
*/
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0, QgsRasterBlockFeedback *feedback = 0 );
virtual bool hasStatistics( int bandNo,
int stats = QgsRasterBandStats::All,
const QgsRectangle & extent = QgsRectangle(),
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0 );

/** \brief Get histogram. Histograms are cached in providers.
* @param bandNo The band (number).
* @param binCount Number of bins (intervals,buckets). If 0, the number of bins is decided automatically according to data type, raster size etc.
* @param minimum Minimum value, if NaN, raster minimum value will be used.
* @param maximum Maximum value, if NaN, raster minimum value will be used.
* @param extent Extent used to calc histogram, if empty, whole raster extent is used.
* @param sampleSize Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.
* @param includeOutOfRange include out of range values
* @return Vector of non NULL cell counts for each bin.
* @note binCount, minimum and maximum not optional in python bindings
*/
virtual QgsRasterHistogram histogram( int bandNo,
int binCount,
double minimum,
double maximum,
const QgsRectangle & extent,
int sampleSize,
bool includeOutOfRange );
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = 0,
bool includeOutOfRange = false, QgsRasterBlockFeedback *feedback = 0 );

/** \brief Returns true if histogram is available (cached, already calculated), the parameters are the same as in histogram()
* @note binCount, minimum and maximum not optional in python bindings
*/
virtual bool hasHistogram( int bandNo,
int binCount,
double minimum,
Expand Down
7 changes: 0 additions & 7 deletions python/core/raster/qgsrasterlayer.sip
Expand Up @@ -158,9 +158,6 @@ class QgsRasterLayer : QgsMapLayer
/** \brief Set default contrast enhancement */
void setDefaultContrastEnhancement();

/** \brief [ data provider interface ] A wrapper function to emit a progress update signal */
void showProgress( int value );

/** \brief Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS */
virtual QStringList subLayers() const;

Expand Down Expand Up @@ -188,12 +185,8 @@ class QgsRasterLayer : QgsMapLayer
public slots:
void showStatusMessage( const QString & message );

/** \brief receive progress signal from provider */
void onProgress( int, double, const QString& );

signals:
/** \brief Signal for notifying listeners of long running processes */
void progressUpdate( int value );

/**
* This is emitted whenever data or metadata (e.g. color table, extent) has changed
Expand Down
15 changes: 11 additions & 4 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -1028,7 +1028,9 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
{
QgsRasterDataProvider *provider = mRasterLayer->dataProvider();

connect( provider, &QgsRasterDataProvider::progressUpdate, mPyramidProgress, &QProgressBar::setValue );
std::unique_ptr< QgsRasterBlockFeedback > feedback( new QgsRasterBlockFeedback() );

connect( feedback.get(), &QgsRasterBlockFeedback::progressChanged, mPyramidProgress, &QProgressBar::setValue );
//
// Go through the list marking any files that are selected in the listview
// as true so that we can generate pyramids for them.
Expand Down Expand Up @@ -1056,14 +1058,19 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
QString res = provider->buildPyramids(
myPyramidList,
resamplingMethod,
( QgsRaster::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex() );
( QgsRaster::RasterPyramidsFormat ) cbxPyramidsFormat->currentIndex(),
QStringList(),
feedback.get() );
QApplication::restoreOverrideCursor();
mPyramidProgress->setValue( 0 );
buttonBuildPyramids->setEnabled( false );
disconnect( provider, &QgsRasterDataProvider::progressUpdate, mPyramidProgress, &QProgressBar::setValue );
if ( !res.isNull() )
{
if ( res == QLatin1String( "ERROR_WRITE_ACCESS" ) )
if ( res == QLatin1String( "CANCELED" ) )
{
// user canceled
}
else if ( res == QLatin1String( "ERROR_WRITE_ACCESS" ) )
{
QMessageBox::warning( this, tr( "Write access denied" ),
tr( "Write access denied. Adjust the file permissions and try again." ) );
Expand Down

0 comments on commit 97611fe

Please sign in to comment.