QGIS API Documentation  2.99.0-Master (c558d51)
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"
32 #include "qgsmaplayer.h"
33 #include "qgsraster.h"
34 #include "qgsrasterpipe.h"
35 #include "qgsrasterviewport.h"
36 #include "qgscontrastenhancement.h"
37 
38 class QgsMapToPixel;
39 class QgsRasterRenderer;
40 class QgsRectangle;
41 class QImage;
42 class QLibrary;
43 class QPixmap;
44 class QSlider;
45 
46 typedef QList < QPair< QString, QColor > > QgsLegendColorList;
47 
135 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
136 {
137  Q_OBJECT
138  public:
140  static const double CUMULATIVE_CUT_LOWER;
141 
143  static const double CUMULATIVE_CUT_UPPER;
144 
146  static const double SAMPLE_SIZE;
147 
149  QgsRasterLayer();
150 
167  QgsRasterLayer( const QString &path,
168  const QString &baseName = QString::null,
169  bool loadDefaultStyleFlag = true );
170 
171  //TODO - QGIS 3.0
172  //This constructor is confusing if used with string literals for providerKey,
173  //as the previous constructor will be called with the literal for providerKey
174  //implicitly converted to a bool.
175  //for QGIS 3.0, make either constructor explicit or alter the signatures
177  QgsRasterLayer( const QString &uri,
178  const QString &baseName,
179  const QString &providerKey,
180  bool loadDefaultStyleFlag = true );
181 
183  ~QgsRasterLayer();
184 
187  {
192  UserDefinedShader
193  };
194 
197  {
201  ColorLayer
202  };
203 
209  static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
210  static bool isValidRasterFileName( const QString & theFileNameQString );
211 
213  static QDateTime lastModified( const QString & name );
214 
216  void setDataProvider( const QString & provider );
217 
219  LayerType rasterType() { return mRasterType; }
220 
222  void setRenderer( QgsRasterRenderer* theRenderer );
223  QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
224 
226  QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
227 
228  QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); }
229  QgsHueSaturationFilter * hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
230 
232  QgsRasterPipe * pipe() { return &mPipe; }
233 
235  int width() const;
236 
238  int height() const;
239 
241  int bandCount() const;
242 
244  QString bandName( int theBandNoInt ) const;
245 
247  QgsRasterDataProvider* dataProvider();
248 
252  const QgsRasterDataProvider* dataProvider() const;
253 
255  virtual void reload() override;
256 
260  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) override;
261 
263  void draw( QPainter * theQPainter,
264  QgsRasterViewPort * myRasterViewPort,
265  const QgsMapToPixel* theQgsMapToPixel = nullptr );
266 
268  QgsLegendColorList legendSymbologyItems() const;
269 
270  virtual bool isSpatial() const override { return true; }
271 
273  QString metadata() const override;
274 
276  QPixmap paletteAsPixmap( int theBandNumber = 1 );
277 
279  QString providerType() const;
280 
282  double rasterUnitsPerPixelX();
283  double rasterUnitsPerPixelY();
284 
293  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
295  const QgsRectangle& theExtent = QgsRectangle(),
296  int theSampleSize = SAMPLE_SIZE,
297  bool theGenerateLookupTableFlag = true );
298 
300  void setDefaultContrastEnhancement();
301 
303  void showProgress( int theValue );
304 
306  virtual QStringList subLayers() const override;
307 
310  QImage previewAsImage( QSize size, const QColor& bgColor = Qt::white,
311  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
312 
319  virtual void setLayerOrder( const QStringList &layers ) override;
320 
324  virtual void setSubLayerVisibility( const QString& name, bool vis ) override;
325 
327  virtual QDateTime timestamp() const override;
328 
329  public slots:
330  void showStatusMessage( const QString & theMessage );
331 
333  void onProgress( int, double, const QString& );
334 
335  signals:
337  void progressUpdate( int theValue );
338 
339  protected:
341  bool readSymbology( const QDomNode& node, QString& errorMessage ) override;
342 
344  bool readStyle( const QDomNode &node, QString &errorMessage ) override;
345 
347  bool readXml( const QDomNode& layer_node ) override;
348 
350  bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const override;
351 
353  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const override;
354 
356  bool writeXml( QDomNode & layer_node, QDomDocument & doc ) const override;
357 
358  private:
360  void init();
361 
363  void closeDataProvider();
364 
366  bool update();
367 
369  void setRendererForDrawingStyle( QgsRaster::DrawingStyle theDrawingStyle );
370 
372  const QString QSTRING_NOT_SET;
373  const QString TRSTRING_NOT_SET;
374 
376  QgsRasterDataProvider* mDataProvider;
377 
379  QDateTime mLastModified;
380 
381  QgsRasterViewPort mLastViewPort;
382 
384  QString mProviderKey;
385 
386  LayerType mRasterType;
387 
388  QgsRasterPipe mPipe;
389 };
390 
391 #endif
virtual QStringList subLayers() const
Returns the sublayers of this layer.
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:43
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
Definition: qgsraster.h:112
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsRasterPipe * pipe()
Get raster pipe.
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage) const
Write just the style information for the layer into the document.
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:290
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.
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage) const =0
Write the symbology for the layer into the docment provided.
ColorShadingAlgorithm
This enumerator describes the types of shading that can be used.
virtual QString metadata() const
Obtain Metadata for this layer.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
QgsRasterRenderer * renderer() const
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
static const double CUMULATIVE_CUT_UPPER
Default cumulative cut upper limit.
ContrastEnhancementLimits
Contrast enhancement limits.
Definition: qgsraster.h:103
QgsRasterResampleFilter * resampleFilter() const
Set raster resample filter. Takes ownership of the resample filter object.
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.
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 bool writeXml(QDomNode &layer_node, QDomDocument &document) const
Called by writeLayerXML(), used by children to write state specific to them to project files...
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.
QgsHueSaturationFilter * hueSaturationFilter() const
Base class for utility classes that encapsulate information necessary for rendering of map layers...
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)=0
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:690
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.
Raster renderer pipe that applies colors to a raster.
QgsBrightnessContrastFilter * brightnessFilter() const
Base class for raster data providers.