QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrasterlayer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterlayer.h - description
3  -------------------
4  begin : Fri Jun 28 2002
5  copyright : (C) 2004 by T.Sutton, Gary E.Sherman, Steve Halasz
6  email : [email protected]
7 ***************************************************************************/
8 /*
9  * Peter J. Ersts - contributed to the refactoring and maintenance of this class
10  * B. Morley - added functions to convert this class to a data provider interface
11  * Frank Warmerdam - contributed bug fixes and migrated class to use all GDAL_C_API calls
12  */
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 #ifndef QGSRASTERLAYER_H
22 #define QGSRASTERLAYER_H
23 
24 #include <QColor>
25 #include <QDateTime>
26 #include <QList>
27 #include <QMap>
28 #include <QPair>
29 #include <QVector>
30 
31 #include "qgis.h"
33 #include "qgscolorrampshader.h"
34 #include "qgscontrastenhancement.h"
35 #include "qgshuesaturationfilter.h"
36 #include "qgsmaplayer.h"
37 #include "qgspoint.h"
38 #include "qgsraster.h"
39 #include "qgsrasterdataprovider.h"
40 #include "qgsrasterinterface.h"
41 #include "qgsrasterpipe.h"
44 #include "qgsrastershader.h"
45 #include "qgsrastertransparency.h"
46 #include "qgsrasterviewport.h"
47 
48 class QgsMapToPixel;
49 class QgsRasterRenderer;
50 class QgsRectangle;
51 class QImage;
52 class QLibrary;
53 class QPixmap;
54 class QSlider;
55 
56 typedef QList < QPair< QString, QColor > > QgsLegendColorList;
57 
163 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
164 {
165  Q_OBJECT
166  public:
168  static const double CUMULATIVE_CUT_LOWER;
169 
171  static const double CUMULATIVE_CUT_UPPER;
172 
174  static const double SAMPLE_SIZE;
175 
177  QgsRasterLayer();
178 
195  QgsRasterLayer( const QString &path,
196  const QString &baseName = QString::null,
197  bool loadDefaultStyleFlag = true );
198 
199  //TODO - QGIS 3.0
200  //This constructor is confusing if used with string literals for providerKey,
201  //as the previous constructor will be called with the literal for providerKey
202  //implicitly converted to a bool.
203  //for QGIS 3.0, make either constructor explicit or alter the signatures
205  QgsRasterLayer( const QString &uri,
206  const QString &baseName,
207  const QString &providerKey,
208  bool loadDefaultStyleFlag = true );
209 
211  ~QgsRasterLayer();
212 
215  {
220  UserDefinedShader
221  };
222 
225  {
229  ColorLayer
230  };
231 
237  static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
238  static bool isValidRasterFileName( const QString & theFileNameQString );
239 
241  static QDateTime lastModified( const QString & name );
242 
244  void setDataProvider( const QString & provider );
245 
247  LayerType rasterType() { return mRasterType; }
248 
250  void setRenderer( QgsRasterRenderer* theRenderer );
251  QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
252 
254  QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
255 
256  QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); }
257  QgsHueSaturationFilter * hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
258 
260  QgsRasterPipe * pipe() { return &mPipe; }
261 
263  int width() const;
264 
266  int height() const;
267 
269  int bandCount() const;
270 
272  const QString bandName( int theBandNoInt );
273 
275  QgsRasterDataProvider* dataProvider();
276 
280  const QgsRasterDataProvider* dataProvider() const;
281 
283  virtual void reload() override;
284 
288  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) override;
289 
291  bool draw( QgsRenderContext& rendererContext ) override;
292 
294  void draw( QPainter * theQPainter,
295  QgsRasterViewPort * myRasterViewPort,
296  const QgsMapToPixel* theQgsMapToPixel = 0 );
297 
299  QgsLegendColorList legendSymbologyItems() const;
300 
302  QString metadata() override;
303 
305  QPixmap paletteAsPixmap( int theBandNumber = 1 );
306 
308  QString providerType() const;
309 
311  double rasterUnitsPerPixelX();
312  double rasterUnitsPerPixelY();
313 
322  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
324  QgsRectangle theExtent = QgsRectangle(),
325  int theSampleSize = SAMPLE_SIZE,
326  bool theGenerateLookupTableFlag = true );
327 
329  void setDefaultContrastEnhancement();
330 
332  void setDrawingStyle( const QString & theDrawingStyleQString );
333 
335  void showProgress( int theValue );
336 
338  virtual QStringList subLayers() const override;
339 
342  Q_DECL_DEPRECATED QPixmap previewAsPixmap( QSize size, QColor bgColor = Qt::white );
343 
346  QImage previewAsImage( QSize size, QColor bgColor = Qt::white,
347  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
348 
355  virtual void setLayerOrder( const QStringList &layers ) override;
356 
360  virtual void setSubLayerVisibility( QString name, bool vis ) override;
361 
363  virtual QDateTime timestamp() const override { return mDataProvider->timestamp() ; }
364 
365  public slots:
366  void showStatusMessage( const QString & theMessage );
367 
369  Q_DECL_DEPRECATED void updateProgress( int, int );
370 
372  void onProgress( int, double, QString );
373 
374  signals:
376  void progressUpdate( int theValue );
377 
381  void dataChanged();
382 
383  protected:
385  bool readSymbology( const QDomNode& node, QString& errorMessage ) override;
386 
388  bool readXml( const QDomNode& layer_node ) override;
389 
391  bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const override;
392 
394  bool writeXml( QDomNode & layer_node, QDomDocument & doc ) override;
395 
396  private:
398  void init();
399 
401  void closeDataProvider();
402 
404  bool update();
405 
407  void setRendererForDrawingStyle( const QgsRaster::DrawingStyle & theDrawingStyle );
408 
410  const QString QSTRING_NOT_SET;
411  const QString TRSTRING_NOT_SET;
412 
414  QgsRasterDataProvider* mDataProvider;
415 
416  //DrawingStyle mDrawingStyle;
417 
419  QDateTime mLastModified;
420 
421  QgsRasterViewPort mLastViewPort;
422 
424  QString mProviderKey;
425 
426  LayerType mRasterType;
427 
428  QgsRasterPipe mPipe;
429 };
430 
431 #endif