QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
57 
145 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
146 {
147  Q_OBJECT
148  public:
150  static const double CUMULATIVE_CUT_LOWER;
151 
153  static const double CUMULATIVE_CUT_UPPER;
154 
156  static const double SAMPLE_SIZE;
157 
159  QgsRasterLayer();
160 
177  QgsRasterLayer( const QString &path,
178  const QString &baseName = QString::null,
179  bool loadDefaultStyleFlag = true );
180 
181  //TODO - QGIS 3.0
182  //This constructor is confusing if used with string literals for providerKey,
183  //as the previous constructor will be called with the literal for providerKey
184  //implicitly converted to a bool.
185  //for QGIS 3.0, make either constructor explicit or alter the signatures
187  QgsRasterLayer( const QString &uri,
188  const QString &baseName,
189  const QString &providerKey,
190  bool loadDefaultStyleFlag = true );
191 
193  ~QgsRasterLayer();
194 
197  {
202  UserDefinedShader
203  };
204 
207  {
211  ColorLayer
212  };
213 
219  static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
220  static bool isValidRasterFileName( const QString & theFileNameQString );
221 
223  static QDateTime lastModified( const QString & name );
224 
226  void setDataProvider( const QString & provider );
227 
229  LayerType rasterType() { return mRasterType; }
230 
232  void setRenderer( QgsRasterRenderer* theRenderer );
233  QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
234 
236  QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
237 
238  QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); }
239  QgsHueSaturationFilter * hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
240 
242  QgsRasterPipe * pipe() { return &mPipe; }
243 
245  int width() const;
246 
248  int height() const;
249 
251  int bandCount() const;
252 
254  const QString bandName( int theBandNoInt );
255 
257  QgsRasterDataProvider* dataProvider();
258 
262  const QgsRasterDataProvider* dataProvider() const;
263 
265  virtual void reload() override;
266 
270  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) override;
271 
273  bool draw( QgsRenderContext& rendererContext ) override;
274 
276  void draw( QPainter * theQPainter,
277  QgsRasterViewPort * myRasterViewPort,
278  const QgsMapToPixel* theQgsMapToPixel = nullptr );
279 
281  QgsLegendColorList legendSymbologyItems() const;
282 
283  virtual bool isSpatial() const override { return true; }
284 
286  QString metadata() override;
287 
289  QPixmap paletteAsPixmap( int theBandNumber = 1 );
290 
292  QString providerType() const;
293 
295  double rasterUnitsPerPixelX();
296  double rasterUnitsPerPixelY();
297 
306  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
308  const QgsRectangle& theExtent = QgsRectangle(),
309  int theSampleSize = SAMPLE_SIZE,
310  bool theGenerateLookupTableFlag = true );
311 
313  void setDefaultContrastEnhancement();
314 
318  Q_DECL_DEPRECATED void setDrawingStyle( const QString & theDrawingStyleQString );
319 
321  void showProgress( int theValue );
322 
324  virtual QStringList subLayers() const override;
325 
328  Q_DECL_DEPRECATED QPixmap previewAsPixmap( QSize size, const QColor& bgColor = Qt::white );
329 
332  QImage previewAsImage( QSize size, const QColor& bgColor = Qt::white,
333  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
334 
341  virtual void setLayerOrder( const QStringList &layers ) override;
342 
346  virtual void setSubLayerVisibility( const QString& name, bool vis ) override;
347 
349  virtual QDateTime timestamp() const override { return mDataProvider->timestamp() ; }
350 
351  public slots:
352  void showStatusMessage( const QString & theMessage );
353 
355  Q_DECL_DEPRECATED void updateProgress( int, int );
356 
358  void onProgress( int, double, const QString& );
359 
360  signals:
362  void progressUpdate( int theValue );
363 
364  protected:
366  bool readSymbology( const QDomNode& node, QString& errorMessage ) override;
367 
369  bool readStyle( const QDomNode &node, QString &errorMessage ) override;
370 
372  bool readXml( const QDomNode& layer_node ) override;
373 
375  bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const override;
376 
378  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const override;
379 
381  bool writeXml( QDomNode & layer_node, QDomDocument & doc ) override;
382 
383  private:
385  void init();
386 
388  void closeDataProvider();
389 
391  bool update();
392 
394  void setRendererForDrawingStyle( QgsRaster::DrawingStyle theDrawingStyle );
395 
397  const QString QSTRING_NOT_SET;
398  const QString TRSTRING_NOT_SET;
399 
401  QgsRasterDataProvider* mDataProvider;
402 
404  QDateTime mLastModified;
405 
406  QgsRasterViewPort mLastViewPort;
407 
409  QString mProviderKey;
410 
411  LayerType mRasterType;
412 
413  QgsRasterPipe mPipe;
414 };
415 
416 #endif
virtual QStringList subLayers() const
Returns the sublayers of this layer (Useful for providers that manage their own layers, such as WMS)
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
Base class for processing modules.
Definition: qgsrasterpipe.h:42
virtual QString metadata()
Obtain Metadata for this layer.
QgsHueSaturationFilter * hueSaturationFilter() const
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
Definition: qgsraster.h:95
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsRasterPipe * pipe()
Get raster pipe.
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:250
virtual bool isSpatial() const override
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
Resample filter pipe for rasters.
QgsRasterRenderer * renderer() const
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:255
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage) const =0
Write the symbology for the layer into the docment provided.
QgsBrightnessContrastFilter * brightnessFilter() const
virtual bool draw(QgsRenderContext &rendererContext)
This is the method that does the actual work of drawing the layer onto a paint device.
ColorShadingAlgorithm
This enumerator describes the types of shading that can be used.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document)
Called by writeLayerXML(), used by children to write state specific to them to project files...
static const double CUMULATIVE_CUT_UPPER
Default cumulative cut upper limit.
ContrastEnhancementLimits
Contrast enhancement limits.
Definition: qgsraster.h:86
LayerType rasterType()
Accessor for raster layer type (which is a read only property)
virtual bool readStyle(const QDomNode &node, QString &errorMessage)
Read the style for the current layer from the Dom node supplied.
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage) const
Write just the style information for the layer into the document.
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
QList< QPair< QString, QColor > > QgsLegendColorList
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used...
Contains information about the context of a rendering operation.
virtual QDateTime timestamp() const override
Time stamp of data source in the moment when data/metadata were loaded by provider.
QgsRasterResampleFilter * resampleFilter() const
Set raster resample filter.
virtual bool readXml(const QDomNode &layer_node)
Called by readLayerXML(), used by children to read state specific to them from project files...
Brightness/contrast filter pipe for rasters.
Color and saturation filter pipe for rasters.
static const double CUMULATIVE_CUT_LOWER
Default cumulative cut lower limit.
Base class for utility classes that encapsulate information necessary for rendering of map layers...
This class provides details of the viewable area that a raster will be rendered into.
LayerType
This enumerator describes the type of raster layer.
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top (Useful for providers tha...
Raster renderer pipe that applies colors to a raster.
Base class for raster data providers.