00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef QGSRASTERLAYER_H
00023 #define QGSRASTERLAYER_H
00024
00025
00026
00027
00028
00029 #include <QColor>
00030 #include <QDateTime>
00031 #include <QVector>
00032 #include <QList>
00033 #include <QMap>
00034
00035 #include "qgis.h"
00036 #include "qgspoint.h"
00037 #include "qgsmaplayer.h"
00038 #include "qgsrasterviewport.h"
00039 #include "qgscontrastenhancement.h"
00040 #include "qgsrastertransparency.h"
00041 #include "qgsrastershader.h"
00042 #include "qgscolorrampshader.h"
00043 #include "qgsrastershaderfunction.h"
00044 #include "qgsrasterdataprovider.h"
00045
00046 #define CPL_SUPRESS_CPLUSPLUS
00047 #include <gdal.h>
00051 int CPL_STDCALL progressCallback( double dfComplete,
00052 const char *pszMessage,
00053 void * pProgressArg );
00054
00055
00056
00057
00058 class QgsMapToPixel;
00059 class QgsRectangle;
00060 class QgsRasterBandStats;
00061 class QgsRasterPyramid;
00062 class QImage;
00063 class QPixmap;
00064 class QSlider;
00065 class QLibrary;
00066
00178 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
00179 {
00180 Q_OBJECT
00181 public:
00198 QgsRasterLayer( const QString & path = QString::null,
00199 const QString & baseName = QString::null,
00200 bool loadDefaultStyleFlag = true );
00201
00203 QgsRasterLayer( int dummy,
00204 const QString & baseName = QString(),
00205 const QString & path = QString(),
00206 const QString & providerLib = QString(),
00207 const QStringList & layers = QStringList(),
00208 const QStringList & styles = QStringList(),
00209 const QString & format = QString(),
00210 const QString & crs = QString() );
00211
00212
00214 ~QgsRasterLayer();
00215
00216
00217
00218
00219
00221 enum ColorShadingAlgorithm
00222 {
00223 UndefinedShader,
00224 PseudoColorShader,
00225 FreakOutShader,
00226 ColorRampShader,
00227 UserDefinedShader
00228 };
00229
00231 enum DrawingStyle
00232 {
00233 UndefinedDrawingStyle,
00234 SingleBandGray,
00235 SingleBandPseudoColor,
00236 PalettedColor,
00237 PalettedSingleBandGray,
00238 PalettedSingleBandPseudoColor,
00239 PalettedMultiBandColor,
00240 MultiBandSingleGandGray,
00241
00242 MultiBandSingleBandGray = MultiBandSingleGandGray,
00243 MultiBandSingleBandPseudoColor,
00244 MultiBandColor
00245
00246 };
00247
00249 enum LayerType
00250 {
00251 GrayOrUndefined,
00252 Palette,
00253 Multiband
00254 } ;
00255
00257 typedef QList<QgsContrastEnhancement> ContrastEnhancementList;
00258
00266 typedef QList<QgsRasterPyramid> RasterPyramidList;
00267
00271 typedef QList<QgsRasterBandStats> RasterStatsList;
00272
00273
00274
00275
00276
00277
00278
00279
00280 static void buildSupportedRasterFileFilter( QString & fileFilters );
00281
00287 static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
00288 static bool isValidRasterFileName( const QString & theFileNameQString );
00289 static QStringList subLayers( GDALDatasetH dataset );
00290
00291
00293 static QDateTime lastModified( const QString & name );
00294
00296 static void registerGdalDrivers();
00297
00298
00299
00300
00301
00302
00303
00304
00306 QString blueBandName() const { return mBlueBandName; }
00307
00309 QgsRasterLayer::ColorShadingAlgorithm colorShadingAlgorithm() const { return mColorShadingAlgorithm; }
00310
00312 QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() { return mContrastEnhancementAlgorithm; }
00313
00315 QString contrastEnhancementAlgorithmAsString() const;
00316
00318 DrawingStyle drawingStyle() { return mDrawingStyle; }
00319
00321 QString grayBandName() const { return mGrayBandName; }
00322
00324 QString greenBandName() const { return mGreenBandName; }
00325
00327 bool hasPyramids() { return mHasPyramids; }
00328
00330 bool hasUserDefinedGrayMinimumMaximum() const { return mUserDefinedGrayMinimumMaximum; }
00331
00333 bool hasUserDefinedRGBMinimumMaximum() const { return mUserDefinedRGBMinimumMaximum; }
00334
00336 int height() { return mHeight; }
00337
00339 bool invertHistogram() const { return mInvertColor; }
00340
00342 bool isNoDataValueValid() const { return mValidNoDataValue; }
00343
00345 bool isGrayMinimumMaximumEstimated() const { return mGrayMinimumMaximumEstimated; }
00346
00348 bool isRGBMinimumMaximumEstimated() const { return mRGBMinimumMaximumEstimated; }
00349
00351 double noDataValue( bool* isValid = 0 ) { if ( isValid ) { *isValid = mValidNoDataValue;} return mNoDataValue; }
00352
00354 QgsRasterTransparency* rasterTransparency() { return &mRasterTransparency; }
00355
00357 QgsRasterShader* rasterShader() { return mRasterShader; }
00358
00360 LayerType rasterType() { return mRasterType; }
00361
00363 QString redBandName() const { return mRedBandName; }
00364
00366 void setDataProvider( const QString & provider,
00367 const QStringList & layers,
00368 const QStringList & styles,
00369 const QString & format,
00370 const QString & crs );
00371
00373 void setDrawingStyle( const DrawingStyle & theDrawingStyle ) { mDrawingStyle = theDrawingStyle; }
00374
00376 void setGrayMinimumMaximumEstimated( bool theBool ) { mGrayMinimumMaximumEstimated = theBool; }
00377
00379 void setInvertHistogram( bool theFlag ) { mInvertColor = theFlag; }
00380
00382 void setRGBMinimumMaximumEstimated( bool theBool ) { mRGBMinimumMaximumEstimated = theBool; }
00383
00385 void setStandardDeviations( double theStandardDeviations ) { mStandardDeviations = theStandardDeviations; }
00386
00388 void setUserDefinedGrayMinimumMaximum( bool theBool ) { mUserDefinedGrayMinimumMaximum = theBool; }
00389
00391 void setUserDefinedRGBMinimumMaximum( bool theBool ) { mUserDefinedRGBMinimumMaximum = theBool; }
00392
00394 double standardDeviations() const { return mStandardDeviations; }
00395
00397 QString transparentBandName() const { return mTransparencyBandName; }
00398
00400 bool usesProvider();
00401
00403 int width() { return mWidth; }
00404
00405
00406
00407
00408
00409
00410
00411
00413 unsigned int bandCount();
00414
00416 const QString bandName( int theBandNoInt );
00417
00421 int bandNumber( const QString & theBandName );
00422
00424 const QgsRasterBandStats bandStatistics( int );
00425
00427 const QgsRasterBandStats bandStatistics( const QString & );
00428
00434 RasterPyramidList buildPyramidList();
00435
00437 QString colorShadingAlgorithmAsString() const;
00438
00440 void computeMinimumMaximumEstimates( int theBand, double* theMinMax );
00441
00443 void computeMinimumMaximumEstimates( QString theBand, double* theMinMax );
00444
00447 void computeMinimumMaximumEstimates( int theBand, double& theMin, double& theMax );
00448
00450 void computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax );
00451
00453 void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );
00454
00457 void computeMinimumMaximumFromLastExtent( int theBand, double& theMin, double& theMax );
00458
00460 QgsContrastEnhancement* contrastEnhancement( unsigned int theBand );
00461
00463 bool copySymbologySettings( const QgsMapLayer& theOther );
00464
00466 QList<QgsColorRampShader::ColorRampItem>* colorTable( int theBandNoInt );
00467
00469 QgsRasterDataProvider* dataProvider();
00470
00472 const QgsRasterDataProvider* dataProvider() const;
00473
00476 virtual void reload();
00477
00479 bool draw( QgsRenderContext& rendererContext );
00480
00482 void draw( QPainter * theQPainter,
00483 QgsRasterViewPort * myRasterViewPort,
00484 const QgsMapToPixel* theQgsMapToPixel = 0 );
00485
00491 QString drawingStyleAsString() const;
00492
00494 bool hasCompatibleSymbology( const QgsMapLayer& theOther ) const;
00495
00497 bool hasStatistics( int theBandNoInt );
00498
00500 bool identify( const QgsPoint & point, QMap<QString, QString>& results );
00501
00503 QString identifyAsText( const QgsPoint & point );
00504
00508 QString identifyAsHtml( const QgsPoint & point );
00509
00511 bool isEditable() const;
00512
00514 QString lastError();
00515
00517 QString lastErrorTitle();
00518
00520 QPixmap legendAsPixmap();
00521
00523 QPixmap legendAsPixmap( bool );
00524
00526 QPixmap legendAsPixmap( int theLabelCount );
00527
00529 double maximumValue( unsigned int theBand );
00530
00532 double maximumValue( QString theBand );
00533
00535 QString metadata();
00536
00538 double minimumValue( unsigned int theBand );
00539
00541 double minimumValue( QString theBand );
00542
00544 QPixmap paletteAsPixmap( int theBand = 1 );
00545
00547 QString providerKey();
00548
00550 double rasterUnitsPerPixel();
00551
00553 bool readColorTable( int theBandNumber, QList<QgsColorRampShader::ColorRampItem>* theList );
00554
00556 void resetNoDataValue();
00557
00559 void setBlueBandName( const QString & theBandName );
00560
00562 void setColorShadingAlgorithm( QgsRasterLayer::ColorShadingAlgorithm theShaderAlgorithm );
00563
00565 void setColorShadingAlgorithm( QString theShaderAlgorithm );
00566
00568 void setContrastEnhancementAlgorithm( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
00569 bool theGenerateLookupTableFlag = true );
00570
00572 void setContrastEnhancementAlgorithm( QString theAlgorithm, bool theGenerateLookupTableFlag = true );
00573
00575 void setContrastEnhancementFunction( QgsContrastEnhancementFunction* theFunction );
00576
00578 void setDrawingStyle( const QString & theDrawingStyleQString );
00579
00581 void setGrayBandName( const QString & theBandName );
00582
00584 void setGreenBandName( const QString & theBandName );
00585
00587 void setMaximumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );
00588
00590 void setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );
00591
00593 void setMinimumMaximumUsingLastExtent();
00594
00596 void setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );
00597
00599 void setMinimumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );
00600
00602 void setNoDataValue( double theNoData );
00603
00606 void setRasterShaderFunction( QgsRasterShaderFunction* theFunction );
00607
00609 void setRedBandName( const QString & theBandName );
00610
00612 void setTransparentBandName( const QString & theBandName );
00613
00615 void showProgress( int theValue );
00616
00618 QStringList subLayers() const;
00619
00621 void thumbnailAsPixmap( QPixmap * theQPixmap );
00625 void thumbnailAsImage( QImage * thepImage );
00626
00628 void triggerRepaint();
00629
00630
00631
00632
00633
00634
00635
00636
00643 virtual void setLayerOrder( const QStringList & layers );
00644
00648 virtual void setSubLayerVisibility( const QString & name, bool vis );
00649
00650
00651
00652
00653
00654 public slots:
00656 QString buildPyramids( const RasterPyramidList &,
00657 const QString & theResamplingMethod = "NEAREST",
00658 bool theTryInternalFlag = false );
00659
00661 void populateHistogram( int theBandNoInt,
00662 int theBinCountInt = 256,
00663 bool theIgnoreOutOfRangeFlag = true,
00664 bool theThoroughBandScanFlag = false );
00665
00666 void showStatusMessage( const QString & theMessage );
00667
00669 void updateProgress( int, int );
00670
00671
00672
00673
00674
00675 signals:
00677 void progressUpdate( int theValue );
00678
00679
00680
00681
00682 protected:
00683
00685 bool readSymbology( const QDomNode& node, QString& errorMessage );
00686
00688 bool readXml( QDomNode & layer_node );
00689
00691 bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
00692
00694 bool writeXml( QDomNode & layer_node, QDomDocument & doc );
00695
00696
00697
00698
00699
00700 private:
00701
00702
00703
00704
00706 void drawMultiBandColor( QPainter * theQPainter,
00707 QgsRasterViewPort * theRasterViewPort,
00708 const QgsMapToPixel* theQgsMapToPixel );
00709
00711 void drawMultiBandSingleBandGray( QPainter * theQPainter,
00712 QgsRasterViewPort * theRasterViewPort,
00713 const QgsMapToPixel* theQgsMapToPixel,
00714 int theBandNoInt );
00715
00717 void drawMultiBandSingleBandPseudoColor( QPainter * theQPainter,
00718 QgsRasterViewPort * theRasterViewPort,
00719 const QgsMapToPixel* theQgsMapToPixel,
00720 int theBandNoInt );
00721
00723 void drawPalettedSingleBandColor( QPainter * theQPainter,
00724 QgsRasterViewPort * theRasterViewPort,
00725 const QgsMapToPixel* theQgsMapToPixel,
00726 int theBandNoInt );
00727
00729 void drawPalettedSingleBandGray( QPainter * theQPainter,
00730 QgsRasterViewPort * theRasterViewPort,
00731 const QgsMapToPixel* theQgsMapToPixel,
00732 int theBandNoInt );
00733
00735 void drawPalettedSingleBandPseudoColor( QPainter * theQPainter,
00736 QgsRasterViewPort * theRasterViewPort,
00737 const QgsMapToPixel* theQgsMapToPixel,
00738 int theBandNoInt );
00739
00741 void drawPalettedMultiBandColor( QPainter * theQPainter,
00742 QgsRasterViewPort * theRasterViewPort,
00743 const QgsMapToPixel* theQgsMapToPixel,
00744 int theBandNoInt );
00745
00747 void drawSingleBandGray( QPainter * theQPainter,
00748 QgsRasterViewPort * theRasterViewPort,
00749 const QgsMapToPixel* theQgsMapToPixel,
00750 int theBandNoInt );
00751
00753 void drawSingleBandPseudoColor( QPainter * theQPainter,
00754 QgsRasterViewPort * theRasterViewPort,
00755 const QgsMapToPixel* theQgsMapToPixel,
00756 int theBandNoInt );
00757
00759 void closeDataset();
00760
00762 QString generateBandName( int );
00763
00765 bool hasBand( const QString & theBandName );
00766
00768 void paintImageToCanvas( QPainter* theQPainter, QgsRasterViewPort * theRasterViewPort,
00769 const QgsMapToPixel* theQgsMapToPixel, QImage* theImage );
00770
00772 QString projectionWkt();
00773
00775 void* readData( GDALRasterBandH gdalBand, QgsRasterViewPort *viewPort );
00776
00778 bool readFile( const QString & fileName );
00779
00781 inline double readValue( void *data, GDALDataType type, int index );
00782
00784 bool update();
00785
00787 QString validateBandName( const QString & theBandName );
00788
00789
00790
00791
00792
00793
00794
00796 const QString QSTRING_NOT_SET;
00797 const QString TRSTRING_NOT_SET;
00798
00800 int mBandCount;
00801
00803 QString mBlueBandName;
00804
00806 ColorShadingAlgorithm mColorShadingAlgorithm;
00807
00809 QgsContrastEnhancement::ContrastEnhancementAlgorithm mContrastEnhancementAlgorithm;
00810
00812 ContrastEnhancementList mContrastEnhancementList;
00813
00815 double mStandardDeviations;
00816
00818 QgsRasterDataProvider* mDataProvider;
00819
00820 DrawingStyle mDrawingStyle;
00821
00823 bool mEditable;
00824
00826 QString mError;
00827
00829 QString mErrorCaption;
00830
00832 GDALDatasetH mGdalBaseDataset;
00833
00835 GDALDatasetH mGdalDataset;
00836
00838 double mGeoTransform[6];
00839
00841 QString mGrayBandName;
00842
00844 bool mGrayMinimumMaximumEstimated;
00845
00847 QString mGreenBandName;
00848
00850 bool mHasPyramids;
00851
00853 int mWidth;
00854
00856 int mHeight;
00857
00859 bool mInvertColor;
00860
00862 QDateTime mLastModified;
00863
00864 QgsRasterViewPort mLastViewPort;
00865
00867 QLibrary* mLib;
00868
00870 bool mModified;
00871
00873 double mNoDataValue;
00874
00876 QString mProviderKey;
00877
00879 RasterPyramidList mPyramidList;
00880
00882 QgsRasterShader* mRasterShader;
00883
00885 RasterStatsList mRasterStatsList;
00886
00888 QgsRasterTransparency mRasterTransparency;
00889
00890 LayerType mRasterType;
00891
00893 QString mRedBandName;
00894
00896 bool mRGBMinimumMaximumEstimated;
00897
00899 QString mTransparencyBandName;
00900
00902 bool mUserDefinedGrayMinimumMaximum;
00903
00905 bool mUserDefinedRGBMinimumMaximum;
00906
00908 bool mValidNoDataValue;
00909 };
00910
00911
00912
00913
00914
00915
00916
00917
00918
00922 class CORE_EXPORT QgsRasterImageBuffer
00923 {
00924 public:
00925 QgsRasterImageBuffer( GDALRasterBandH rasterBand, QPainter* p,
00926 QgsRasterViewPort* viewPort, const QgsMapToPixel* mapToPixel, double* mGeoTransform );
00927 ~QgsRasterImageBuffer();
00928 void reset( int maxPixelsInVirtualMemory = 5000000 );
00930 bool nextScanLine( QRgb** imageScanLine, void** rasterScanLine );
00931
00932 void setWritingEnabled( bool enabled ) { mWritingEnabled = enabled; }
00933
00934 private:
00935 QgsRasterImageBuffer();
00937 bool createNextPartImage();
00938
00940 void drawPixelRectangle();
00941
00942 GDALRasterBandH mRasterBand;
00943 QPainter* mPainter;
00944 QgsRasterViewPort* mViewPort;
00945 const QgsMapToPixel* mMapToPixel;
00946 double* mGeoTransform;
00947
00948 bool mValid;
00950 bool mWritingEnabled;
00952 bool mDrawPixelRect;
00953 int mCurrentRow;
00954 int mNumPartImages;
00955 int mNumRasterRowsPerPart;
00956 int mCurrentPartRasterMin;
00957 int mCurrentPartRasterMax;
00958 int mCurrentPartImageRow;
00959 int mNumCurrentImageRows;
00960
00961
00962 QImage* mCurrentImage;
00963 void* mCurrentGDALData;
00964 };
00965
00966 #endif