QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 : tim@linfiniti.com
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 
285  virtual void reload();
286 
290  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext );
291 
293  bool draw( QgsRenderContext& rendererContext );
294 
296  void draw( QPainter * theQPainter,
297  QgsRasterViewPort * myRasterViewPort,
298  const QgsMapToPixel* theQgsMapToPixel = 0 );
299 
302  QgsLegendColorList legendSymbologyItems() const;
303 
305  QString metadata();
306 
308  QPixmap paletteAsPixmap( int theBandNumber = 1 );
309 
313  QString providerType() const;
314 
316  double rasterUnitsPerPixelX();
317  double rasterUnitsPerPixelY();
318 
327  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
329  QgsRectangle theExtent = QgsRectangle(),
330  int theSampleSize = SAMPLE_SIZE,
331  bool theGenerateLookupTableFlag = true );
332 
334  void setDefaultContrastEnhancement();
335 
337  void setDrawingStyle( const QString & theDrawingStyleQString );
338 
340  void showProgress( int theValue );
341 
343  virtual QStringList subLayers() const;
344 
347  Q_DECL_DEPRECATED QPixmap previewAsPixmap( QSize size, QColor bgColor = Qt::white );
348 
351  QImage previewAsImage( QSize size, QColor bgColor = Qt::white,
352  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
353 
360  virtual void setLayerOrder( const QStringList &layers );
361 
365  virtual void setSubLayerVisibility( QString name, bool vis );
366 
368  virtual QDateTime timestamp() const { return mDataProvider->timestamp() ; }
369 
370  public slots:
371  void showStatusMessage( const QString & theMessage );
372 
374  Q_DECL_DEPRECATED void updateProgress( int, int );
375 
377  void onProgress( int, double, QString );
378 
379  signals:
381  void progressUpdate( int theValue );
382 
387  void dataChanged();
388 
389  protected:
391  bool readSymbology( const QDomNode& node, QString& errorMessage );
392 
394  bool readXml( const QDomNode& layer_node );
395 
397  bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const;
398 
400  bool writeXml( QDomNode & layer_node, QDomDocument & doc );
401 
402  private:
404  void init();
405 
407  void closeDataProvider();
408 
410  bool update();
411 
413  void setRendererForDrawingStyle( const QgsRaster::DrawingStyle & theDrawingStyle );
414 
416  const QString QSTRING_NOT_SET;
417  const QString TRSTRING_NOT_SET;
418 
420  QgsRasterDataProvider* mDataProvider;
421 
422  //DrawingStyle mDrawingStyle;
423 
425  QDateTime mLastModified;
426 
427  QgsRasterViewPort mLastViewPort;
428 
430  QString mProviderKey;
431 
432  LayerType mRasterType;
433 
434  QgsRasterPipe mPipe;
435 };
436 
437 #endif
virtual QStringList subLayers() const
Returns the sublayers of this layer (Useful for providers that manage their own layers, such as WMS)
Definition: qgsmaplayer.cpp:757
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
Base class for processing modules.
Definition: qgsrasterpipe.h:41
virtual QString metadata()
Obtain Metadata for this layer.
Definition: qgsmaplayer.cpp:1411
ContrastEnhancementLimits
Contrast enhancement limits.
Definition: qgsraster.h:86
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
Definition: qgsrasterlayer.h:169
QgsRasterPipe * pipe()
Get raster pipe.
Definition: qgsrasterlayer.h:261
Definition: qgsrasterlayer.h:219
virtual bool readSymbology(const QDomNode &node, QString &errorMessage)=0
Read the symbology for the current layer from the Dom node supplied.
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:132
Definition: qgsrasterlayer.h:218
Resample filter pipe for rasters.
Definition: qgsrasterresamplefilter.h:31
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
Definition: qgsrasterlayer.h:180
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:137
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage) const =0
Write the symbology for the layer into the docment provided.
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used...
Definition: qgscontrastenhancement.h:44
virtual bool draw(QgsRenderContext &rendererContext)
This is the method that does the actual work of drawing the layer onto a paint device.
Definition: qgsmaplayer.cpp:150
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
ColorShadingAlgorithm
This enumerator describes the types of shading that can be used.
Definition: qgsrasterlayer.h:215
Definition: qgsrasterlayer.h:220
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document)
called by writeLayerXML(), used by children to write state specific to them to project files...
Definition: qgsmaplayer.cpp:671
QgsRasterRenderer * renderer() const
Definition: qgsrasterlayer.h:252
static const double CUMULATIVE_CUT_UPPER
Default cumulative cut upper limit.
Definition: qgsrasterlayer.h:177
virtual void setSubLayerVisibility(QString name, bool vis)
Set the visibility of the given sublayer name.
Definition: qgsmaplayer.cpp:768
QgsRasterResampleFilter * resampleFilter() const
Set raster resample filter.
Definition: qgsrasterlayer.h:255
LayerType rasterType()
Accessor for raster layer type (which is a read only property)
Definition: qgsrasterlayer.h:248
Definition: qgsrasterlayer.h:227
QList< QPair< QString, QColor > > QgsLegendColorList
Definition: qgsrasterlayer.h:54
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
Definition: qgsrasterlayer.h:217
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsrasterlayer.h:368
virtual bool readXml(const QDomNode &layer_node)
called by readLayerXML(), used by children to read state specific to them from project files...
Definition: qgsmaplayer.cpp:425
Brightness/contrast filter pipe for rasters.
Definition: qgsbrightnesscontrastfilter.h:29
Color and saturation filter pipe for rasters.
Definition: qgshuesaturationfilter.h:29
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
Definition: qgsraster.h:95
static const double CUMULATIVE_CUT_LOWER
Default cumulative cut lower limit.
Definition: qgsrasterlayer.h:174
QgsHueSaturationFilter * hueSaturationFilter() const
Definition: qgsrasterlayer.h:258
void dataChanged()
data of layer changed added in 1.5
Base class for utility classes that encapsulate information necessary for rendering of map layers...
Definition: qgsmaplayerrenderer.h:43
Definition: qgsraster.h:89
Definition: qgsrasterlayer.h:228
This class provides details of the viewable area that a raster will be rendered into.
Definition: qgsrasterviewport.h:31
Definition: qgsrasterlayer.h:229
double size
Definition: qgssvgcache.cpp:77
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top (Useful for providers tha...
Definition: qgsmaplayer.cpp:762
LayerType
This enumerator describes the type of raster layer.
Definition: qgsrasterlayer.h:225
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:34
QgsBrightnessContrastFilter * brightnessFilter() const
Definition: qgsrasterlayer.h:257
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:53