Skip to content

Commit

Permalink
Merge pull request #3871 from rouault/auto_stretch
Browse files Browse the repository at this point in the history
[FEATURE] Implement raster auto-stretching when updating canvas
  • Loading branch information
rouault committed Dec 16, 2016
2 parents 5dc39e0 + 532eb58 commit 792873a
Show file tree
Hide file tree
Showing 49 changed files with 1,926 additions and 889 deletions.
21 changes: 20 additions & 1 deletion doc/api_break.dox
Expand Up @@ -1313,6 +1313,14 @@ QgsProject {#qgis_api_break_3_0_QgsProject}
- clearProperties() was removed. Use clear() instead.


QgsRaster {#qgis_api_break_3_0_QgsRaster}
---------

- QgsRaster::ContrastEnhancementLimits has been removed, use QgsRasterMinMaxOrigin::Limits
- QgsRaster::contrastEnhancementLimitsAsString() has been removed, use QgsRasterMinMaxOrigin::limitsString()
- QgsRaster::contrastEnhancementLimitsFromString() has been removed, use QgsRasterMinMaxOrigin::limitsFromString()


QgsRasterCalcNode {#qgis_api_break_3_0_QgsRasterCalcNode}
-----------------

Expand Down Expand Up @@ -1343,13 +1351,18 @@ QgsRasterLayer {#qgis_api_break_3_0_QgsRasterLayer}
- setDrawingStyle() was removed. Use setRendererForDrawingStyle() or setRenderer() instead.
- previewAsPixmap() was removed. Use previewAsImage() instead.
- 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

QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}
------------------

- extentSize() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should be used instead of a null pointer if no transformation is required.

QgsRasterRenderer
-----------------

- MinMaxOrigin enum, minMaxOriginName(), minMaxOriginLabel(), minMaxOriginFromName() removed. Use minMaxOrigin() instead

QgsRelation {#qgis_api_break_3_0_QgsRelation}
-----------
Expand Down Expand Up @@ -1430,6 +1443,12 @@ QgsSimpleMarkerSymbolLayerWidget {#qgis_api_break_3_0_QgsSimpleMarkerSymb
- setName() was removed.


QgsSingleBandPseudoColorRenderer {#qgis_api_break_3_0_QgsSingleBandPseudoColorRenderer}
--------------------------------

- classificationMinMaxOrigin() and setClassificationMinMaxOrigin() removed. Use minMaxOrigin() and setMinMaxOrigin()


QgsSingleSymbolRendererWidget {#qgis_api_break_3_0_QgsSingleSymbolRendererWidget}
-----------------------------

Expand Down
1 change: 1 addition & 0 deletions python/core/core.sip
Expand Up @@ -274,6 +274,7 @@
%Include raster/qgsrasterinterface.sip
%Include raster/qgsrasteriterator.sip
%Include raster/qgsrasterlayer.sip
%Include raster/qgsrasterminmaxorigin.sip
%Include raster/qgsrasternuller.sip
%Include raster/qgsrasterpipe.sip
%Include raster/qgsrasterprojector.sip
Expand Down
11 changes: 0 additions & 11 deletions python/core/raster/qgsraster.sip
Expand Up @@ -62,14 +62,6 @@ class QgsRaster
PyramidsErdas,
};

/** \brief Contrast enhancement limits */
enum ContrastEnhancementLimits
{
ContrastEnhancementNone,
ContrastEnhancementMinMax,
ContrastEnhancementStdDev,
ContrastEnhancementCumulativeCut
};

/** \brief This enumerator describes the different kinds of drawing we can do */
enum DrawingStyle
Expand All @@ -87,9 +79,6 @@ class QgsRaster
SingleBandColorDataStyle // ARGB values rendered directly
};

static QString contrastEnhancementLimitsAsString( QgsRaster::ContrastEnhancementLimits theLimits );
static ContrastEnhancementLimits contrastEnhancementLimitsFromString( const QString& theLimits );

/** Get value representable by given data type.
* Supported are numerical types Byte, UInt16, Int16, UInt32, Int32, Float32, Float64.
* @param value
Expand Down
7 changes: 1 addition & 6 deletions python/core/raster/qgsrasterlayer.sip
Expand Up @@ -10,11 +10,6 @@ class QgsRasterLayer : QgsMapLayer
%End

public:
/** \brief Default cumulative cut lower limit */
static const double CUMULATIVE_CUT_LOWER;

/** \brief Default cumulative cut upper limit */
static const double CUMULATIVE_CUT_UPPER;

/** \brief Default sample size (number of pixels) for estimated statistics/histogram calculation */
static const double SAMPLE_SIZE;
Expand Down Expand Up @@ -165,7 +160,7 @@ class QgsRasterLayer : QgsMapLayer


void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
QgsRaster::ContrastEnhancementLimits theLimits = QgsRaster::ContrastEnhancementMinMax,
QgsRasterMinMaxOrigin::Limits theLimits = QgsRasterMinMaxOrigin::MinMax,
const QgsRectangle& theExtent = QgsRectangle(),
int theSampleSize = QgsRasterLayer::SAMPLE_SIZE,
bool theGenerateLookupTableFlag = true );
Expand Down
127 changes: 127 additions & 0 deletions python/core/raster/qgsrasterminmaxorigin.sip
@@ -0,0 +1,127 @@
/** \class QgsRasterMinMaxOrigin
* This class describes the origin of min/max values. It does not store by
* itself the min/max values.
*/

class QgsRasterMinMaxOrigin
{
%TypeHeaderCode
#include <qgsrasterminmaxorigin.h>
%End
public:
//! \brief Default cumulative cut lower limit
static const double CUMULATIVE_CUT_LOWER;

//! \brief Default cumulative cut upper limit
static const double CUMULATIVE_CUT_UPPER;

//! \brief Default standard deviation factor
static const double DEFAULT_STDDEV_FACTOR;

//! \brief This enumerator describes the limits used to compute min/max values
enum Limits
{
//! User defined.
None /PyName=None_/,
//! Real min-max values
MinMax,
//! Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ]
StdDev,
//! Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]
CumulativeCut
};

//! \brief This enumerator describes the extent used to compute min/max values
enum Extent
{
//! Whole raster is used to compute statistics.
WholeRaster,
//! Current extent of the canvas (at the time of computation) is used to compute statistics.
CurrentCanvas,
//! Constantly updated extent of the canvas is used to compute statistics.
UpdatedCanvas
};

//! \brief This enumerator describes the accuracy used to compute statistics.
enum StatAccuracy
{
//! Exact statistics.
Exact,
//! Approximated statistics.
Estimated
};

//! \brief Default constructor.
QgsRasterMinMaxOrigin();

//! \brief Equality operator.
bool operator ==( const QgsRasterMinMaxOrigin& other ) const;

//////// Getter methods /////////////////////

//! \brief Return limits.
QgsRasterMinMaxOrigin::Limits limits() const;

//! \brief Return extent.
QgsRasterMinMaxOrigin::Extent extent() const;

//! \brief Return statistic accuracy.
QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const;

//! \brief Return lower bound of cumulative cut method (between 0 and 1).
double cumulativeCutLower() const;

//! \brief Return upper bound of cumulative cut method (between 0 and 1).
double cumulativeCutUpper() const;

//! \brief Return factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ]
double stdDevFactor() const;

//////// Setter methods /////////////////////

//! \brief Set limits.
void setLimits(QgsRasterMinMaxOrigin::Limits theLimits);

//! \brief Set extent.
void setExtent(QgsRasterMinMaxOrigin::Extent theExtent);

//! \brief Set statistics accuracy.
void setStatAccuracy(QgsRasterMinMaxOrigin::StatAccuracy theAccuracy);

//! \brief Set lower bound of cumulative cut method (between 0 and 1).
void setCumulativeCutLower(double val);

//! \brief Set upper bound of cumulative cut method (between 0 and 1).
void setCumulativeCutUpper(double val);

//! \brief Set factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ]
void setStdDevFactor(double val);

//////// XML serialization /////////////////////

//! \brief Serialize object.
void writeXml( QDomDocument& doc, QDomElement& parentElem ) const;

//! \brief Deserialize object.
void readXml( const QDomElement& elem );

//////// Static methods /////////////////////

//! \brief Return a string to serialize Limits
static QString limitsString( QgsRasterMinMaxOrigin::Limits theLimits );

//! \brief Deserialize Limits
static QgsRasterMinMaxOrigin::Limits limitsFromString( const QString& theLimits );

//! \brief Return a string to serialize Extent
static QString extentString( QgsRasterMinMaxOrigin::Extent theExtent );

//! \brief Deserialize Extent
static QgsRasterMinMaxOrigin::Extent extentFromString( const QString& theExtent );

//! \brief Return a string to serialize StatAccuracy
static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy theAccuracy );

//! \brief Deserialize StatAccuracy
static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString& theAccuracy );
};
26 changes: 6 additions & 20 deletions python/core/raster/qgsrasterrenderer.sip
Expand Up @@ -6,22 +6,6 @@ class QgsRasterRenderer : QgsRasterInterface
%End

public:
// Origin of min / max values
enum MinMaxOrigin
{
MinMaxUnknown,
MinMaxUser, // entered by user
// method
MinMaxMinMax,
MinMaxCumulativeCut,
MinMaxStdDev,
// Extent
MinMaxFullExtent,
MinMaxSubExtent,
// Precision
MinMaxEstimated,
MinMaxExact
};

static const QRgb NODATA_COLOR;

Expand Down Expand Up @@ -60,14 +44,16 @@ class QgsRasterRenderer : QgsRasterInterface
/** Copies common properties like opacity / transparency data from other renderer.
* Useful when cloning renderers.
* @note added in 2.16 */
void copyCommonProperties( const QgsRasterRenderer* other );
void copyCommonProperties( const QgsRasterRenderer* other, bool copyMinMaxOrigin = true );

/** Returns a list of band numbers used by the renderer*/
virtual QList<int> usesBands() const;

static QString minMaxOriginName( int theOrigin );
static QString minMaxOriginLabel( int theOrigin );
static int minMaxOriginFromName( const QString& theName );
//! Returns const reference to origin of min/max values
const QgsRasterMinMaxOrigin& minMaxOrigin() const;

//! Sets origin of min/max values
void setMinMaxOrigin( const QgsRasterMinMaxOrigin& theOrigin );

protected:

Expand Down
2 changes: 0 additions & 2 deletions python/core/raster/qgssinglebandpseudocolorrenderer.sip
Expand Up @@ -40,8 +40,6 @@ class QgsSingleBandPseudoColorRenderer: QgsRasterRenderer
double classificationMax() const;
void setClassificationMin( double min );
void setClassificationMax( double max );
int classificationMinMaxOrigin() const;
void setClassificationMinMaxOrigin( int origin );

private:

Expand Down
3 changes: 2 additions & 1 deletion python/gui/raster/qgsmultibandcolorrendererwidget.sip
Expand Up @@ -19,7 +19,8 @@ class QgsMultiBandColorRendererWidget: QgsRasterRendererWidget
void setMin( const QString& value, int index = 0 );
void setMax( const QString& value, int index = 0 );
int selectedBand( int index = 0 );
void doComputations();

public slots:
void loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin );
void loadMinMax( int theBandNo, double theMin, double theMax );
};
31 changes: 28 additions & 3 deletions python/gui/raster/qgsrasterminmaxwidget.sip
Expand Up @@ -37,9 +37,34 @@ class QgsRasterMinMaxWidget: QWidget
/** Return the selected sample size. */
int sampleSize();

// Load programmaticaly with current values
void load();
//! \brief Set the "source" of min/max values.
void setFromMinMaxOrigin( const QgsRasterMinMaxOrigin& );

//! \brief Return a QgsRasterMinMaxOrigin object with the widget values.
QgsRasterMinMaxOrigin minMaxOrigin();

//! Hide updated extent radio button
void hideUpdatedExtent();

//! Load programmaticaly with current values
void doComputations();

//! Uncheck cumulative cut, min/max, std-dev radio buttons
void userHasSetManualMinMaxValues();

//! Return if the widget is collaped.
bool isCollapsed() const;

//! Set collapsed state of widget
void setCollapsed(bool b);

signals:
void load( int theBandNo, double theMin, double theMax, int origin );
/**
* Emitted when something on the widget has changed.
* All widgets will fire this event to notify of an internal change.
*/
void widgetChanged();

//! signal emitted when new min/max values are computed from statistics.
void load( int theBandNo, double theMin, double theMax );
};
10 changes: 2 additions & 8 deletions python/gui/raster/qgsrasterrendererwidget.sip
Expand Up @@ -7,14 +7,6 @@ class QgsRasterRendererWidget: QWidget
QgsRasterRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent );
virtual ~QgsRasterRendererWidget();

enum LoadMinMaxAlgo
{
Estimate,
Actual,
CurrentExtent,
CumulativeCut // 2 - 98% cumulative cut
};

virtual QgsRasterRenderer* renderer() = 0 /Factory/;

void setRasterLayer( QgsRasterLayer* layer );
Expand Down Expand Up @@ -42,6 +34,8 @@ class QgsRasterRendererWidget: QWidget
virtual QString stdDev();
virtual void setStdDev( const QString& value );
virtual int selectedBand( int index = 0 );
virtual void doComputations();
virtual QgsRasterMinMaxWidget* minMaxWidget();

signals:
/**
Expand Down
3 changes: 2 additions & 1 deletion python/gui/raster/qgssinglebandgrayrendererwidget.sip
Expand Up @@ -19,7 +19,8 @@ class QgsSingleBandGrayRendererWidget: QgsRasterRendererWidget
void setMin( const QString& value, int index = 0 );
void setMax( const QString& value, int index = 0 );
int selectedBand( int index = 0 );
void doComputations();

public slots:
void loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin );
void loadMinMax( int theBandNo, double theMin, double theMax );
};
4 changes: 3 additions & 1 deletion python/gui/raster/qgssinglebandpseudocolorrendererwidget.sip
Expand Up @@ -21,12 +21,14 @@ class QgsSingleBandPseudoColorRendererWidget : QgsRasterRendererWidget

void setFromRenderer( const QgsRasterRenderer* r );

void doComputations();

public slots:

/** Executes the single band pseudo raster classficiation
*/
void classify();
void loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin );
void loadMinMax( int theBandNo, double theMin, double theMax );

};

0 comments on commit 792873a

Please sign in to comment.