Skip to content
Permalink
Browse files
Merge pull request #4308 from nyalldawson/raster_unique
[FEATURE] Allow easy styling of discrete rasters
  • Loading branch information
nyalldawson committed Apr 3, 2017
2 parents 541ecc5 + 3d5a039 commit 97611fed36693d800db67903468d4a7c21798c27
Showing with 6,346 additions and 417 deletions.
  1. +11 −2 doc/api_break.dox
  2. +24 −13 python/core/raster/qgspalettedrasterrenderer.sip
  3. +2 −5 python/core/raster/qgsrasterdataprovider.sip
  4. +0 −3 python/core/raster/qgsrasterhistogram.sip
  5. +6 −25 python/core/raster/qgsrasterinterface.sip
  6. +0 −7 python/core/raster/qgsrasterlayer.sip
  7. +11 −4 src/app/qgsrasterlayerproperties.cpp
  8. +275 −90 src/core/raster/qgspalettedrasterrenderer.cpp
  9. +90 −18 src/core/raster/qgspalettedrasterrenderer.h
  10. +3 −6 src/core/raster/qgsrasterdataprovider.h
  11. +10 −4 src/core/raster/qgsrasterinterface.cpp
  12. +4 −2 src/core/raster/qgsrasterinterface.h
  13. +0 −17 src/core/raster/qgsrasterlayer.cpp
  14. +0 −10 src/core/raster/qgsrasterlayer.h
  15. +3 −32 src/core/raster/qgsrasterrendererregistry.cpp
  16. +651 −79 src/gui/raster/qgspalettedrendererwidget.cpp
  17. +150 −9 src/gui/raster/qgspalettedrendererwidget.h
  18. +17 −13 src/gui/raster/qgsrasterhistogramwidget.cpp
  19. +26 −28 src/providers/gdal/qgsgdalprovider.cpp
  20. +4 −7 src/providers/gdal/qgsgdalprovider.h
  21. +1 −1 src/providers/grass/qgsgrassrasterprovider.cpp
  22. +1 −1 src/providers/grass/qgsgrassrasterprovider.h
  23. +0 −3 src/providers/wcs/qgswcsprovider.h
  24. +0 −3 src/providers/wms/qgswmsprovider.h
  25. +184 −34 src/ui/qgspalettedrendererwidgetbase.ui
  26. +369 −1 tests/src/python/test_qgsrasterlayer.py
  27. BIN tests/testdata/control_images/expected_paletted_renderer/expected_paletted_renderer.png
  28. +4,494 −0 tests/testdata/raster/hub13263.vrt
  29. +10 −0 tests/testdata/raster/test.clr
  30. BIN tests/testdata/raster/unique_1.tif
  31. BIN tests/testdata/raster/with_color_table.tif
@@ -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}
--------------
@@ -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}
@@ -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}
------------------
@@ -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/;
@@ -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:

@@ -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.
@@ -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
@@ -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. */
@@ -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,
@@ -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;

@@ -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
@@ -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.
@@ -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." ) );
Loading

0 comments on commit 97611fe

Please sign in to comment.