QGIS API Documentation  2.0.1-Dufour
 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 
167 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
168 {
169  Q_OBJECT
170  public:
172  static const double CUMULATIVE_CUT_LOWER;
173 
175  static const double CUMULATIVE_CUT_UPPER;
176 
178  static const double SAMPLE_SIZE;
179 
181  QgsRasterLayer();
182 
199  QgsRasterLayer( const QString & path,
200  const QString & baseName = QString::null,
201  bool loadDefaultStyleFlag = true );
202 
204  QgsRasterLayer( const QString & uri,
205  const QString & baseName,
206  const QString & providerKey,
207  bool loadDefaultStyleFlag = true );
208 
210  ~QgsRasterLayer();
211 
214  {
219  UserDefinedShader
220  };
221 
224  {
228  ColorLayer
229  };
230 
236  static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
237  static bool isValidRasterFileName( const QString & theFileNameQString );
238 
240  static QDateTime lastModified( const QString & name );
241 
243  void setDataProvider( const QString & provider );
244 
246  LayerType rasterType() { return mRasterType; }
247 
249  //DrawingStyle drawingStyle() { return mDrawingStyle; }
250 
252  //void setDrawingStyle( const DrawingStyle & theDrawingStyle ) { mDrawingStyle = theDrawingStyle; setRendererForDrawingStyle( theDrawingStyle ); }
253 
255  void setRenderer( QgsRasterRenderer* theRenderer );
256  QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
257 
259  QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
260 
261  QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); }
262  QgsHueSaturationFilter * hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
263 
265  QgsRasterPipe * pipe() { return &mPipe; }
266 
268  int width() const;
269 
271  int height() const;
272 
274  int bandCount() const;
275 
277  const QString bandName( int theBandNoInt );
278 
280  QgsRasterDataProvider* dataProvider();
281 
285  const QgsRasterDataProvider* dataProvider() const;
286 
289  virtual void reload();
290 
292  bool draw( QgsRenderContext& rendererContext );
293 
295  void draw( QPainter * theQPainter,
296  QgsRasterViewPort * myRasterViewPort,
297  const QgsMapToPixel* theQgsMapToPixel = 0 );
298 
300  QString lastError();
301 
303  QString lastErrorTitle();
304 
307  QList< QPair< QString, QColor > > legendSymbologyItems() const;
308 
310  QString metadata();
311 
313  QPixmap paletteAsPixmap( int theBandNumber = 1 );
314 
318  QString providerType() const;
319 
321  double rasterUnitsPerPixelX();
322  double rasterUnitsPerPixelY();
323 
332  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
334  QgsRectangle theExtent = QgsRectangle(),
335  int theSampleSize = SAMPLE_SIZE,
336  bool theGenerateLookupTableFlag = true );
337 
339  void setDefaultContrastEnhancement();
340 
342  void setDrawingStyle( const QString & theDrawingStyleQString );
343 
345  void showProgress( int theValue );
346 
348  virtual QStringList subLayers() const;
349 
351  QPixmap previewAsPixmap( QSize size, QColor bgColor = Qt::white );
352 
354  void triggerRepaint();
355 
362  virtual void setLayerOrder( const QStringList &layers );
363 
367  virtual void setSubLayerVisibility( QString name, bool vis );
368 
370  virtual QDateTime timestamp() const { return mDataProvider->timestamp() ; }
371 
372  public slots:
373  void showStatusMessage( const QString & theMessage );
374 
376  void updateProgress( int, int );
377 
379  void onProgress( int, double, QString );
380 
381  signals:
383  void progressUpdate( int theValue );
384 
389  void dataChanged();
390 
391  protected:
393  bool readSymbology( const QDomNode& node, QString& errorMessage );
394 
396  bool readXml( const QDomNode& layer_node );
397 
399  bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
400 
402  bool writeXml( QDomNode & layer_node, QDomDocument & doc );
403 
404  private:
406  void init();
407 
409  void closeDataProvider();
410 
412  bool update();
413 
415  void setRendererForDrawingStyle( const QgsRaster::DrawingStyle & theDrawingStyle );
416 
418  const QString QSTRING_NOT_SET;
419  const QString TRSTRING_NOT_SET;
420 
423 
424  //DrawingStyle mDrawingStyle;
425 
427  QString mError;
428 
430  QString mErrorCaption;
431 
433  QDateTime mLastModified;
434 
436 
438  QString mProviderKey;
439 
441 
443 };
444 
445 #endif