From 8b18577a67b443c961b51d839061c9f5b453f744 Mon Sep 17 00:00:00 2001 From: Radim Blazek Date: Fri, 19 Apr 2013 21:10:38 +0200 Subject: [PATCH] raster cleanup --- python/core/raster/qgsrasterlayer.sip | 166 +-- src/app/legend/qgslegend.cpp | 18 +- src/app/qgsrastercalcdialog.cpp | 2 +- src/core/qgsprojectfiletransform.cpp | 9 +- src/core/raster/qgscontrastenhancement.cpp | 54 +- src/core/raster/qgscontrastenhancement.h | 2 + src/core/raster/qgsrasterlayer.cpp | 1253 +---------------- src/core/raster/qgsrasterlayer.h | 381 +---- src/core/raster/qgsrasterpipe.cpp | 6 +- src/core/raster/qgsrasterpipe.h | 13 +- src/gui/raster/qgspalettedrendererwidget.cpp | 21 +- ...qgssinglebandpseudocolorrendererwidget.cpp | 9 +- .../georeferencer/qgsgeorefplugingui.cpp | 8 +- tests/src/core/testqgsrasterlayer.cpp | 4 +- 14 files changed, 183 insertions(+), 1763 deletions(-) diff --git a/python/core/raster/qgsrasterlayer.sip b/python/core/raster/qgsrasterlayer.sip index be12b9e096f..ec0f85c448e 100644 --- a/python/core/raster/qgsrasterlayer.sip +++ b/python/core/raster/qgsrasterlayer.sip @@ -99,23 +99,6 @@ class QgsRasterLayer : QgsMapLayer ContrastEnhancementCumulativeCut }; - /** \brief A list containing on ContrastEnhancement object per raster band in this raster layer */ - typedef QList ContrastEnhancementList; - - /** \brief A list containing one RasterPyramid struct per raster band in this raster layer. - * POTENTIAL pyramid layer. This works by dividing the height - * and width of the raster by an incrementing number. As soon as the result - * of the division is <=256 we stop allowing RasterPyramid structs - * to be added to the list. Each time a RasterPyramid is created - * we will check to see if a pyramid matching these dimensions already exists - * in the raster layer, and if so mark the exists flag as true */ - /* typedef QList RasterPyramidList; */ - - /** \brief A list containing one RasterBandStats struct per raster band in this raster layer. - * Note that while every RasterBandStats element will have the name and number of its associated - * band populated, any additional stats are calculated on a need to know basis.*/ - /* typedef QList RasterStatsList; */ - // // Static methods: // @@ -128,48 +111,21 @@ class QgsRasterLayer : QgsMapLayer */ static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError ); static bool isValidRasterFileName( const QString & theFileNameQString ); - //static QStringList subLayers( GDALDatasetH dataset ); /** Return time stamp for given file name */ static QDateTime lastModified( const QString & name ); - // Keep this for now, it is used by Python interface!!! - /** \brief ensures that GDAL drivers are registered, but only once */ - static void registerGdalDrivers(); - // // Non Static inline methods // - - /** \brief Initialize default values */ - void init(); - /** [ data provider interface ] Set the data provider */ void setDataProvider( const QString & provider ); - /** \brief Accessor for blue band name mapping */ - QString blueBandName() const; - - /** \brief Accessor for color shader algorithm */ - QgsRasterLayer::ColorShadingAlgorithm colorShadingAlgorithm() const; - - /** \brief Accessor for contrast enhancement algorithm */ - QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm(); - - /** \brief Returns contrast enhancement algorithm as a string */ - QString contrastEnhancementAlgorithmAsString() const; - /** \brief Accessor for drawing style */ DrawingStyle drawingStyle(); - /** \brief Accessor for mHasPyramids (READ ONLY) */ - /* bool hasPyramids(); */ - - /** \brief Accessor for mUserDefinedGrayMinimumMaximum */ - bool hasUserDefinedGrayMinimumMaximum() const; - - /** \brief Accessor for mUserDefinedRGBMinimumMaximum */ - bool hasUserDefinedRGBMinimumMaximum() const; + /** \brief Accessor that returns the width of the (unclipped) raster */ + int width(); /** \brief Accessor that returns the height of the (unclipped) raster */ int height(); @@ -177,20 +133,8 @@ class QgsRasterLayer : QgsMapLayer /** \brief Accessor for raster layer type (which is a read only property) */ LayerType rasterType(); - /** \brief Mutator for drawing style */ void setDrawingStyle( const DrawingStyle & theDrawingStyle ); - /**Sets corresponding renderer for style*/ - void setRendererForDrawingStyle( const DrawingStyle & theDrawingStyle ); - - /** \brief Mutator to alter the number of standard deviations that should be plotted */ - void setStandardDeviations( double theStandardDeviations ); - - /** \brief Mutator for mUserDefinedGrayMinimumMaximum */ - void setUserDefinedGrayMinimumMaximum( bool theBool ); - - /** \brief Mutator for mUserDefinedRGBMinimumMaximum */ - void setUserDefinedRGBMinimumMaximum( bool theBool ); /**Set raster renderer. Takes ownership of the renderer object*/ void setRenderer( QgsRasterRenderer* theRenderer /Transfer/ ); @@ -203,12 +147,6 @@ class QgsRasterLayer : QgsMapLayer /** Get raster pipe */ QgsRasterPipe * pipe(); - /** \brief Accessor to find out how many standard deviations are being plotted */ - double standardDeviations() const; - - /** \brief Accessor that returns the width of the (unclipped) raster */ - int width(); - // // Non Static methods // @@ -218,33 +156,6 @@ class QgsRasterLayer : QgsMapLayer /** \brief Get the name of a band given its number */ const QString bandName( int theBandNoInt ); - /** \brief Get the number of a band given its name. The name is the rewritten name set - * up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal! - * If no matching band is found zero will be returned! */ - int bandNumber( const QString & theBandName ) const; - - /** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the - * POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers - * ACTUALLY exists you need to look at the existsFlag member in each struct stored in the - * list. - */ - // RasterPyramidList buildPyramidList(); - - /** \brief Accessor for color shader algorithm */ - QString colorShadingAlgorithmAsString() const; - - /** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent - \note added in v1.6 */ - //void computeMinimumMaximumFromLastExtent( int theBand, double& theMin /Out/, double& theMax /Out/ ); - - /** \brief Get a pointer to the contrast enhancement for the selected band */ - QgsContrastEnhancement* contrastEnhancement( unsigned int theBand ); - - const QgsContrastEnhancement* constContrastEnhancement( unsigned int theBand ) const; - - /** \brief Get a pointer to the color table */ - QList colorTable( int theBandNoInt ); - /** Returns the data provider */ QgsRasterDataProvider* dataProvider(); @@ -266,33 +177,6 @@ class QgsRasterLayer : QgsMapLayer QgsRasterViewPort * myRasterViewPort, const QgsMapToPixel* theQgsMapToPixel = 0 ); - /** \brief Returns a string representation of drawing style - * - * Implemented mainly for serialisation / deserialisation of settings to xml. - * NOTE: May be deprecated in the future!. DrawingStyle drawingStyle() instead. - * */ - QString drawingStyleAsString() const; - - /** \brief Identify raster value(s) found on the point position */ - //bool identify( const QgsPoint & point, QMap& results /Out/ ); - - /** \brief Identify raster value(s) found on the point position */ -// bool identifyMap( const QgsPoint & point, QMap& results /Out/ ); -//%MethodCode -// sipRes = sipCpp->identify( *a0, *a1 ); -//%End - - /** \brief Identify arbitrary details from the WMS server found on the point position */ - //QString identifyAsText( const QgsPoint & point ); - - /** \brief Identify arbitrary details from the WMS server found on the point position - * @note added in 1.5 - */ - //QString identifyAsHtml( const QgsPoint & point ); - - /** \brief Currently returns always false */ - bool isEditable() const; - /** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */ QString lastError(); @@ -303,21 +187,9 @@ class QgsRasterLayer : QgsMapLayer @note this method was added in version 1.8*/ QList< QPair< QString, QColor > > legendSymbologyItems() const; - /** \brief Accessor for maximum value user for contrast enhancement */ - double maximumValue( unsigned int theBand ); - - /** \brief Accessor for maximum value user for contrast enhancement */ - double maximumValue( QString theBand ); - /** \brief Obtain GDAL Metadata for this layer */ QString metadata(); - /** \brief Accessor for minimum value user for contrast enhancement */ - double minimumValue( unsigned int theBand ); - - /** \brief Accessor for minimum value user for contrast enhancement */ - double minimumValue( QString theBand ); - /** \brief Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned */ QPixmap paletteAsPixmap( int theBandNumber = 1 ); @@ -329,20 +201,9 @@ class QgsRasterLayer : QgsMapLayer /** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */ double rasterUnitsPerPixel(); - /** \brief Read color table from GDAL raster band */ - // bool readColorTable( int theBandNumber, QList* theList ); - - /** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */ - //void resetNoDataValue(); - static QString contrastEnhancementLimitsAsString( QgsRasterLayer::ContrastEnhancementLimits theLimits ); static ContrastEnhancementLimits contrastEnhancementLimitsFromString( QString theLimits ); - /** \brief Mutator for contrast enhancement algorithm using min/max */ - // TODO: remove in 2.0, replaced by following - // void setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm, - // bool theGenerateLookupTableFlag = true ); - /** \brief Mutator for contrast enhancement algorithm * @param theAlgorithm Contrast enhancement algorithm * @param theLimits Limits @@ -357,30 +218,12 @@ class QgsRasterLayer : QgsMapLayer int theSampleSize = QgsRasterLayer::SAMPLE_SIZE, bool theGenerateLookupTableFlag = true ); - /** \brief Mutator for contrast enhancement algorithm */ - void setContrastEnhancementAlgorithm( QString theAlgorithm, bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator for contrast enhancement function */ - void setContrastEnhancementFunction( QgsContrastEnhancementFunction* theFunction ); - /** \brief Set default contrast enhancement */ void setDefaultContrastEnhancement(); /** \brief Overloaded version of the above function for convenience when restoring from xml */ void setDrawingStyle( const QString & theDrawingStyleQString ); - /** \brief Mutator for setting the maximum value for contrast enhancement */ - void setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true ); - - /** \brief Sets the minimum and maximum values for the band(s) currently - * being displayed using the only pixel values from the last/current extent - * */ - void setMinimumMaximumUsingLastExtent(); - - /** \brief Sets the minimum and maximum values for the band(s) currently - * being displayed using the only pixel values from the dataset min/max */ - void setMinimumMaximumUsingDataset(); - /** \brief [ data provider interface ] A wrapper function to emit a progress update signal */ void showProgress( int theValue ); @@ -413,11 +256,6 @@ class QgsRasterLayer : QgsMapLayer virtual QDateTime timestamp() const; public slots: - /** \brief Create GDAL pyramid overviews */ - // QString buildPyramids( const RasterPyramidList &, - // const QString & theResamplingMethod = "NEAREST", - // bool theTryInternalFlag = false ); - void showStatusMessage( const QString & theMessage ); /** \brief Propagate progress updates from GDAL up to the parent app */ diff --git a/src/app/legend/qgslegend.cpp b/src/app/legend/qgslegend.cpp index ef90d746b65..2b9371e1f3e 100644 --- a/src/app/legend/qgslegend.cpp +++ b/src/app/legend/qgslegend.cpp @@ -2753,25 +2753,11 @@ void QgsLegend::legendLayerStretchUsingCurrentExtent() QgsRasterLayer *layer = qobject_cast( currentLayer->layer() ); if ( layer ) { - // Note: Do we really want to do these next clauses? The user will get a surprise when the - // drawing style they are using suddenly changes....! TS - if ( layer->drawingStyle() == QgsRasterLayer::SingleBandPseudoColor ) - { - layer->setDrawingStyle( QgsRasterLayer::SingleBandGray ); - } - else if ( layer->drawingStyle() == QgsRasterLayer::MultiBandSingleBandPseudoColor ) - { - layer->setDrawingStyle( QgsRasterLayer::MultiBandSingleBandGray ); - } - - if ( layer->contrastEnhancementAlgorithmAsString() == "NoEnhancement" ) - { - layer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" ); - } + QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm = QgsContrastEnhancement::StretchToMinimumMaximum; QgsRectangle myRectangle; myRectangle = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( layer, mMapCanvas->extent() ); - layer->setContrastEnhancementAlgorithm( layer->contrastEnhancementAlgorithm(), QgsRasterLayer::ContrastEnhancementMinMax, myRectangle ); + layer->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm, QgsRasterLayer::ContrastEnhancementMinMax, myRectangle ); layer->setCacheImage( NULL ); refreshLayerSymbology( layer->id() ); diff --git a/src/app/qgsrastercalcdialog.cpp b/src/app/qgsrastercalcdialog.cpp index a5ababecaa9..4aaa56acf7b 100644 --- a/src/app/qgsrastercalcdialog.cpp +++ b/src/app/qgsrastercalcdialog.cpp @@ -125,7 +125,7 @@ void QgsRasterCalcDialog::insertAvailableRasterBands() firstLayer = false; } //get number of bands - for ( unsigned int i = 0; i < rlayer->bandCount(); ++i ) + for ( int i = 0; i < rlayer->bandCount(); ++i ) { QgsRasterCalculatorEntry entry; entry.raster = rlayer; diff --git a/src/core/qgsprojectfiletransform.cpp b/src/core/qgsprojectfiletransform.cpp index b65357d5ee7..dd11f2677bc 100644 --- a/src/core/qgsprojectfiletransform.cpp +++ b/src/core/qgsprojectfiletransform.cpp @@ -816,10 +816,13 @@ int QgsProjectFileTransform::rasterBandNumber( const QDomElement& rasterProperti QDomElement rasterBandElem = rasterPropertiesElem.firstChildElement( bandName ); if ( !rasterBandElem.isNull() ) { - band = rlayer->bandNumber( rasterBandElem.text() ); - if ( band == 0 ) + for ( int i = 1; i <= rlayer->bandCount(); i++ ) { - band = -1; + if ( rlayer->bandName( i ) == rasterBandElem.text() ) + { + band = i; + break; + } } } return band; diff --git a/src/core/raster/qgscontrastenhancement.cpp b/src/core/raster/qgscontrastenhancement.cpp index 223be213e9f..8cbc1c216dd 100644 --- a/src/core/raster/qgscontrastenhancement.cpp +++ b/src/core/raster/qgscontrastenhancement.cpp @@ -395,7 +395,7 @@ void QgsContrastEnhancement::writeXML( QDomDocument& doc, QDomElement& parentEle //algorithm QDomElement algorithmElem = doc.createElement( "algorithm" ); - QDomText algorithmText = doc.createTextNode( QString::number( mContrastEnhancementAlgorithm ) ); + QDomText algorithmText = doc.createTextNode( contrastEnhancementAlgorithmString( mContrastEnhancementAlgorithm ) ); algorithmElem.appendChild( algorithmText ); parentElem.appendChild( algorithmElem ); } @@ -415,10 +415,56 @@ void QgsContrastEnhancement::readXML( const QDomElement& elem ) QDomElement algorithmElem = elem.firstChildElement( "algorithm" ); if ( !algorithmElem.isNull() ) { - setContrastEnhancementAlgorithm(( ContrastEnhancementAlgorithm )( algorithmElem.text().toInt() ) ); + QString algorithmString = algorithmElem.text(); + ContrastEnhancementAlgorithm algorithm = NoEnhancement; + // old version ( < 19 Apr 2013) was using enum directly -> for backward compatibility + if ( algorithmString == "0" ) + { + algorithm = NoEnhancement; + } + else if ( algorithmString == "1" ) + { + algorithm = StretchToMinimumMaximum; + } + else if ( algorithmString == "2" ) + { + algorithm = StretchAndClipToMinimumMaximum; + } + else if ( algorithmString == "3" ) + { + algorithm = ClipToMinimumMaximum; + } + else if ( algorithmString == "4" ) + { + algorithm = UserDefinedEnhancement; + } + else + { + algorithm = contrastEnhancementAlgorithmFromString( algorithmString ); + } + + setContrastEnhancementAlgorithm( algorithm ); } } +QString QgsContrastEnhancement::contrastEnhancementAlgorithmString( ContrastEnhancementAlgorithm algorithm ) +{ + switch ( algorithm ) + { + case NoEnhancement: + return "NoEnhancement"; + case StretchToMinimumMaximum: + return "StretchToMinimumMaximum"; + case StretchAndClipToMinimumMaximum: + return "StretchAndClipToMinimumMaximum"; + case ClipToMinimumMaximum: + return "ClipToMinimumMaximum"; + case UserDefinedEnhancement: + return "UserDefinedEnhancement"; + } + return "NoEnhancement"; +} + QgsContrastEnhancement::ContrastEnhancementAlgorithm QgsContrastEnhancement::contrastEnhancementAlgorithmFromString( const QString& contrastEnhancementString ) { if ( contrastEnhancementString == "StretchToMinimumMaximum" ) @@ -433,6 +479,10 @@ QgsContrastEnhancement::ContrastEnhancementAlgorithm QgsContrastEnhancement::con { return ClipToMinimumMaximum; } + else if ( contrastEnhancementString == "UserDefinedEnhancement" ) + { + return UserDefinedEnhancement; + } else { return NoEnhancement; diff --git a/src/core/raster/qgscontrastenhancement.h b/src/core/raster/qgscontrastenhancement.h index bd4ae57c063..0d5b06525dc 100644 --- a/src/core/raster/qgscontrastenhancement.h +++ b/src/core/raster/qgscontrastenhancement.h @@ -100,6 +100,8 @@ class CORE_EXPORT QgsContrastEnhancement ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const { return mContrastEnhancementAlgorithm; } + static QString contrastEnhancementAlgorithmString( ContrastEnhancementAlgorithm algorithm ); + static ContrastEnhancementAlgorithm contrastEnhancementAlgorithmFromString( const QString& contrastEnhancementString ); /* diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index 13da3f4388c..0ae21364519 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -14,44 +14,37 @@ email : tim at linfiniti.com * (at your option) any later version. * * * ***************************************************************************/ - +//#include "gdalwarper.h" +//#include "cpl_conv.h" #include "qgsapplication.h" +#include "qgscolorrampshader.h" +#include "qgscoordinatereferencesystem.h" +#include "qgscoordinatetransform.h" #include "qgsdatasourceuri.h" +#include "qgsfreakoutshader.h" #include "qgslogger.h" -#include "qgsmessagelog.h" #include "qgsmaplayerregistry.h" #include "qgsmaptopixel.h" +#include "qgsmessagelog.h" +#include "qgsmultibandcolorrenderer.h" +#include "qgspalettedrasterrenderer.h" #include "qgsprojectfiletransform.h" #include "qgsproviderregistry.h" +#include "qgspseudocolorshader.h" +#include "qgsrasterdrawer.h" +#include "qgsrasteriterator.h" #include "qgsrasterlayer.h" +#include "qgsrasterprojector.h" #include "qgsrasterrange.h" #include "qgsrasterrendererregistry.h" #include "qgsrectangle.h" #include "qgsrendercontext.h" -#include "qgscoordinatereferencesystem.h" -#include "qgscoordinatetransform.h" - -#include "gdalwarper.h" -#include "cpl_conv.h" - -#include "qgspseudocolorshader.h" -#include "qgsfreakoutshader.h" -#include "qgscolorrampshader.h" - -//renderers -#include "qgspalettedrasterrenderer.h" -#include "qgsmultibandcolorrenderer.h" #include "qgssinglebandcolordatarenderer.h" -#include "qgssinglebandpseudocolorrenderer.h" #include "qgssinglebandgrayrenderer.h" +#include "qgssinglebandpseudocolorrenderer.h" -#include "qgsrasterprojector.h" - -#include "qgsrasteriterator.h" -#include "qgsrasterdrawer.h" - -#include #include +#include #include #include @@ -66,27 +59,21 @@ email : tim at linfiniti.com #include #include #include +#include #include #include #include -#include #include #include #include -#include #include +#include #include // typedefs for provider plugin functions of interest typedef void buildsupportedrasterfilefilter_t( QString & theFileFiltersString ); typedef bool isvalidrasterfilename_t( QString const & theFileNameQString, QString & retErrMsg ); -// Comparison value for equality; i.e., we shouldn't directly compare two -// floats so it's better to take their difference and see if they're within -// a certain range -- in this case twenty times the smallest value that -// doubles can take for the current system. (Yes, 20 was arbitrary.) -#define TINY_VALUE std::numeric_limits::epsilon() * 20 - #define ERR(message) QGS_ERROR_MESSAGE(message,"Raster layer") const double QgsRasterLayer::CUMULATIVE_CUT_LOWER = 0.02; @@ -97,10 +84,7 @@ QgsRasterLayer::QgsRasterLayer() : QgsMapLayer( RasterLayer ) , QSTRING_NOT_SET( "Not Set" ) , TRSTRING_NOT_SET( tr( "Not Set" ) ) - , mStandardDeviations( 0 ) , mDataProvider( 0 ) - , mWidth( std::numeric_limits::max() ) - , mHeight( std::numeric_limits::max() ) { init(); mValid = false; @@ -111,13 +95,9 @@ QgsRasterLayer::QgsRasterLayer( QString const & baseName, bool loadDefaultStyleFlag ) : QgsMapLayer( RasterLayer, baseName, path ) - // Constant that signals property not used. , QSTRING_NOT_SET( "Not Set" ) , TRSTRING_NOT_SET( tr( "Not Set" ) ) - , mStandardDeviations( 0 ) , mDataProvider( 0 ) - , mWidth( std::numeric_limits::max() ) - , mHeight( std::numeric_limits::max() ) { QgsDebugMsg( "Entered" ); @@ -150,12 +130,7 @@ QgsRasterLayer::QgsRasterLayer( const QString & uri, // Constant that signals property not used. , QSTRING_NOT_SET( "Not Set" ) , TRSTRING_NOT_SET( tr( "Not Set" ) ) - , mStandardDeviations( 0 ) , mDataProvider( 0 ) - , mEditable( false ) - , mWidth( std::numeric_limits::max() ) - , mHeight( std::numeric_limits::max() ) - , mModified( false ) , mProviderKey( providerKey ) { QgsDebugMsg( "Entered" ); @@ -174,18 +149,6 @@ QgsRasterLayer::QgsRasterLayer( const QString & uri, setDefaultContrastEnhancement(); } - // Default for the popup menu - // TODO: popMenu = 0; - - // Get the update threshold from user settings. We - // do this only on construction to avoid the penality of - // fetching this each time the layer is drawn. If the user - // changes the threshold from the preferences dialog, it will - // have no effect on existing layers - // TODO: QSettings settings; - // updateThreshold = settings.readNumEntry("Map/updateThreshold", 1000); - - // TODO: Connect signals from the dataprovider to the qgisapp emit statusChanged( tr( "QgsRasterLayer created" ) ); @@ -272,344 +235,22 @@ typedef QgsDataProvider * classFactoryFunction_t( const QString * ); // ///////////////////////////////////////////////////////// -unsigned int QgsRasterLayer::bandCount() const +int QgsRasterLayer::bandCount() const { - return mBandCount; + if ( !mDataProvider ) return 0; + return mDataProvider->bandCount(); } const QString QgsRasterLayer::bandName( int theBandNo ) { -#if 0 - if ( theBandNo <= mRasterStatsList.size() && theBandNo > 0 ) - { - //vector starts at base 0, band counts at base1! - return mRasterStatsList[theBandNo - 1].bandName; - } - else - { - return QString( "" ); - } -#endif return dataProvider()->generateBandName( theBandNo ); } -int QgsRasterLayer::bandNumber( QString const & theBandName ) const -{ - if ( !mDataProvider ) return 0; - for ( int myIterator = 1; myIterator <= dataProvider()->bandCount(); ++myIterator ) - { - //find out the name of this band -#if 0 - QgsRasterBandStats myRasterBandStats = mRasterStatsList[myIterator]; - QgsDebugMsg( "myRasterBandStats.bandName: " + myRasterBandStats.bandName + " :: theBandName: " - + theBandName ); - - if ( myRasterBandStats.bandName == theBandName ) -#endif - QString myBandName = dataProvider()->generateBandName( myIterator ); - if ( myBandName == theBandName ) - { - QgsDebugMsg( "********** band " + QString::number( myIterator ) + - " was found in bandNumber " + theBandName ); - - return myIterator; - } - } - QgsDebugMsg( "********** no band was found in bandNumber " + theBandName ); - - return 0; //no band was found -} - -#if 0 -/** - * Private method to calculate statistics for a band. Populates rasterStatsMemArray. - * Calculates: - * - *
    - *
  • myRasterBandStats.elementCount - *
  • myRasterBandStats.minimumValue - *
  • myRasterBandStats.maximumValue - *
  • myRasterBandStats.sum - *
  • myRasterBandStats.range - *
  • myRasterBandStats.mean - *
  • myRasterBandStats.sumOfSquares - *
  • myRasterBandStats.stdDev - *
  • myRasterBandStats.colorTable - *
- * - * @sa RasterBandStats - * @note This is a cpu intensive and slow task! - */ -const QgsRasterBandStats QgsRasterLayer::bandStatistics( int theBandNo ) -{ - QgsDebugMsg( "theBandNo = " + QString::number( theBandNo ) ); - QgsDebugMsg( "mRasterType = " + QString::number( mRasterType ) ); - if ( mRasterType == ColorLayer ) - { - // Statistics have no sense for ColorLayer - QgsRasterBandStats myNullReturnStats; - return myNullReturnStats; - } - // check if we have received a valid band number - if (( mDataProvider->bandCount() < theBandNo ) && mRasterType != Palette ) - { - // invalid band id, return nothing - QgsRasterBandStats myNullReturnStats; - return myNullReturnStats; - } - if ( mRasterType == Palette && ( theBandNo > 3 ) ) - { - // invalid band id, return nothing - QgsRasterBandStats myNullReturnStats; - return myNullReturnStats; - } - // check if we have previously gathered stats for this band... - if ( theBandNo < 1 || theBandNo > mRasterStatsList.size() ) - { - // invalid band id, return nothing - QgsRasterBandStats myNullReturnStats; - return myNullReturnStats; - } - - // TODO this is buggy - because the stats might have changed (e.g. theIgnoreOutOfRangeFlag in populateHistogram()) - // should have a pointer to the stats instead - QgsRasterBandStats myRasterBandStats = mRasterStatsList[theBandNo - 1]; - myRasterBandStats.bandNumber = theBandNo; - - // don't bother with this if we already have stats - if ( myRasterBandStats.statsGathered ) - { - return myRasterBandStats; - } - - myRasterBandStats = mDataProvider->bandStatistics( theBandNo ); - QgsDebugMsg( "adding stats to stats collection at position " + QString::number( theBandNo - 1 ) ); - //add this band to the class stats map - mRasterStatsList[theBandNo - 1] = myRasterBandStats; - - emit drawingProgress( mHeight, mHeight ); //reset progress - QgsDebugMsg( "Stats collection completed returning" ); - return myRasterBandStats; -} // QgsRasterLayer::bandStatistics - -const QgsRasterBandStats QgsRasterLayer::bandStatistics( QString const & theBandName ) -{ - // only print message if we are actually gathering the stats - emit statusChanged( tr( "Retrieving stats for %1" ).arg( name() ) ); - qApp->processEvents(); - //reset the main app progress bar - emit drawingProgress( 0, 0 ); - //we cant use a vector iterator because the iterator is astruct not a class - //and the qvector model does not like this. - for ( int i = 1; i <= mDataProvider->bandCount(); i++ ) - { - QgsRasterBandStats myRasterBandStats = bandStatistics( i ); - if ( myRasterBandStats.bandName == theBandName ) - { - return myRasterBandStats; - } - } - - return QgsRasterBandStats(); // return a null one -} - -QString QgsRasterLayer::buildPyramids( RasterPyramidList const & theRasterPyramidList, - QString const & theResamplingMethod, bool theTryInternalFlag ) -{ - return mDataProvider->buildPyramids( theRasterPyramidList, theResamplingMethod, theTryInternalFlag ); -} - - -QgsRasterLayer::RasterPyramidList QgsRasterLayer::buildPyramidList() -{ - return mDataProvider->buildPyramidList(); -} -#endif - -QString QgsRasterLayer::colorShadingAlgorithmAsString() const -{ - switch ( mColorShadingAlgorithm ) - { - case PseudoColorShader: - return QString( "PseudoColorShader" ); - break; - case FreakOutShader: - return QString( "FreakOutShader" ); - break; - case ColorRampShader: - return QString( "ColorRampShader" ); - break; - case UserDefinedShader: - return QString( "UserDefinedShader" ); - break; - default: - break; - } - - return QString( "UndefinedShader" ); -} - -#if 0 -/** - * @param theBand The band (number) for which to estimate the min max values - * @param theMinMax Pointer to a double[2] which hold the estimated min max - */ -void QgsRasterLayer::computeMinimumMaximumEstimates( int theBand, double* theMinMax ) -{ - if ( !theMinMax ) - return; - - if ( 0 < theBand && theBand <= ( int ) bandCount() ) - { - theMinMax[0] = mDataProvider->minimumValue( theBand ); - theMinMax[1] = mDataProvider->maximumValue( theBand ); - } -} - -/** - * @param theBand The band (name) for which to estimate the min max values - * @param theMinMax Pointer to a double[2] which hold the estimated min max - */ -void QgsRasterLayer::computeMinimumMaximumEstimates( QString theBand, double* theMinMax ) -{ - computeMinimumMaximumEstimates( bandNumber( theBand ), theMinMax ); -} - -void QgsRasterLayer::computeMinimumMaximumEstimates( int theBand, double& theMin, double& theMax ) -{ - double theMinMax[2]; - computeMinimumMaximumEstimates( theBand, theMinMax ); - theMin = theMinMax[0]; - theMax = theMinMax[1]; -} - -/** - * @param theBand The band (number) for which to calculate the min max values - * @param theMinMax Pointer to a double[2] which hold the estimated min max - */ -void QgsRasterLayer::computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax ) -{ - if ( !theMinMax ) - return; - - QGis::DataType myDataType = mDataProvider->dataType( theBand ); - void* myScanData = readData( theBand, &mLastViewPort ); - - /* Check for out of memory error */ - if ( myScanData == NULL ) - { - return; - } - - if ( 0 < theBand && theBand <= ( int ) bandCount() ) - { - // Was there any reason to use float for myMin, myMax, myValue? - // It was breaking Float64 data obviously, especially if an extreme value - // was used for NoDataValue. - double myMin = std::numeric_limits::max(); - double myMax = -1 * std::numeric_limits::max(); - double myValue = 0.0; - for ( int myRow = 0; myRow < mLastViewPort.drawableAreaYDim; ++myRow ) - { - for ( int myColumn = 0; myColumn < mLastViewPort.drawableAreaXDim; ++myColumn ) - { - myValue = QgsRasterInterface::readValue( myScanData, myDataType, myRow * mLastViewPort.drawableAreaXDim + myColumn ); - if ( mDataProvider->isNoDataValue( theBand, myValue ) ) - { - continue; - } - myMin = qMin( myMin, myValue ); - myMax = qMax( myMax, myValue ); - } - } - theMinMax[0] = myMin; - theMinMax[1] = myMax; - } -} - -/** - * @param theBand The band (name) for which to calculate the min max values - * @param theMinMax Pointer to a double[2] which hold the estimated min max - */ -void QgsRasterLayer::computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax ) -{ - computeMinimumMaximumFromLastExtent( bandNumber( theBand ), theMinMax ); -} - -void QgsRasterLayer::computeMinimumMaximumFromLastExtent( int theBand, double& theMin, double& theMax ) -{ - double theMinMax[2]; - computeMinimumMaximumFromLastExtent( theBand, theMinMax ); - theMin = theMinMax[0]; - theMax = theMinMax[1]; -} -#endif - -/** - * @param theBand The band (number) for which to get the contrast enhancement for - * @return Pointer to the contrast enhancement or 0 on failure - */ -QgsContrastEnhancement* QgsRasterLayer::contrastEnhancement( unsigned int theBand ) -{ - if ( 0 < theBand && theBand <= bandCount() ) - { - return &mContrastEnhancementList[theBand - 1]; - } - - return 0; -} - -const QgsContrastEnhancement* QgsRasterLayer::constContrastEnhancement( unsigned int theBand ) const -{ - if ( 0 < theBand && theBand <= bandCount() ) - { - return &mContrastEnhancementList[theBand - 1]; - } - - return 0; -} - -QString QgsRasterLayer::contrastEnhancementAlgorithmAsString() const -{ - switch ( mContrastEnhancementAlgorithm ) - { - case QgsContrastEnhancement::NoEnhancement: - return QString( "NoEnhancement" ); - break; - case QgsContrastEnhancement::StretchToMinimumMaximum: - return QString( "StretchToMinimumMaximum" ); - break; - case QgsContrastEnhancement::StretchAndClipToMinimumMaximum: - return QString( "StretchAndClipToMinimumMaximum" ); - break; - case QgsContrastEnhancement::ClipToMinimumMaximum: - return QString( "ClipToMinimumMaximum" ); - break; - case QgsContrastEnhancement::UserDefinedEnhancement: - return QString( "UserDefined" ); - break; - } - - return QString( "NoEnhancement" ); -} - void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawingStyle ) { setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( theDrawingStyle, mDataProvider ) ); } - -/** - * @param theBandNo the band number - * @return ointer to the color table - */ -QList QgsRasterLayer::colorTable( int theBandNo ) -{ - //return &( mRasterStatsList[theBandNo-1].colorTable ); - if ( !mDataProvider ) return QList(); - return dataProvider()->colorTable( theBandNo ); -} - /** * @return 0 if not using the data provider model (i.e. directly using GDAL) */ @@ -760,17 +401,10 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext ) //the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is becasue //theQgsMapToPixel.mapUnitsPerPixel() is less then 1, //so we will just get the pixel data and then render these special cases differently in paintImageToCanvas() -#if 0 - if ( 2 >= myRasterViewPort->clippedWidth && 2 >= myRasterViewPort->clippedHeight ) - { - myRasterViewPort->drawableAreaXDim = myRasterViewPort->clippedWidth; - myRasterViewPort->drawableAreaYDim = myRasterViewPort->clippedHeight; - } -#endif QgsDebugMsgLevel( QString( "mapUnitsPerPixel = %1" ).arg( theQgsMapToPixel.mapUnitsPerPixel() ), 3 ); - QgsDebugMsgLevel( QString( "mWidth = %1" ).arg( mWidth ), 3 ); - QgsDebugMsgLevel( QString( "mHeight = %1" ).arg( mHeight ), 3 ); + QgsDebugMsgLevel( QString( "mWidth = %1" ).arg( width() ), 3 ); + QgsDebugMsgLevel( QString( "mHeight = %1" ).arg( height() ), 3 ); QgsDebugMsgLevel( QString( "myRasterExtent.xMinimum() = %1" ).arg( myRasterExtent.xMinimum() ), 3 ); QgsDebugMsgLevel( QString( "myRasterExtent.xMaximum() = %1" ).arg( myRasterExtent.xMaximum() ), 3 ); QgsDebugMsgLevel( QString( "myRasterExtent.yMinimum() = %1" ).arg( myRasterExtent.yMinimum() ), 3 ); @@ -832,173 +466,6 @@ void QgsRasterLayer::draw( QPainter * theQPainter, QgsDebugMsg( QString( "total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ) ); } //end of draw method -QString QgsRasterLayer::drawingStyleAsString() const -{ - switch ( mDrawingStyle ) - { - case SingleBandGray: - return QString( "SingleBandGray" ); //no need to tr() this its not shown in ui - break; - case SingleBandPseudoColor: - return QString( "SingleBandPseudoColor" );//no need to tr() this its not shown in ui - break; - case PalettedColor: - return QString( "PalettedColor" );//no need to tr() this its not shown in ui - break; - case PalettedSingleBandGray: - return QString( "PalettedSingleBandGray" );//no need to tr() this its not shown in ui - break; - case PalettedSingleBandPseudoColor: - return QString( "PalettedSingleBandPseudoColor" );//no need to tr() this its not shown in ui - break; - case PalettedMultiBandColor: - return QString( "PalettedMultiBandColor" );//no need to tr() this its not shown in ui - break; - case MultiBandSingleBandGray: - return QString( "MultiBandSingleBandGray" );//no need to tr() this its not shown in ui - break; - case MultiBandSingleBandPseudoColor: - return QString( "MultiBandSingleBandPseudoColor" );//no need to tr() this its not shown in ui - break; - case MultiBandColor: - return QString( "MultiBandColor" );//no need to tr() this its not shown in ui - break; - case SingleBandColorDataStyle: - return QString( "SingleBandColorDataStyle" );//no need to tr() this its not shown in ui - break; - default: - break; - } - - return QString( "UndefinedDrawingStyle" ); - -} - - -#if 0 -/** - * @param theBandNo The number of the band to check - * @return true if statistics have already been build for this band otherwise false - */ -bool QgsRasterLayer::hasStatistics( int theBandNo ) -{ - if ( theBandNo <= mRasterStatsList.size() && theBandNo > 0 ) - { - //vector starts at base 0, band counts at base1! - return mRasterStatsList[theBandNo - 1].statsGathered; - } - else - { - return false; - } -} -#endif - -#if 0 -/** - * @param thePoint the QgsPoint for which to obtain pixel values - * @param theResults QMap to hold the pixel values at thePoint for each layer in the raster file - * @return False if WMS layer and true otherwise - */ -bool QgsRasterLayer::identify( const QgsPoint& thePoint, QMap& theResults ) -{ - theResults.clear(); - - if ( !mDataProvider ) return false; - - QMap results; - if ( ! identify( thePoint, results ) ) return false; - - foreach ( int bandNo, results.keys() ) - { - theResults[ mDataProvider->generateBandName( bandNo )] = results.value( bandNo ); - } - return true; -} - -bool QgsRasterLayer::identify( const QgsPoint & point, QMap& theResults ) -{ - if ( !mDataProvider ) return false; - - theResults.clear(); - //return mDataProvider->identify( point, theResults ); - - QMap dataMap = mDataProvider->identify( point ); - foreach ( int bandNo, dataMap.keys() ) - { - QGis::DataType dataType = mDataProvider->dataType( bandNo ); - void * data = dataMap.value( bandNo ); - QString str; - if ( !data ) - { - str = tr( "Cannot read data" ); - } - else - { - if ( QgsRasterBlock::typeIsNumeric( dataType ) ) - { - double value = mDataProvider->readValue( data, dataType, 0 ); - if ( mDataProvider->isNoDataValue( bandNo, value ) ) - { - str = tr( "null (no data)" ); - } - else - { - str.setNum( value ); - } - } - else - { - QRgb c((( uint* )data )[0] ); - str = QString( "%1,%2,%3,%4" ).arg( qRed( c ) ).arg( qGreen( c ) ).arg( qBlue( c ) ).arg( qAlpha( c ) ); - } - free( data ); - } - theResults[ bandNo ] = str; - } - return true; -} - -/** - * @note The arbitraryness of the returned document is enforced by WMS standards up to at least v1.3.0 - * - * @param thePoint an image pixel coordinate in the last requested extent of layer. - * @return A text document containing the return from the WMS server - */ -QString QgsRasterLayer::identifyAsText( const QgsPoint& thePoint ) -{ - if ( mProviderKey != "wms" ) - { - // Currently no meaning for anything other than OGC WMS layers - return QString(); - } - - return mDataProvider->identifyAsText( thePoint ); -} - -/** - * @note The arbitraryness of the returned document is enforced by WMS standards up to at least v1.3.0 - * - * @param thePoint an image pixel coordinate in the last requested extent of layer. - * @return A html document containing the return from the WMS server - */ -QString QgsRasterLayer::identifyAsHtml( const QgsPoint& thePoint ) -{ - if ( mProviderKey != "wms" ) - { - // Currently no meaning for anything other than OGC WMS layers - return QString(); - } - - return mDataProvider->identifyAsHtml( thePoint ); -} -#endif - -bool QgsRasterLayer::isEditable() const -{ - return false; -} - QString QgsRasterLayer::lastError() { return mError; @@ -1012,125 +479,14 @@ QString QgsRasterLayer::lastErrorTitle() QList< QPair< QString, QColor > > QgsRasterLayer::legendSymbologyItems() const { QList< QPair< QString, QColor > > symbolList; - //if ( mPipe.renderer() ) - //{ - // mPipe.renderer()->legendSymbologyItems( symbolList ); - //} QgsRasterRenderer *renderer = mPipe.renderer(); if ( renderer ) { renderer->legendSymbologyItems( symbolList ); } return symbolList; - -#if 0 - if ( mDrawingStyle == SingleBandGray || mDrawingStyle == PalettedSingleBandGray || mDrawingStyle == MultiBandSingleBandGray ) - { - //add min/max from contrast enhancement - QString grayBand = grayBandName(); - if ( !grayBand.isEmpty() ) - { - int grayBandNr = bandNumber( grayBand ); - const QgsContrastEnhancement* ceh = constContrastEnhancement( grayBandNr ); - if ( ceh ) - { - QgsContrastEnhancement::ContrastEnhancementAlgorithm alg = ceh->contrastEnhancementAlgorithm(); - if ( alg == QgsContrastEnhancement::NoEnhancement - || alg == QgsContrastEnhancement::ClipToMinimumMaximum ) - { - //diffcult to display a meaningful item - symbolList.push_back( qMakePair( QString::number( ceh->minimumValue() ) + "-" + QString::number( ceh->maximumValue() ), QColor( 125, 125, 125 ) ) ); - } - else - { - symbolList.push_back( qMakePair( QString::number( ceh->minimumValue() ), QColor( 0, 0, 0 ) ) ); - symbolList.push_back( qMakePair( QString::number( ceh->maximumValue() ), QColor( 255, 255, 255 ) ) ); - } - } - } - } - else - { - switch ( mColorShadingAlgorithm ) - { - case ColorRampShader: - { - const QgsColorRampShader* crShader = dynamic_cast( mRasterShader->rasterShaderFunction() ); - if ( crShader ) - { - QList shaderItems = crShader->colorRampItemList(); - QList::const_iterator itemIt = shaderItems.constBegin(); - for ( ; itemIt != shaderItems.constEnd(); ++itemIt ) - { - symbolList.push_back( qMakePair( itemIt->label, itemIt->color ) ); - } - } - break; - } - case PseudoColorShader: - { - //class breaks have fixed color for the pseudo color shader - const QgsPseudoColorShader* pcShader = dynamic_cast( mRasterShader->rasterShaderFunction() ); - if ( pcShader ) - { - symbolList.push_back( qMakePair( QString::number( pcShader->classBreakMin1() ), QColor( 0, 0, 255 ) ) ); - symbolList.push_back( qMakePair( QString::number( pcShader->classBreakMax1() ), QColor( 0, 255, 255 ) ) ); - symbolList.push_back( qMakePair( QString::number( pcShader->classBreakMax2() ), QColor( 255, 255, 0 ) ) ); - symbolList.push_back( qMakePair( QString::number( pcShader->maximumValue() ), QColor( 255, 0, 0 ) ) ); - } - break; - } - case FreakOutShader: - { - const QgsFreakOutShader* foShader = dynamic_cast( mRasterShader->rasterShaderFunction() ); - if ( foShader ) - { - symbolList.push_back( qMakePair( QString::number( foShader->classBreakMin1() ), QColor( 255, 0, 255 ) ) ); - symbolList.push_back( qMakePair( QString::number( foShader->classBreakMax1() ), QColor( 0, 255, 255 ) ) ); - symbolList.push_back( qMakePair( QString::number( foShader->classBreakMax2() ), QColor( 255, 0, 0 ) ) ); - symbolList.push_back( qMakePair( QString::number( foShader->maximumValue() ), QColor( 0, 255, 0 ) ) ); - } - break; - } - default: - { - break; - } - } - } - return symbolList; -#endif //0 } -/** - * @param theBand the band number for which to get the maximum pixel value - * @return the maximum pixel value - */ -double QgsRasterLayer::maximumValue( unsigned int theBand ) -{ - if ( 0 < theBand && theBand <= bandCount() ) - { - return mContrastEnhancementList[theBand - 1].maximumValue(); - } - - return 0.0; -} - -/** - * @param theBand the band name for which to get the maximum pixel value - * @return the maximum pixel value - */ -double QgsRasterLayer::maximumValue( QString theBand ) -{ - if ( theBand != tr( "Not Set" ) ) - { - return maximumValue( bandNumber( theBand ) ); - } - - return 0.0; -} - - QString QgsRasterLayer::metadata() { QString myMetadata ; @@ -1141,8 +497,6 @@ QString QgsRasterLayer::metadata() // Insert provider-specific (e.g. WMS-specific) metadata // crashing - //QString s = mDataProvider->metadata(); - //QgsDebugMsg( s ); myMetadata += mDataProvider->metadata(); myMetadata += "

"; @@ -1168,38 +522,38 @@ QString QgsRasterLayer::metadata() //just use the first band switch ( mDataProvider->srcDataType( 1 ) ) { - case GDT_Byte: - myMetadata += tr( "GDT_Byte - Eight bit unsigned integer" ); + case QGis::Byte: + myMetadata += tr( "Byte - Eight bit unsigned integer" ); break; - case GDT_UInt16: - myMetadata += tr( "GDT_UInt16 - Sixteen bit unsigned integer " ); + case QGis::UInt16: + myMetadata += tr( "UInt16 - Sixteen bit unsigned integer " ); break; - case GDT_Int16: - myMetadata += tr( "GDT_Int16 - Sixteen bit signed integer " ); + case QGis::Int16: + myMetadata += tr( "Int16 - Sixteen bit signed integer " ); break; - case GDT_UInt32: - myMetadata += tr( "GDT_UInt32 - Thirty two bit unsigned integer " ); + case QGis::UInt32: + myMetadata += tr( "UInt32 - Thirty two bit unsigned integer " ); break; - case GDT_Int32: - myMetadata += tr( "GDT_Int32 - Thirty two bit signed integer " ); + case QGis::Int32: + myMetadata += tr( "Int32 - Thirty two bit signed integer " ); break; - case GDT_Float32: - myMetadata += tr( "GDT_Float32 - Thirty two bit floating point " ); + case QGis::Float32: + myMetadata += tr( "Float32 - Thirty two bit floating point " ); break; - case GDT_Float64: - myMetadata += tr( "GDT_Float64 - Sixty four bit floating point " ); + case QGis::Float64: + myMetadata += tr( "Float64 - Sixty four bit floating point " ); break; - case GDT_CInt16: - myMetadata += tr( "GDT_CInt16 - Complex Int16 " ); + case QGis::CInt16: + myMetadata += tr( "CInt16 - Complex Int16 " ); break; - case GDT_CInt32: - myMetadata += tr( "GDT_CInt32 - Complex Int32 " ); + case QGis::CInt32: + myMetadata += tr( "CInt32 - Complex Int32 " ); break; - case GDT_CFloat32: - myMetadata += tr( "GDT_CFloat32 - Complex Float32 " ); + case QGis::CFloat32: + myMetadata += tr( "CFloat32 - Complex Float32 " ); break; - case GDT_CFloat64: - myMetadata += tr( "GDT_CFloat64 - Complex Float64 " ); + case QGis::CFloat64: + myMetadata += tr( "CFloat64 - Complex Float64 " ); break; default: myMetadata += tr( "Could not determine raster data type." ); @@ -1345,29 +699,6 @@ QString QgsRasterLayer::metadata() return myMetadata; } -/** - * @param theBand the band number for which to get the minimum pixel value - * @return the minimum pixel value - */ -double QgsRasterLayer::minimumValue( unsigned int theBand ) -{ - if ( 0 < theBand && theBand <= bandCount() ) - { - return mContrastEnhancementList[theBand - 1].minimumValue(); - } - - return 0.0; -} - -/** - * @param theBand the band name for which to get the minimum pixel value - * @return the minimum pixel value - */ -double QgsRasterLayer::minimumValue( QString theBand ) -{ - return minimumValue( bandNumber( theBand ) ); -} - /** * @param theBandNumber the number of the band to use for generating a pixmap of the associated palette * @return a 100x100 pixel QPixmap of the bands palette @@ -1377,17 +708,13 @@ QPixmap QgsRasterLayer::paletteAsPixmap( int theBandNumber ) //TODO: This function should take dimensions QgsDebugMsg( "entered." ); - // Only do this for the non-provider (hard-coded GDAL) scenario... + // Only do this for the GDAL provider? // Maybe WMS can do this differently using QImage::numColors and QImage::color() - if ( mProviderKey.isEmpty() && hasBand( "Palette" ) && theBandNumber > 0 ) //don't tr() this its a gdal word! + if ( mDataProvider->colorInterpretation( theBandNumber ) == QgsRasterDataProvider::PaletteIndex ) { QgsDebugMsg( "....found paletted image" ); QgsColorRampShader myShader; - //QList myColorRampItemList = myShader.colorRampItemList(); - - //if ( readColorTable( 1, &myColorRampItemList ) ) - QList myColorRampItemList = mDataProvider->colorTable( 1 ); - // TODO: add CT capability? It can depends on band (?) + QList myColorRampItemList = mDataProvider->colorTable( theBandNumber ); if ( myColorRampItemList.size() > 0 ) { QgsDebugMsg( "....got color ramp item list" ); @@ -1432,14 +759,7 @@ QPixmap QgsRasterLayer::paletteAsPixmap( int theBandNumber ) QString QgsRasterLayer::providerType() const { - if ( mProviderKey.isEmpty() ) - { - return QString(); - } - else - { - return mProviderKey; - } + return mProviderKey; } /** @@ -1463,23 +783,10 @@ double QgsRasterLayer::rasterUnitsPerPixel() void QgsRasterLayer::init() { - // keep this until mGeoTransform occurences are removed! - mGeoTransform[0] = 0; - mGeoTransform[1] = 1; - mGeoTransform[2] = 0; - mGeoTransform[3] = 0; - mGeoTransform[4] = 0; - mGeoTransform[5] = -1; - - mRasterType = QgsRasterLayer::GrayOrUndefined; setDrawingStyle( QgsRasterLayer::UndefinedDrawingStyle ); - mBandCount = 0; - //mNoDataValue = -9999.0; - //mValidNoDataValue = false; - //Initialize the last view port structure, should really be a class mLastViewPort.drawableAreaXDim = 0; mLastViewPort.drawableAreaYDim = 0; @@ -1503,7 +810,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider ) setLayerName( mLayerName ); } - mBandCount = 0; + //mBandCount = 0; mDataProvider = ( QgsRasterDataProvider* )QgsProviderRegistry::instance()->provider( mProviderKey, mDataSource ); if ( !mDataProvider ) @@ -1529,8 +836,6 @@ void QgsRasterLayer::setDataProvider( QString const & provider ) mDataSource = mDataProvider->dataSourceUri(); } - //setNoDataValue( mDataProvider->noDataValue() ); - // get the extent QgsRectangle mbr = mDataProvider->extent(); @@ -1540,18 +845,11 @@ void QgsRasterLayer::setDataProvider( QString const & provider ) // store the extent setExtent( mbr ); - mWidth = mDataProvider->xSize(); - mHeight = mDataProvider->ySize(); - - // upper case the first letter of the layer name QgsDebugMsg( "mLayerName: " + name() ); - //mValidNoDataValue = mDataProvider->isNoDataValueValid(); - // set up the raster drawing style // Do not set any 'sensible' style here, the style is set later - // setDrawingStyle( MultiBandColor ); //sensible default // Setup source CRS setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) ); @@ -1560,34 +858,10 @@ void QgsRasterLayer::setDataProvider( QString const & provider ) QgsDebugMsg( "using wkt:\n" + mySourceWkt ); - mBandCount = mDataProvider->bandCount( ); - for ( int i = 1; i <= mBandCount; i++ ) - { -#if 0 - QgsRasterBandStats myRasterBandStats; - myRasterBandStats.bandName = mDataProvider->generateBandName( i ); - myRasterBandStats.bandNumber = i; - myRasterBandStats.statsGathered = false; - //Store the default color table - //readColorTable( i, &myRasterBandStats.colorTable ); - QList ct; - ct = mDataProvider->colorTable( i ); - myRasterBandStats.colorTable = ct; - - mRasterStatsList.push_back( myRasterBandStats ); -#endif - - //Build a new contrast enhancement for the band and store in list - //QgsContrastEnhancement myContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )mDataProvider->dataType( i ) ); - QgsContrastEnhancement myContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )mDataProvider->srcDataType( i ) ); - mContrastEnhancementList.append( myContrastEnhancement ); - } - //defaults - Needs to be set after the Contrast list has been build //Try to read the default contrast enhancement from the config file QSettings myQSettings; - //setContrastEnhancementAlgorithm( myQSettings.value( "/Raster/defaultContrastEnhancementAlgorithm", "NoEnhancement" ).toString() ); //decide what type of layer this is... //TODO Change this to look at the color interp and palette interp to decide which type of layer it is @@ -1602,11 +876,6 @@ void QgsRasterLayer::setDataProvider( QString const & provider ) { mRasterType = ColorLayer; } - //TODO hasBand is really obsolete and only used in the Palette instance, change to new function hasPalette(int) - //else if ( hasBand( "Palette" ) ) //don't tr() this its a gdal word! - // not sure if is worth to add colorTable capability - CT can be empty in any case - // Calc bandStatistics is very slow!!! - //else if ( bandStatistics(1).colorTable.count() > 0 ) else if ( mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::PaletteIndex ) { mRasterType = Palette; @@ -1734,12 +1003,6 @@ void QgsRasterLayer::closeDataProvider() mValid = false; mPipe.remove( mDataProvider ); mDataProvider = 0; - mContrastEnhancementList.clear(); -} - -void QgsRasterLayer::setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm, bool theGenerateLookupTableFlag ) -{ - setContrastEnhancementAlgorithm( theAlgorithm, ContrastEnhancementMinMax, QgsRectangle(), SAMPLE_SIZE, theGenerateLookupTableFlag ); } void QgsRasterLayer::setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm, ContrastEnhancementLimits theLimits, QgsRectangle theExtent, int theSampleSize, bool theGenerateLookupTableFlag ) @@ -1750,8 +1013,6 @@ void QgsRasterLayer::setContrastEnhancementAlgorithm( QgsContrastEnhancement::Co return; } - mContrastEnhancementAlgorithm = theAlgorithm; - QList myBands; QList myEnhancements; QgsSingleBandGrayRenderer* myGrayRenderer = 0; @@ -1783,9 +1044,6 @@ void QgsRasterLayer::setContrastEnhancementAlgorithm( QgsContrastEnhancement::Co if ( theLimits == ContrastEnhancementMinMax ) { - // minimumValue/maximumValue are not well defined (estimation) and will be removed - //myMin = mDataProvider->minimumValue( myBand ); - //myMax = mDataProvider->maximumValue( myBand ); QgsRasterBandStats myRasterBandStats = mDataProvider->bandStatistics( myBand, QgsRasterBandStats::Min | QgsRasterBandStats::Max, theExtent, theSampleSize ); myMin = myRasterBandStats.minimumValue; myMax = myRasterBandStats.maximumValue; @@ -1829,49 +1087,6 @@ void QgsRasterLayer::setContrastEnhancementAlgorithm( QgsContrastEnhancement::Co } } -void QgsRasterLayer::setContrastEnhancementAlgorithm( QString theAlgorithm, bool theGenerateLookupTableFlag ) -{ - QgsDebugMsg( "called with [" + theAlgorithm + "] and flag=" + QString::number(( int )theGenerateLookupTableFlag ) ); - - if ( theAlgorithm == "NoEnhancement" ) - { - setContrastEnhancementAlgorithm( QgsContrastEnhancement::NoEnhancement, theGenerateLookupTableFlag ); - } - else if ( theAlgorithm == "StretchToMinimumMaximum" ) - { - setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum, theGenerateLookupTableFlag ); - } - else if ( theAlgorithm == "StretchAndClipToMinimumMaximum" ) - { - setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchAndClipToMinimumMaximum, theGenerateLookupTableFlag ); - } - else if ( theAlgorithm == "ClipToMinimumMaximum" ) - { - setContrastEnhancementAlgorithm( QgsContrastEnhancement::ClipToMinimumMaximum, theGenerateLookupTableFlag ); - } - else if ( theAlgorithm == "UserDefined" ) - { - setContrastEnhancementAlgorithm( QgsContrastEnhancement::UserDefinedEnhancement, theGenerateLookupTableFlag ); - } - else - { - setContrastEnhancementAlgorithm( QgsContrastEnhancement::NoEnhancement, theGenerateLookupTableFlag ); - } -} - -void QgsRasterLayer::setContrastEnhancementFunction( QgsContrastEnhancementFunction* theFunction ) -{ - if ( theFunction ) - { - QList::iterator myIterator = mContrastEnhancementList.begin(); - while ( myIterator != mContrastEnhancementList.end() ) - { - ( *myIterator ).setContrastEnhancementFunction( theFunction ); - ++myIterator; - } - } -} - void QgsRasterLayer::setDefaultContrastEnhancement() { QgsDebugMsg( QString( "mDrawingStyle = %1" ).arg( mDrawingStyle ) ); @@ -2026,46 +1241,6 @@ void QgsRasterLayer::setLayerOrder( QStringList const & layers ) } -void QgsRasterLayer::setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag ) -{ - QgsDebugMsg( "setMaximumValue theValue = " + QString::number( theValue ) ); - if ( 0 < theBand && theBand <= bandCount() ) - { - mContrastEnhancementList[theBand - 1].setMaximumValue( theValue, theGenerateLookupTableFlag ); - } -} - -void QgsRasterLayer::setMinimumMaximumUsingLastExtent() -{ - //legacy method -} - -void QgsRasterLayer::setMinimumMaximumUsingDataset() -{ - //legacy method -} - -#if 0 -void QgsRasterLayer::setNoDataValue( double theNoDataValue ) -{ - if ( theNoDataValue != mNoDataValue ) - { - mNoDataValue = theNoDataValue; - mValidNoDataValue = true; - //Basically set the raster stats as invalid - // TODO! No data value must be set on provider and stats cleared -#if 0 - QList::iterator myIterator = mRasterStatsList.begin(); - while ( myIterator != mRasterStatsList.end() ) - { - ( *myIterator ).statsGathered = false; - ++myIterator; - } -#endif - } -} -#endif - void QgsRasterLayer::setSubLayerVisibility( QString name, bool vis ) { @@ -2084,20 +1259,6 @@ void QgsRasterLayer::setRenderer( QgsRasterRenderer* theRenderer ) mPipe.set( theRenderer ); } -#if 0 -// not sure if we want it -void QgsRasterLayer::setResampleFilter( QgsRasterResampleFilter* resampleFilter ) -{ - QgsDebugMsg( "Entered" ); - if ( !resampleFilter ) { return; } - if ( !mPipe.set( resampleFilter ) ) - { - // TODO: somehow notify (and delete?) - QgsDebugMsg( "Cannot set resample filter." ); - } -} -#endif - void QgsRasterLayer::showProgress( int theValue ) { emit progressUpdate( theValue ); @@ -2113,13 +1274,11 @@ void QgsRasterLayer::showStatusMessage( QString const & theMessage ) emit statusChanged( theMessage ); } - QStringList QgsRasterLayer::subLayers() const { return mDataProvider->subLayers(); } - QPixmap QgsRasterLayer::previewAsPixmap( QSize size, QColor bgColor ) { QPixmap myQPixmap( size ); @@ -2146,16 +1305,10 @@ QPixmap QgsRasterLayer::previewAsPixmap( QSize size, QColor bgColor ) double myPixelWidth = myExtent.width() / myMapUnitsPerPixel; double myPixelHeight = myExtent.height() / myMapUnitsPerPixel; - //myRasterViewPort->topLeftPoint = QgsPoint( 0, 0 ); myRasterViewPort->topLeftPoint = QgsPoint( myX, myY ); - - //myRasterViewPort->bottomRightPoint = QgsPoint( myQPixmap.width(), myQPixmap.height() ); - myRasterViewPort->bottomRightPoint = QgsPoint( myPixelWidth, myPixelHeight ); myRasterViewPort->drawableAreaXDim = myQPixmap.width(); myRasterViewPort->drawableAreaYDim = myQPixmap.height(); - //myRasterViewPort->drawableAreaXDim = myPixelWidth; - //myRasterViewPort->drawableAreaYDim = myPixelHeight; myRasterViewPort->mDrawnExtent = myExtent; myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid @@ -2173,36 +1326,6 @@ QPixmap QgsRasterLayer::previewAsPixmap( QSize size, QColor bgColor ) return myQPixmap; } -#if 0 -void QgsRasterLayer::thumbnailAsImage( QImage * thepImage ) -{ - //TODO: This should be depreciated and a new function written that just returns a new QImage, it will be safer - // removed as it's not used anywhere, use previewAsPixmap() instead - if ( !thepImage ) - return; - - - thepImage->fill( Qt::white ); //defaults to white - - // Raster providers are disabled (for the moment) - if ( mProviderKey.isEmpty() ) - { - QgsRasterViewPort *myRasterViewPort = new QgsRasterViewPort(); - myRasterViewPort->topLeftPoint = QgsPoint( 0, 0 ); - myRasterViewPort->bottomRightPoint = QgsPoint( thepImage->width(), thepImage->height() ); - myRasterViewPort->drawableAreaXDim = thepImage->width(); - myRasterViewPort->drawableAreaYDim = thepImage->height(); - - QPainter * myQPainter = new QPainter( thepImage ); - draw( myQPainter, myRasterViewPort ); - delete myRasterViewPort; - myQPainter->end(); - delete myQPainter; - } - -} -#endif - void QgsRasterLayer::triggerRepaint() { emit repaintRequested(); @@ -2248,10 +1371,10 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe } //rasterlayerproperties element there -> old format (1.8 and early 1.9) - if ( !pipeNode.firstChildElement( "rasterproperties" ).isNull() ) + if ( !layer_node.firstChildElement( "rasterproperties" ).isNull() ) { //copy node because layer_node is const - QDomNode layerNodeCopy = pipeNode.cloneNode(); + QDomNode layerNodeCopy = layer_node.cloneNode(); QDomDocument doc = layerNodeCopy.ownerDocument(); QDomElement rasterPropertiesElem = layerNodeCopy.firstChildElement( "rasterproperties" ); QgsProjectFileTransform::convertRasterProperties( doc, layerNodeCopy, rasterPropertiesElem, @@ -2495,35 +1618,6 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum layer_node.appendChild( pipeElement ); -#if 0 - QgsRasterRenderer *renderer = mPipe.renderer(); - if ( renderer ) - { - renderer->writeXML( document, layerElem ); - } - - QgsBrightnessContrastFilter *brightnessFilter = mPipe.brightnessFilter(); - if ( brightnessFilter ) - { - QDomElement layerElem = layer_node.toElement(); - brightnessFilter->writeXML( document, layerElem ); - } - - QgsHueSaturationFilter *hueSaturationFilter = mPipe.hueSaturationFilter(); - if ( hueSaturationFilter ) - { - QDomElement layerElem = layer_node.toElement(); - hueSaturationFilter->writeXML( document, layerElem ); - } - - QgsRasterResampleFilter *resampleFilter = mPipe.resampleFilter(); - if ( resampleFilter ) - { - QDomElement layerElem = layer_node.toElement(); - resampleFilter->writeXML( document, layerElem ); - } -#endif - // add blend mode node QDomElement blendModeElement = document.createElement( "blendMode" ); QDomText blendModeText = document.createTextNode( QString::number( QgsMapRenderer::getBlendModeEnum( blendMode() ) ) ); @@ -2592,151 +1686,23 @@ bool QgsRasterLayer::writeXml( QDomNode & layer_node, return writeSymbology( layer_node, document, errorMsg ); } +int QgsRasterLayer::width() const +{ + if ( !mDataProvider ) return 0; + return mDataProvider->xSize(); +} + +int QgsRasterLayer::height() const +{ + if ( !mDataProvider ) return 0; + return mDataProvider->ySize(); +} + ////////////////////////////////////////////////////////// // // Private methods // ///////////////////////////////////////////////////////// - - -#if 0 -QString QgsRasterLayer::generateBandName( int theBandNumber ) -{ - return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) ); -} -#endif - -/** - * This method looks to see if a given band name exists. - *@note This function is no longer really needed and about to be removed - */ -bool QgsRasterLayer::hasBand( QString const & theBandName ) -{ - //TODO: This function is no longer really needed and about be removed - //-- it is only used to see if "Palette" exists which is not the correct way to see if a band is paletted or not - QgsDebugMsg( "Looking for band : " + theBandName ); - - for ( int i = 1; i <= mDataProvider->bandCount(); i++ ) - { - QString myColorQString = mDataProvider->colorInterpretationName( i ); - QgsDebugMsgLevel( QString( "band%1" ).arg( i ), 2 ); - - if ( myColorQString == theBandName ) - { - QgsDebugMsgLevel( QString( "band%1" ).arg( i ), 2 ); - QgsDebugMsgLevel( "Found band : " + theBandName, 2 ); - - return true; - } - QgsDebugMsgLevel( "Found unmatched band : " + QString::number( i ) + " " + myColorQString, 2 ); - } - return false; -} - -QString QgsRasterLayer::projectionWkt() -{ - // TODO: where is it used? It would be better to use crs. - return mDataProvider->crs().toWkt(); -} - -/* - *data type is the same as raster band. The memory must be released later! - * \return pointer to the memory - */ -#if 0 -void *QgsRasterLayer::readData( int bandNo, QgsRasterViewPort *viewPort ) -{ - int size = mDataProvider->dataTypeSize( bandNo ); - -#if 0 - QgsDebugMsg( "calling RasterIO with " + - QString( ", source NW corner: " ) + QString::number( viewPort->rectXOffset ) + - ", " + QString::number( viewPort->rectYOffset ) + - ", source size: " + QString::number( viewPort->clippedWidth ) + - ", " + QString::number( viewPort->clippedHeight ) + - ", dest size: " + QString::number( viewPort->drawableAreaXDim ) + - ", " + QString::number( viewPort->drawableAreaYDim ) ); -#endif - void *data = qgsMalloc( size * viewPort->drawableAreaXDim * viewPort->drawableAreaYDim ); - - /* Abort if out of memory */ - if ( data == NULL ) - { - QgsDebugMsg( "Layer " + name() + " couldn't allocate enough memory. Ignoring" ); - } - else - { - // TODO: check extent - QgsRectangle partExtent( - viewPort->mDrawnExtent.xMinimum(), - viewPort->mDrawnExtent.yMinimum(), - viewPort->mDrawnExtent.xMaximum(), - viewPort->mDrawnExtent.yMaximum() - ); - mDataProvider->readBlock( bandNo, partExtent, - viewPort->drawableAreaXDim, - viewPort->drawableAreaYDim, - viewPort->mSrcCRS, - viewPort->mDestCRS, data ); - } - return data; -} -#endif - -/* - * @note Called from ctor if a raster image given there - * - * @param theFilename absolute path and filename of the raster to be loaded - * @returns true if successfully read file - */ -bool QgsRasterLayer::readFile( QString const &theFilename ) -{ - Q_UNUSED( theFilename ); - mValid = false; - return true; -} // QgsRasterLayer::readFile - -/* - * @param index index in memory block - */ -#if 0 -double QgsRasterLayer::readValue( void *data, int type, int index ) -{ - if ( !data ) - return mValidNoDataValue ? mNoDataValue : 0.0; - - switch ( type ) - { - case QgsRasterDataProvider::Byte: - return ( double )(( GByte * )data )[index]; - break; - case QgsRasterDataProvider::UInt16: - return ( double )(( GUInt16 * )data )[index]; - break; - case QgsRasterDataProvider::Int16: - return ( double )(( GInt16 * )data )[index]; - break; - case QgsRasterDataProvider::UInt32: - return ( double )(( GUInt32 * )data )[index]; - break; - case QgsRasterDataProvider::Int32: - return ( double )(( GInt32 * )data )[index]; - break; - case QgsRasterDataProvider::Float32: - return ( double )(( float * )data )[index]; - break; - case QgsRasterDataProvider::Float64: - return ( double )(( double * )data )[index]; - break; - default: - QgsMessageLog::logMessage( tr( "GDAL data type %1 is not supported" ).arg( type ), tr( "Raster" ) ); - break; - } - - return mValidNoDataValue ? mNoDataValue : 0.0; -} -#endif - bool QgsRasterLayer::update() { QgsDebugMsg( "entered." ); @@ -2751,96 +1717,3 @@ bool QgsRasterLayer::update() } return mValid; } - -QString QgsRasterLayer::validateBandName( QString const & theBandName ) -{ - QgsDebugMsg( "Checking..." ); - //check if the band is unset - if ( theBandName == TRSTRING_NOT_SET || theBandName == QSTRING_NOT_SET ) - { - QgsDebugMsg( "Band name is '" + QSTRING_NOT_SET + "'. Nothing to do." ); - // Use translated name internally - return TRSTRING_NOT_SET; - } - - if ( !mDataProvider ) return TRSTRING_NOT_SET; - - //check that a valid band name was passed - QgsDebugMsg( "Looking through raster band stats for matching band name" ); - for ( int myIterator = 1; myIterator < mDataProvider->bandCount(); ++myIterator ) - { - //find out the name of this band - if ( mDataProvider->generateBandName( myIterator ) == theBandName ) - { - QgsDebugMsg( "Matching band name found" ); - return theBandName; - } - } - QgsDebugMsg( "No matching band name found in raster band stats" ); - -#if 0 - QgsDebugMsg( "Testing for non zero-buffered names" ); - //TODO Remove test in v2.0 or earlier - QStringList myBandNameComponents = theBandName.split( " " ); - if ( myBandNameComponents.size() == 2 ) - { - int myBandNumber = myBandNameComponents.at( 1 ).toInt(); - if ( myBandNumber > 0 ) - { - QString myBandName = mDataProvider->generateBandName( myBandNumber ); - for ( int myIterator = 0; myIterator < mRasterStatsList.size(); ++myIterator ) - { - //find out the name of this band - if ( mRasterStatsList[myIterator].bandName == myBandName ) - { - QgsDebugMsg( "Matching band name found" ); - return myBandName; - } - } - } - } - - QgsDebugMsg( "Testing older naming format" ); - //See of the band in an older format #:something. - //TODO Remove test in v2.0 or earlier - myBandNameComponents.clear(); - if ( theBandName.contains( ':' ) ) - { - myBandNameComponents = theBandName.split( ":" ); - if ( myBandNameComponents.size() == 2 ) - { - int myBandNumber = myBandNameComponents.at( 0 ).toInt(); - if ( myBandNumber > 0 ) - { - QgsDebugMsg( "Transformed older name format to current format" ); - return "Band " + QString::number( myBandNumber ); - } - } - } -#endif - - //if no matches were found default to not set - QgsDebugMsg( "All checks failed, returning '" + QSTRING_NOT_SET + "'" ); - return TRSTRING_NOT_SET; -} - -// Keep this for now, it is used by Python interface!!! -void QgsRasterLayer::registerGdalDrivers() -{ - if ( GDALGetDriverCount() == 0 ) - GDALAllRegister(); -} - -// Keep this for QgsRasterLayerProperties -bool QgsRasterLayer::readColorTable( int theBandNumber, QList* theList ) -{ - // TODO : check if exists - returned vale? - QList myColorRampItemList = mDataProvider->colorTable( theBandNumber ); - if ( myColorRampItemList.size() == 0 ) - { - return false; - } - *theList = myColorRampItemList; - return true; -} - diff --git a/src/core/raster/qgsrasterlayer.h b/src/core/raster/qgsrasterlayer.h index eae2a830ca5..85eaf8e4f9d 100644 --- a/src/core/raster/qgsrasterlayer.h +++ b/src/core/raster/qgsrasterlayer.h @@ -21,43 +21,36 @@ #ifndef QGSRASTERLAYER_H #define QGSRASTERLAYER_H -// -// Includes -// - #include #include -#include #include #include #include +#include #include "qgis.h" -#include "qgspoint.h" -#include "qgsmaplayer.h" -#include "qgsrasterviewport.h" -#include "qgscontrastenhancement.h" -#include "qgsrastertransparency.h" -#include "qgsrastershader.h" -#include "qgscolorrampshader.h" -#include "qgsrastershaderfunction.h" -#include "qgsrasterinterface.h" -#include "qgsrasterresamplefilter.h" #include "qgsbrightnesscontrastfilter.h" +#include "qgscolorrampshader.h" +#include "qgscontrastenhancement.h" #include "qgshuesaturationfilter.h" +#include "qgsmaplayer.h" +#include "qgspoint.h" #include "qgsrasterdataprovider.h" +#include "qgsrasterinterface.h" #include "qgsrasterpipe.h" +#include "qgsrasterresamplefilter.h" +#include "qgsrastershaderfunction.h" +#include "qgsrastershader.h" +#include "qgsrastertransparency.h" +#include "qgsrasterviewport.h" -// -// Forward declarations -// class QgsMapToPixel; -class QgsRectangle; class QgsRasterRenderer; +class QgsRectangle; class QImage; +class QLibrary; class QPixmap; class QSlider; -class QLibrary; /** \ingroup core * This class provides qgis with the ability to render raster datasets @@ -215,10 +208,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer /** \brief The destructor */ ~QgsRasterLayer(); - - // - // Enums, structs and typedefs - // /** \brief This enumerator describes the types of shading that can be used */ enum ColorShadingAlgorithm { @@ -263,26 +252,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer ContrastEnhancementCumulativeCut }; - /** \brief A list containing on ContrastEnhancement object per raster band in this raster layer */ - typedef QList ContrastEnhancementList; - - /** \brief A list containing one RasterPyramid struct per raster band in this raster layer. - * POTENTIAL pyramid layer. This works by dividing the height - * and width of the raster by an incrementing number. As soon as the result - * of the division is <=256 we stop allowing RasterPyramid structs - * to be added to the list. Each time a RasterPyramid is created - * we will check to see if a pyramid matching these dimensions already exists - * in the raster layer, and if so mark the exists flag as true */ - /* typedef QList RasterPyramidList; */ - - /** \brief A list containing one RasterBandStats struct per raster band in this raster layer. - * Note that while every RasterBandStats element will have the name and number of its associated - * band populated, any additional stats are calculated on a need to know basis.*/ - /* typedef QList RasterStatsList; */ - - // - // Static methods: - // static void buildSupportedRasterFileFilter( QString & fileFilters ); /** This helper checks to see whether the file name appears to be a valid @@ -292,76 +261,27 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer */ static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError ); static bool isValidRasterFileName( const QString & theFileNameQString ); - //static QStringList subLayers( GDALDatasetH dataset ); /** Return time stamp for given file name */ static QDateTime lastModified( const QString & name ); - // Keep this for now, it is used by Python interface!!! - /** \brief ensures that GDAL drivers are registered, but only once */ - static void registerGdalDrivers(); - - // - // Non Static inline methods - // - - /** \brief Initialize default values */ - void init(); - /** [ data provider interface ] Set the data provider */ void setDataProvider( const QString & provider ); - /** \brief Accessor for blue band name mapping */ - QString blueBandName() const { return mBlueBandName; } - - /** \brief Accessor for color shader algorithm */ - QgsRasterLayer::ColorShadingAlgorithm colorShadingAlgorithm() const { return mColorShadingAlgorithm; } - - /** \brief Accessor for contrast enhancement algorithm */ - QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() { return mContrastEnhancementAlgorithm; } - - /** \brief Returns contrast enhancement algorithm as a string */ - QString contrastEnhancementAlgorithmAsString() const; - /** \brief Accessor for drawing style */ DrawingStyle drawingStyle() { return mDrawingStyle; } - /** \brief Accessor for mHasPyramids (READ ONLY) */ - /* bool hasPyramids() { return dataProvider() != NULL ? dataProvider()->hasPyramids() : false ; } */ - - /** \brief Accessor for mUserDefinedGrayMinimumMaximum */ - bool hasUserDefinedGrayMinimumMaximum() const { return mUserDefinedGrayMinimumMaximum; } - - /** \brief Accessor for mUserDefinedRGBMinimumMaximum */ - bool hasUserDefinedRGBMinimumMaximum() const { return mUserDefinedRGBMinimumMaximum; } - - /** \brief Accessor that returns the height of the (unclipped) raster */ - int height() { return mHeight; } - /** \brief Accessor for raster layer type (which is a read only property) */ LayerType rasterType() { return mRasterType; } - /** \brief Mutator for drawing style */ void setDrawingStyle( const DrawingStyle & theDrawingStyle ) { mDrawingStyle = theDrawingStyle; setRendererForDrawingStyle( theDrawingStyle ); } - /**Sets corresponding renderer for style*/ - void setRendererForDrawingStyle( const DrawingStyle & theDrawingStyle ); - - /** \brief Mutator to alter the number of standard deviations that should be plotted */ - void setStandardDeviations( double theStandardDeviations ) { mStandardDeviations = theStandardDeviations; } - - /** \brief Mutator for mUserDefinedGrayMinimumMaximum */ - void setUserDefinedGrayMinimumMaximum( bool theBool ) { mUserDefinedGrayMinimumMaximum = theBool; } - - /** \brief Mutator for mUserDefinedRGBMinimumMaximum */ - void setUserDefinedRGBMinimumMaximum( bool theBool ) { mUserDefinedRGBMinimumMaximum = theBool; } /**Set raster renderer. Takes ownership of the renderer object*/ void setRenderer( QgsRasterRenderer* theRenderer ); QgsRasterRenderer* renderer() const { return mPipe.renderer(); } /**Set raster resample filter. Takes ownership of the resample filter object*/ - //void setResampleFilter( QgsRasterResampleFilter* resampleFilter ); QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); } QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); } @@ -370,48 +290,18 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer /** Get raster pipe */ QgsRasterPipe * pipe() { return &mPipe; } - /** \brief Accessor to find out how many standard deviations are being plotted */ - double standardDeviations() const { return mStandardDeviations; } - /** \brief Accessor that returns the width of the (unclipped) raster */ - int width() { return mWidth; } + int width() const; + + /** \brief Accessor that returns the height of the (unclipped) raster */ + int height() const; - // - // Non Static methods - // /** \brief Get the number of bands in this layer */ - unsigned int bandCount() const; + int bandCount() const; /** \brief Get the name of a band given its number */ const QString bandName( int theBandNoInt ); - /** \brief Get the number of a band given its name. The name is the rewritten name set - * up in the constructor, and will not necessarily be the same as the name retrieved directly from gdal! - * If no matching band is found zero will be returned! */ - int bandNumber( const QString & theBandName ) const; - - /** \brief Accessor for ths raster layers pyramid list. A pyramid list defines the - * POTENTIAL pyramids that can be in a raster. To know which of the pyramid layers - * ACTUALLY exists you need to look at the existsFlag member in each struct stored in the - * list. - */ - // RasterPyramidList buildPyramidList(); - - /** \brief Accessor for color shader algorithm */ - QString colorShadingAlgorithmAsString() const; - - /** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent - \note added in v1.6 */ - //void computeMinimumMaximumFromLastExtent( int theBand, double& theMin, double& theMax ); - - /** \brief Get a pointer to the contrast enhancement for the selected band */ - QgsContrastEnhancement* contrastEnhancement( unsigned int theBand ); - - const QgsContrastEnhancement* constContrastEnhancement( unsigned int theBand ) const; - - /** \brief Get a pointer to the color table */ - QList colorTable( int theBandNoInt ); - /** Returns the data provider */ QgsRasterDataProvider* dataProvider(); @@ -432,32 +322,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer QgsRasterViewPort * myRasterViewPort, const QgsMapToPixel* theQgsMapToPixel = 0 ); - /** \brief Returns a string representation of drawing style - * - * Implemented mainly for serialisation / deserialisation of settings to xml. - * NOTE: May be deprecated in the future!. DrawingStyle drawingStyle() instead. - * */ - QString drawingStyleAsString() const; - - /** \brief Identify raster value(s) found on the point position */ - //bool identify( const QgsPoint & point, QMap& results ); - - /** \brief Identify raster value(s) found on the point position - * @note available in python bindings as identifyMap - */ - //bool identify( const QgsPoint & point, QMap& results ); - - /** \brief Identify arbitrary details from the WMS server found on the point position */ - //QString identifyAsText( const QgsPoint & point ); - - /** \brief Identify arbitrary details from the WMS server found on the point position - * @note added in 1.5 - */ - //QString identifyAsHtml( const QgsPoint & point ); - - /** \brief Currently returns always false */ - bool isEditable() const; - /** \brief [ data provider interface ] If an operation returns 0 (e.g. draw()), this function returns the text of the error associated with the failure */ QString lastError(); @@ -468,21 +332,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer @note this method was added in version 1.8*/ QList< QPair< QString, QColor > > legendSymbologyItems() const; - /** \brief Accessor for maximum value user for contrast enhancement */ - double maximumValue( unsigned int theBand ); - - /** \brief Accessor for maximum value user for contrast enhancement */ - double maximumValue( QString theBand ); - /** \brief Obtain GDAL Metadata for this layer */ QString metadata(); - /** \brief Accessor for minimum value user for contrast enhancement */ - double minimumValue( unsigned int theBand ); - - /** \brief Accessor for minimum value user for contrast enhancement */ - double minimumValue( QString theBand ); - /** \brief Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned */ QPixmap paletteAsPixmap( int theBandNumber = 1 ); @@ -494,24 +346,10 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer /** \brief Returns the number of raster units per each raster pixel. In a world file, this is normally the first row (without the sign) */ double rasterUnitsPerPixel(); - /** \brief Read color table from GDAL raster band */ - // Keep this for QgsRasterLayerProperties - // @note not available in python bindings - bool readColorTable( int theBandNumber, QList* theList ); - - /** \brief Simple reset function that set the noDataValue back to the value stored in the first raster band */ - //void resetNoDataValue(); - static QString contrastEnhancementLimitsAsString( QgsRasterLayer::ContrastEnhancementLimits theLimits ); static ContrastEnhancementLimits contrastEnhancementLimitsFromString( QString theLimits ); - /** \brief Mutator for contrast enhancement algorithm using min/max */ - // TODO: remove in 2.0, replaced by following - // @note not available in python bindings - void setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm, - bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator for contrast enhancement algorithm + /** \brief Set contrast enhancement algorithm * @param theAlgorithm Contrast enhancement algorithm * @param theLimits Limits * @param theExtent Extent used to calculate limits, if empty, use full layer extent @@ -525,30 +363,12 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer int theSampleSize = SAMPLE_SIZE, bool theGenerateLookupTableFlag = true ); - /** \brief Mutator for contrast enhancement algorithm */ - void setContrastEnhancementAlgorithm( QString theAlgorithm, bool theGenerateLookupTableFlag = true ); - - /** \brief Mutator for contrast enhancement function */ - void setContrastEnhancementFunction( QgsContrastEnhancementFunction* theFunction ); - /** \brief Set default contrast enhancement */ void setDefaultContrastEnhancement(); /** \brief Overloaded version of the above function for convenience when restoring from xml */ void setDrawingStyle( const QString & theDrawingStyleQString ); - /** \brief Mutator for setting the maximum value for contrast enhancement */ - void setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true ); - - /** \brief Sets the minimum and maximum values for the band(s) currently - * being displayed using the only pixel values from the last/current extent - * */ - void setMinimumMaximumUsingLastExtent(); - - /** \brief Sets the minimum and maximum values for the band(s) currently - * being displayed using the only pixel values from the dataset min/max */ - void setMinimumMaximumUsingDataset(); - /** \brief [ data provider interface ] A wrapper function to emit a progress update signal */ void showProgress( int theValue ); @@ -561,9 +381,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer /** \brief Emit a signal asking for a repaint. (inherited from maplayer) */ void triggerRepaint(); - // - // Virtual methods - // /** * Reorders the *previously selected* sublayers of this layer from bottom to top * @@ -581,11 +398,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer virtual QDateTime timestamp() const { return mDataProvider->timestamp() ; } public slots: - /** \brief Create GDAL pyramid overviews */ - // QString buildPyramids( const RasterPyramidList &, - // const QString & theResamplingMethod = "NEAREST", - // bool theTryInternalFlag = false ); - void showStatusMessage( const QString & theMessage ); /** \brief Propagate progress updates from GDAL up to the parent app */ @@ -605,7 +417,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer void dataChanged(); protected: - /** \brief Read the symbology for the current layer from the Dom node supplied */ bool readSymbology( const QDomNode& node, QString& errorMessage ); @@ -619,187 +430,43 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer bool writeXml( QDomNode & layer_node, QDomDocument & doc ); private: - // - // Private methods - // - /** \brief Drawing routine for color type data */ - void drawSingleBandColorData( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); - - /** \brief Drawing routine for multiband image */ - void drawMultiBandColor( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel ); - - /** \brief Drawing routine for multiband image, rendered as a single band image in grayscale */ - void drawMultiBandSingleBandGray( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); - - /** \brief Drawing routine for multiband image, rendered as a single band image in pseudocolor */ - void drawMultiBandSingleBandPseudoColor( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); - - /** \brief Drawing routine for single band with a color map */ - void drawPalettedSingleBandColor( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); - - /** \brief Drawing routine for paletted image, rendered as a single band image in grayscale */ - void drawPalettedSingleBandGray( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); - - /** \brief Drawing routine for paletted image, rendered as a single band image in pseudocolor */ - void drawPalettedSingleBandPseudoColor( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); - - /** \brief Drawing routine for paletted multiband image */ - void drawPalettedMultiBandColor( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); - - /** \brief Drawing routine for single band grayscale image */ - void drawSingleBandGray( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); - - /** \brief Drawing routine for single band grayscale image, rendered in pseudocolor */ - void drawSingleBandPseudoColor( QPainter * theQPainter, - QgsRasterViewPort * theRasterViewPort, - const QgsMapToPixel* theQgsMapToPixel, - int theBandNoInt ); + /** \brief Initialize default values */ + void init(); /** \brief Close data provider and clear related members */ void closeDataProvider(); - /** \brief helper function to create zero padded band names */ - QString generateBandName( int ); - - /** \brief Find out whether a given band exists. */ - bool hasBand( const QString & theBandName ); - - /** \brief Query GDAL to find out the Wkt projection string for this layer.*/ - QString projectionWkt(); - - /** \brief Allocate memory and load data to that allocated memory */ - //void* readData( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort ); - //void* readData( int bandNo, QgsRasterViewPort *viewPort ); - - /** \brief Load the given raster file */ - bool readFile( const QString & fileName ); - - /** \brief Read a raster value given position from memory block created by readData() */ - //inline double readValue( void *data, GDALDataType type, int index ); - //inline double readValue( void *data, int type, int index ); - /** \brief Update the layer if it is outdated */ bool update(); - /** \brief Verify and transform band name for internal consistency. Return 'Not Set' on any type of failure */ - QString validateBandName( const QString & theBandName ); + /**Sets corresponding renderer for style*/ + void setRendererForDrawingStyle( const DrawingStyle & theDrawingStyle ); - // - // Private member vars - // /** \brief Constant defining flag for XML and a constant that signals property not used */ const QString QSTRING_NOT_SET; const QString TRSTRING_NOT_SET; - /** \brief The number of bands in the dataset */ - int mBandCount; - - /** \brief The band to be associated with the color blue - usually 3 */ - QString mBlueBandName; - - /** \brief The raster shading algorithm being used */ - ColorShadingAlgorithm mColorShadingAlgorithm; - - /** \brief The contrast enhancement algorithm being used */ - QgsContrastEnhancement::ContrastEnhancementAlgorithm mContrastEnhancementAlgorithm; - - /** \brief List containing the contrast enhancements for each band */ - ContrastEnhancementList mContrastEnhancementList; - - /** \brief Number of stddev to plot (0) to ignore. Not applicable to all layer types */ - double mStandardDeviations; - - /** [ data provider interface ] Pointer to data provider derived from the abstract base class QgsDataProvider */ + /** Pointer to data provider */ QgsRasterDataProvider* mDataProvider; DrawingStyle mDrawingStyle; - /** [ data provider interface ] Flag indicating whether the layer is in editing mode or not*/ - bool mEditable; - /** [ data provider interface ]The error message associated with the last error */ QString mError; /** [ data provider interface ] The error caption associated with the last error */ QString mErrorCaption; - /** \brief Pointer to the gdaldataset */ - //GDALDatasetH mGdalBaseDataset; - - /** \brief Pointer to the gdaldataset (possibly warped vrt) */ - //GDALDatasetH mGdalDataset; - - /** \brief Values for mapping pixel to world coordinates. Contents of this array are the same as the GDAL adfGeoTransform */ - double mGeoTransform[6]; - - /** \brief Raster width */ - int mWidth; - - /** \brief Raster height */ - int mHeight; - /** [ data provider interface ] Timestamp, the last modified time of the data source when the layer was created */ QDateTime mLastModified; QgsRasterViewPort mLastViewPort; - /** [ data provider interface ] pointer for loading the provider library */ - //QLibrary* mLib; - - /** [ data provider interface ] Flag indicating whether the layer has been modified since the last commit*/ - bool mModified; - - /** \brief Cell value representing no data. e.g. -9999 */ - //double mNoDataValue; - /** [ data provider interface ] Data provider key */ QString mProviderKey; - /** \brief This list holds a series of RasterPyramid structs which store information for each potential pyramid level */ - /* RasterPyramidList mPyramidList; */ - - /** \brief A collection of stats - one for each band in the layer */ - //RasterStatsList mRasterStatsList; - LayerType mRasterType; - /** \brief Flag to indicate if the user entered custom min max values */ - bool mUserDefinedGrayMinimumMaximum; - - /** \brief Flag to indicate if the user entered custom min max values */ - bool mUserDefinedRGBMinimumMaximum; - - /** \brief Flag indicating if the nodatavalue is valid*/ - //bool mValidNoDataValue; - - //QgsRasterRenderer* mRenderer; - //QgsRasterResampleFilter *mResampleFilter; QgsRasterPipe mPipe; }; diff --git a/src/core/raster/qgsrasterpipe.cpp b/src/core/raster/qgsrasterpipe.cpp index f7f2ccd7238..fe24b74dd73 100644 --- a/src/core/raster/qgsrasterpipe.cpp +++ b/src/core/raster/qgsrasterpipe.cpp @@ -17,11 +17,11 @@ #include -#include "qgsrasterpipe.h" -#include "qgslogger.h" - #include +#include "qgslogger.h" +#include "qgsrasterpipe.h" + QgsRasterPipe::QgsRasterPipe() { } diff --git a/src/core/raster/qgsrasterpipe.h b/src/core/raster/qgsrasterpipe.h index 96f26c198e4..63213ff3c53 100644 --- a/src/core/raster/qgsrasterpipe.h +++ b/src/core/raster/qgsrasterpipe.h @@ -18,18 +18,18 @@ #ifndef QGSRASTERPIPE_H #define QGSRASTERPIPE_H -#include #include +#include -#include "qgsrectangle.h" -#include "qgsrasterinterface.h" -#include "qgsrasterresamplefilter.h" #include "qgsbrightnesscontrastfilter.h" #include "qgshuesaturationfilter.h" #include "qgsrasterdataprovider.h" +#include "qgsrasterinterface.h" #include "qgsrasternuller.h" -#include "qgsrasterrenderer.h" #include "qgsrasterprojector.h" +#include "qgsrasterrenderer.h" +#include "qgsrasterresamplefilter.h" +#include "qgsrectangle.h" #if defined(Q_OS_WIN) #undef interface @@ -101,9 +101,6 @@ class CORE_EXPORT QgsRasterPipe QgsRasterProjector * projector() const; QgsRasterNuller * nuller() const; - /** Set on/off collection of statistics */ - //void setStatsOn( bool on ) { if ( last() ) last()->setStatsOn( on ); } - private: /** Get known parent type_info of interface parent */ Role interfaceRole( QgsRasterInterface * iface ) const; diff --git a/src/gui/raster/qgspalettedrendererwidget.cpp b/src/gui/raster/qgspalettedrendererwidget.cpp index 12ec2c6c6bd..6bc0dfc829d 100644 --- a/src/gui/raster/qgspalettedrendererwidget.cpp +++ b/src/gui/raster/qgspalettedrendererwidget.cpp @@ -91,16 +91,19 @@ void QgsPalettedRendererWidget::setFromRenderer( const QgsRasterRenderer* r ) else { //read default palette settings from layer - QList itemList = - mRasterLayer->colorTable( mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt() ); - QList::const_iterator itemIt = itemList.constBegin(); - int index = 0; - for ( ; itemIt != itemList.constEnd(); ++itemIt ) + QgsRasterDataProvider *provider = mRasterLayer->dataProvider(); + if ( provider ) { - QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget ); - item->setText( 0, QString::number( index ) ); - item->setBackground( 1, QBrush( itemIt->color ) ); - ++index; + QList itemList = provider->colorTable( mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt() ); + QList::const_iterator itemIt = itemList.constBegin(); + int index = 0; + for ( ; itemIt != itemList.constEnd(); ++itemIt ) + { + QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget ); + item->setText( 0, QString::number( index ) ); + item->setBackground( 1, QBrush( itemIt->color ) ); + ++index; + } } } } diff --git a/src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp b/src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp index 25b5b19365f..394e9c62ed5 100644 --- a/src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp +++ b/src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp @@ -365,22 +365,23 @@ void QgsSingleBandPseudoColorRendererWidget::populateColormapTreeWidget( const Q void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromBandButton_clicked() { - if ( !mRasterLayer ) + if ( !mRasterLayer || !mRasterLayer->dataProvider() ) { return; } - QList colorRampList; int bandIndex = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt(); - if ( mRasterLayer->readColorTable( bandIndex, &colorRampList ) ) + + QList colorRampList = mRasterLayer->dataProvider()->colorTable( bandIndex ); + if ( colorRampList.size() > 0 ) { populateColormapTreeWidget( colorRampList ); mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) ); } else { - QMessageBox::warning( this, tr( "Load Color Map" ), tr( "The color map for band %1 failed to load" ).arg( bandIndex ) ); + QMessageBox::warning( this, tr( "Load Color Map" ), tr( "The color map for band %1 has no entries" ).arg( bandIndex ) ); } } diff --git a/src/plugins/georeferencer/qgsgeorefplugingui.cpp b/src/plugins/georeferencer/qgsgeorefplugingui.cpp index 004440d3706..db752570a01 100644 --- a/src/plugins/georeferencer/qgsgeorefplugingui.cpp +++ b/src/plugins/georeferencer/qgsgeorefplugingui.cpp @@ -632,16 +632,16 @@ void QgsGeorefPluginGui::showGeorefConfigDialog() // Histogram stretch slots void QgsGeorefPluginGui::fullHistogramStretch() { - mLayer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" ); - mLayer->setMinimumMaximumUsingDataset(); + mLayer->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum ); mLayer->setCacheImage( NULL ); mCanvas->refresh(); } void QgsGeorefPluginGui::localHistogramStretch() { - mLayer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" ); - mLayer->setMinimumMaximumUsingLastExtent(); + QgsRectangle rectangle = mIface->mapCanvas()->mapRenderer()->outputExtentToLayerExtent( mLayer, mIface->mapCanvas()->extent() ); + + mLayer->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterLayer::ContrastEnhancementMinMax, rectangle ); mLayer->setCacheImage( NULL ); mCanvas->refresh(); } diff --git a/tests/src/core/testqgsrasterlayer.cpp b/tests/src/core/testqgsrasterlayer.cpp index 9397e90082b..69ac5af4205 100644 --- a/tests/src/core/testqgsrasterlayer.cpp +++ b/tests/src/core/testqgsrasterlayer.cpp @@ -151,7 +151,7 @@ void TestQgsRasterLayer::cleanupTestCase() void TestQgsRasterLayer::isValid() { QVERIFY( mpRasterLayer->isValid() ); - mpRasterLayer->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum, false ); + mpRasterLayer->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterLayer::ContrastEnhancementMinMax ); mpMapRenderer->setExtent( mpRasterLayer->extent() ); QVERIFY( render( "raster" ) ); } @@ -289,7 +289,7 @@ void TestQgsRasterLayer::colorRamp4() void TestQgsRasterLayer::landsatBasic() { - mpLandsatRasterLayer->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum, false ); + mpLandsatRasterLayer->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterLayer::ContrastEnhancementMinMax ); QStringList myLayers; myLayers << mpLandsatRasterLayer->id(); mpMapRenderer->setLayerSet( myLayers );