QGIS API Documentation  2.6.0-Brighton
 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 
169 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
170 {
171  Q_OBJECT
172  public:
174  static const double CUMULATIVE_CUT_LOWER;
175 
177  static const double CUMULATIVE_CUT_UPPER;
178 
180  static const double SAMPLE_SIZE;
181 
183  QgsRasterLayer();
184 
201  QgsRasterLayer( const QString & path,
202  const QString & baseName = QString::null,
203  bool loadDefaultStyleFlag = true );
204 
206  QgsRasterLayer( const QString & uri,
207  const QString & baseName,
208  const QString & providerKey,
209  bool loadDefaultStyleFlag = true );
210 
212  ~QgsRasterLayer();
213 
216  {
221  UserDefinedShader
222  };
223 
226  {
230  ColorLayer
231  };
232 
238  static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
239  static bool isValidRasterFileName( const QString & theFileNameQString );
240 
242  static QDateTime lastModified( const QString & name );
243 
245  void setDataProvider( const QString & provider );
246 
248  LayerType rasterType() { return mRasterType; }
249 
251  void setRenderer( QgsRasterRenderer* theRenderer );
252  QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
253 
255  QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
256 
257  QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); }
258  QgsHueSaturationFilter * hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
259 
261  QgsRasterPipe * pipe() { return &mPipe; }
262 
264  int width() const;
265 
267  int height() const;
268 
270  int bandCount() const;
271 
273  const QString bandName( int theBandNoInt );
274 
276  QgsRasterDataProvider* dataProvider();
277 
281  const QgsRasterDataProvider* dataProvider() const;
282 
284  virtual void reload();
285 
289  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext );
290 
292  bool draw( QgsRenderContext& rendererContext );
293 
295  void draw( QPainter * theQPainter,
296  QgsRasterViewPort * myRasterViewPort,
297  const QgsMapToPixel* theQgsMapToPixel = 0 );
298 
300  QgsLegendColorList legendSymbologyItems() const;
301 
303  QString metadata();
304 
306  QPixmap paletteAsPixmap( int theBandNumber = 1 );
307 
309  QString providerType() const;
310 
312  double rasterUnitsPerPixelX();
313  double rasterUnitsPerPixelY();
314 
323  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
325  QgsRectangle theExtent = QgsRectangle(),
326  int theSampleSize = SAMPLE_SIZE,
327  bool theGenerateLookupTableFlag = true );
328 
330  void setDefaultContrastEnhancement();
331 
333  void setDrawingStyle( const QString & theDrawingStyleQString );
334 
336  void showProgress( int theValue );
337 
339  virtual QStringList subLayers() const;
340 
343  Q_DECL_DEPRECATED QPixmap previewAsPixmap( QSize size, QColor bgColor = Qt::white );
344 
347  QImage previewAsImage( QSize size, QColor bgColor = Qt::white,
348  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
349 
356  virtual void setLayerOrder( const QStringList &layers );
357 
361  virtual void setSubLayerVisibility( QString name, bool vis );
362 
364  virtual QDateTime timestamp() const { return mDataProvider->timestamp() ; }
365 
366  public slots:
367  void showStatusMessage( const QString & theMessage );
368 
370  Q_DECL_DEPRECATED void updateProgress( int, int );
371 
373  void onProgress( int, double, QString );
374 
375  signals:
377  void progressUpdate( int theValue );
378 
382  void dataChanged();
383 
384  protected:
386  bool readSymbology( const QDomNode& node, QString& errorMessage );
387 
389  bool readXml( const QDomNode& layer_node );
390 
392  bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
393 
395  bool writeXml( QDomNode & layer_node, QDomDocument & doc );
396 
397  private:
399  void init();
400 
402  void closeDataProvider();
403 
405  bool update();
406 
408  void setRendererForDrawingStyle( const QgsRaster::DrawingStyle & theDrawingStyle );
409 
411  const QString QSTRING_NOT_SET;
412  const QString TRSTRING_NOT_SET;
413 
415  QgsRasterDataProvider* mDataProvider;
416 
417  //DrawingStyle mDrawingStyle;
418 
420  QDateTime mLastModified;
421 
422  QgsRasterViewPort mLastViewPort;
423 
425  QString mProviderKey;
426 
427  LayerType mRasterType;
428 
429  QgsRasterPipe mPipe;
430 };
431 
432 #endif