QGIS API Documentation  master-3f58142
src/core/raster/qgsrasterlayer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                         qgsrasterlayer.h  -  description
00003                               -------------------
00004  begin                : Fri Jun 28 2002
00005  copyright            : (C) 2004 by T.Sutton, Gary E.Sherman, Steve Halasz
00006  email                : tim@linfiniti.com
00007 ***************************************************************************/
00008 /*
00009  * Peter J. Ersts - contributed to the refactoring and maintenance of this class
00010  * B. Morley - added functions to convert this class to a data provider interface
00011  * Frank Warmerdam - contributed bug fixes and migrated class to use all GDAL_C_API calls
00012  */
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021 #ifndef QGSRASTERLAYER_H
00022 #define QGSRASTERLAYER_H
00023 
00024 #include <QColor>
00025 #include <QDateTime>
00026 #include <QList>
00027 #include <QMap>
00028 #include <QPair>
00029 #include <QVector>
00030 
00031 #include "qgis.h"
00032 #include "qgsbrightnesscontrastfilter.h"
00033 #include "qgscolorrampshader.h"
00034 #include "qgscontrastenhancement.h"
00035 #include "qgshuesaturationfilter.h"
00036 #include "qgsmaplayer.h"
00037 #include "qgspoint.h"
00038 #include "qgsraster.h"
00039 #include "qgsrasterdataprovider.h"
00040 #include "qgsrasterinterface.h"
00041 #include "qgsrasterpipe.h"
00042 #include "qgsrasterresamplefilter.h"
00043 #include "qgsrastershaderfunction.h"
00044 #include "qgsrastershader.h"
00045 #include "qgsrastertransparency.h"
00046 #include "qgsrasterviewport.h"
00047 
00048 class QgsMapToPixel;
00049 class QgsRasterRenderer;
00050 class QgsRectangle;
00051 class QImage;
00052 class QLibrary;
00053 class QPixmap;
00054 class QSlider;
00055 
00167 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
00168 {
00169     Q_OBJECT
00170   public:
00172     static const double CUMULATIVE_CUT_LOWER;
00173 
00175     static const double CUMULATIVE_CUT_UPPER;
00176 
00178     static const double SAMPLE_SIZE;
00179 
00181     QgsRasterLayer();
00182 
00199     QgsRasterLayer( const QString & path,
00200                     const QString &  baseName = QString::null,
00201                     bool loadDefaultStyleFlag = true );
00202 
00204     QgsRasterLayer( const QString & uri,
00205                     const QString & baseName,
00206                     const QString & providerKey,
00207                     bool loadDefaultStyleFlag = true );
00208 
00210     ~QgsRasterLayer();
00211 
00213     enum ColorShadingAlgorithm
00214     {
00215       UndefinedShader,
00216       PseudoColorShader,
00217       FreakOutShader,
00218       ColorRampShader,
00219       UserDefinedShader
00220     };
00221 
00223     enum DrawingStyle
00224     {
00225       UndefinedDrawingStyle,
00226       SingleBandGray,                 // a single band image drawn as a range of gray colors
00227       SingleBandPseudoColor,          // a single band image drawn using a pseudocolor algorithm
00228       PalettedColor,                  // a "Palette" image drawn using color table
00229       PalettedSingleBandGray,         // a "Palette" layer drawn in gray scale
00230       PalettedSingleBandPseudoColor,  // a "Palette" layerdrawn using a pseudocolor algorithm
00231       PalettedMultiBandColor,         // currently not supported
00232       MultiBandSingleBandGray,        // a layer containing 2 or more bands, but a single band drawn as a range of gray colors
00233       MultiBandSingleBandPseudoColor, // a layer containing 2 or more bands, but a single band drawn using a pseudocolor algorithm
00234       MultiBandColor,                 // a layer containing 2 or more bands, mapped to RGB color space. In the case of a multiband with only two bands, one band will be mapped to more than one color.
00235       SingleBandColorDataStyle        // ARGB values rendered directly
00236     };
00237 
00239     enum LayerType
00240     {
00241       GrayOrUndefined,
00242       Palette,
00243       Multiband,
00244       ColorLayer
00245     };
00246 
00247     static void buildSupportedRasterFileFilter( QString & fileFilters );
00248 
00254     static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
00255     static bool isValidRasterFileName( const QString & theFileNameQString );
00256 
00258     static QDateTime lastModified( const QString &  name );
00259 
00261     void setDataProvider( const QString & provider );
00262 
00264     LayerType rasterType() { return mRasterType; }
00265 
00267     //DrawingStyle drawingStyle() { return mDrawingStyle; }
00268 
00270     //void setDrawingStyle( const DrawingStyle &  theDrawingStyle ) { mDrawingStyle = theDrawingStyle; setRendererForDrawingStyle( theDrawingStyle ); }
00271 
00273     void setRenderer( QgsRasterRenderer* theRenderer );
00274     QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
00275 
00277     QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
00278 
00279     QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); }
00280     QgsHueSaturationFilter * hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
00281 
00283     QgsRasterPipe * pipe() { return &mPipe; }
00284 
00286     int width() const;
00287 
00289     int height() const;
00290 
00292     int bandCount() const;
00293 
00295     const  QString bandName( int theBandNoInt );
00296 
00298     QgsRasterDataProvider* dataProvider();
00299 
00303     const QgsRasterDataProvider* dataProvider() const;
00304 
00307     virtual void reload();
00308 
00310     bool draw( QgsRenderContext& rendererContext );
00311 
00313     void draw( QPainter * theQPainter,
00314                QgsRasterViewPort * myRasterViewPort,
00315                const QgsMapToPixel* theQgsMapToPixel = 0 );
00316 
00318     QString lastError();
00319 
00321     QString lastErrorTitle();
00322 
00325     QList< QPair< QString, QColor > > legendSymbologyItems() const;
00326 
00328     QString metadata();
00329 
00331     QPixmap paletteAsPixmap( int theBandNumber = 1 );
00332 
00336     QString providerType() const;
00337 
00339     double rasterUnitsPerPixelX();
00340     double rasterUnitsPerPixelY();
00341 
00350     void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
00351                                  QgsRaster::ContrastEnhancementLimits theLimits = QgsRaster::ContrastEnhancementMinMax,
00352                                  QgsRectangle theExtent = QgsRectangle(),
00353                                  int theSampleSize = SAMPLE_SIZE,
00354                                  bool theGenerateLookupTableFlag = true );
00355 
00357     void setDefaultContrastEnhancement();
00358 
00360     void setDrawingStyle( const QString & theDrawingStyleQString );
00361 
00363     void showProgress( int theValue );
00364 
00366     virtual QStringList subLayers() const;
00367 
00369     QPixmap previewAsPixmap( QSize size, QColor bgColor = Qt::white );
00370 
00372     void triggerRepaint();
00373 
00380     virtual void setLayerOrder( const QStringList &layers );
00381 
00385     virtual void setSubLayerVisibility( QString name, bool vis );
00386 
00388     virtual QDateTime timestamp() const { return mDataProvider->timestamp() ; }
00389 
00390   public slots:
00391     void showStatusMessage( const QString & theMessage );
00392 
00394     void updateProgress( int, int );
00395 
00397     void onProgress( int, double, QString );
00398 
00399   signals:
00401     void progressUpdate( int theValue );
00402 
00407     void dataChanged();
00408 
00409   protected:
00411     bool readSymbology( const QDomNode& node, QString& errorMessage );
00412 
00414     bool readXml( const QDomNode& layer_node );
00415 
00417     bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
00418 
00420     bool writeXml( QDomNode & layer_node, QDomDocument & doc );
00421 
00422   private:
00424     void init();
00425 
00427     void closeDataProvider();
00428 
00430     bool update();
00431 
00433     void setRendererForDrawingStyle( const DrawingStyle &  theDrawingStyle );
00434 
00436     const QString QSTRING_NOT_SET;
00437     const QString TRSTRING_NOT_SET;
00438 
00440     QgsRasterDataProvider* mDataProvider;
00441 
00442     //DrawingStyle mDrawingStyle;
00443 
00445     QString mError;
00446 
00448     QString mErrorCaption;
00449 
00451     QDateTime mLastModified;
00452 
00453     QgsRasterViewPort mLastViewPort;
00454 
00456     QString mProviderKey;
00457 
00458     LayerType mRasterType;
00459 
00460     QgsRasterPipe mPipe;
00461 };
00462 
00463 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines