QGIS API Documentation  2.2.0-Valmiera
 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  void setRenderer( QgsRasterRenderer* theRenderer );
250  QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
251 
253  QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
254 
255  QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); }
256  QgsHueSaturationFilter * hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
257 
259  QgsRasterPipe * pipe() { return &mPipe; }
260 
262  int width() const;
263 
265  int height() const;
266 
268  int bandCount() const;
269 
271  const QString bandName( int theBandNoInt );
272 
274  QgsRasterDataProvider* dataProvider();
275 
279  const QgsRasterDataProvider* dataProvider() const;
280 
283  virtual void reload();
284 
286  bool draw( QgsRenderContext& rendererContext );
287 
289  void draw( QPainter * theQPainter,
290  QgsRasterViewPort * myRasterViewPort,
291  const QgsMapToPixel* theQgsMapToPixel = 0 );
292 
294  QString lastError();
295 
297  QString lastErrorTitle();
298 
301  QList< QPair< QString, QColor > > legendSymbologyItems() const;
302 
304  QString metadata();
305 
307  QPixmap paletteAsPixmap( int theBandNumber = 1 );
308 
312  QString providerType() const;
313 
315  double rasterUnitsPerPixelX();
316  double rasterUnitsPerPixelY();
317 
326  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
328  QgsRectangle theExtent = QgsRectangle(),
329  int theSampleSize = SAMPLE_SIZE,
330  bool theGenerateLookupTableFlag = true );
331 
333  void setDefaultContrastEnhancement();
334 
336  void setDrawingStyle( const QString & theDrawingStyleQString );
337 
339  void showProgress( int theValue );
340 
342  virtual QStringList subLayers() const;
343 
345  QPixmap previewAsPixmap( QSize size, QColor bgColor = Qt::white );
346 
348  void triggerRepaint();
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  void updateProgress( int, int );
371 
373  void onProgress( int, double, QString );
374 
375  signals:
377  void progressUpdate( int theValue );
378 
383  void dataChanged();
384 
386  void rendererChanged();
387 
388  protected:
390  bool readSymbology( const QDomNode& node, QString& errorMessage );
391 
393  bool readXml( const QDomNode& layer_node );
394 
396  bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
397 
399  bool writeXml( QDomNode & layer_node, QDomDocument & doc );
400 
401  private:
403  void init();
404 
406  void closeDataProvider();
407 
409  bool update();
410 
412  void setRendererForDrawingStyle( const QgsRaster::DrawingStyle & theDrawingStyle );
413 
415  const QString QSTRING_NOT_SET;
416  const QString TRSTRING_NOT_SET;
417 
420 
421  //DrawingStyle mDrawingStyle;
422 
424  QString mError;
425 
427  QString mErrorCaption;
428 
430  QDateTime mLastModified;
431 
433 
435  QString mProviderKey;
436 
438 
440 };
441 
442 #endif