QGIS API Documentation  2.99.0-Master (0a63d1f)
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 "qgis_core.h"
25 #include <QColor>
26 #include <QDateTime>
27 #include <QList>
28 #include <QMap>
29 #include <QPair>
30 #include <QVector>
31 
32 #include "qgis.h"
33 #include "qgsmaplayer.h"
34 #include "qgsraster.h"
35 #include "qgsrasterpipe.h"
36 #include "qgsrasterviewport.h"
37 #include "qgsrasterminmaxorigin.h"
38 #include "qgscontrastenhancement.h"
39 
40 class QgsMapToPixel;
41 class QgsRasterRenderer;
42 class QgsRectangle;
43 class QImage;
44 class QLibrary;
45 class QPixmap;
46 class QSlider;
47 
48 typedef QList < QPair< QString, QColor > > QgsLegendColorList;
49 
137 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
138 {
139  Q_OBJECT
140  public:
141 
143  static const double SAMPLE_SIZE;
144 
147 
150 
153 
156 
159 
162 
164  QgsRasterLayer();
165 
182  QgsRasterLayer( const QString &path,
183  const QString &baseName = QString::null,
184  bool loadDefaultStyleFlag = true );
185 
186  //TODO - QGIS 3.0
187  //This constructor is confusing if used with string literals for providerKey,
188  //as the previous constructor will be called with the literal for providerKey
189  //implicitly converted to a bool.
190  //for QGIS 3.0, make either constructor explicit or alter the signatures
192  QgsRasterLayer( const QString &uri,
193  const QString &baseName,
194  const QString &providerKey,
195  bool loadDefaultStyleFlag = true );
196 
197  ~QgsRasterLayer();
198 
201  {
206  UserDefinedShader
207  };
208 
211  {
215  ColorLayer
216  };
217 
223  static bool isValidRasterFileName( const QString & theFileNameQString, QString &retError );
224  static bool isValidRasterFileName( const QString & theFileNameQString );
225 
227  static QDateTime lastModified( const QString & name );
228 
230  void setDataProvider( const QString & provider );
231 
233  LayerType rasterType() { return mRasterType; }
234 
236  void setRenderer( QgsRasterRenderer* theRenderer );
237  QgsRasterRenderer* renderer() const { return mPipe.renderer(); }
238 
240  QgsRasterResampleFilter * resampleFilter() const { return mPipe.resampleFilter(); }
241 
242  QgsBrightnessContrastFilter * brightnessFilter() const { return mPipe.brightnessFilter(); }
243  QgsHueSaturationFilter * hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
244 
246  QgsRasterPipe * pipe() { return &mPipe; }
247 
249  int width() const;
250 
252  int height() const;
253 
255  int bandCount() const;
256 
258  QString bandName( int theBandNoInt ) const;
259 
261  QgsRasterDataProvider* dataProvider();
262 
266  const QgsRasterDataProvider* dataProvider() const;
267 
269  virtual void reload() override;
270 
274  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) override;
275 
277  void draw( QPainter * theQPainter,
278  QgsRasterViewPort * myRasterViewPort,
279  const QgsMapToPixel* theQgsMapToPixel = nullptr );
280 
282  QgsLegendColorList legendSymbologyItems() const;
283 
284  virtual bool isSpatial() const override { return true; }
285 
287  QString metadata() const override;
288 
290  QPixmap paletteAsPixmap( int theBandNumber = 1 );
291 
293  QString providerType() const;
294 
296  double rasterUnitsPerPixelX();
297  double rasterUnitsPerPixelY();
298 
307  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
309  const QgsRectangle& theExtent = QgsRectangle(),
310  int theSampleSize = SAMPLE_SIZE,
311  bool theGenerateLookupTableFlag = true );
312 
316  // Used by QgisApp::legendLayerStretchUsingCurrentExtent()
317  void refreshContrastEnhancement( const QgsRectangle& theExtent );
318 
322  // Used by QgsRasterLayerRenderer
323  void refreshRendererIfNeeded( QgsRasterRenderer* rasterRenderer, const QgsRectangle& theExtent );
324 
328  bool defaultContrastEnhancementSettings(
330  QgsRasterMinMaxOrigin::Limits& myLimits ) const;
331 
333  void setDefaultContrastEnhancement();
334 
336  void showProgress( int theValue );
337 
339  virtual QStringList subLayers() const override;
340 
343  QImage previewAsImage( QSize size, const QColor& bgColor = Qt::white,
344  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
345 
352  virtual void setLayerOrder( const QStringList &layers ) override;
353 
357  virtual void setSubLayerVisibility( const QString& name, bool vis ) override;
358 
360  virtual QDateTime timestamp() const override;
361 
362  public slots:
363  void showStatusMessage( const QString & theMessage );
364 
366  void onProgress( int, double, const QString& );
367 
368  signals:
370  void progressUpdate( int theValue );
371 
372  protected:
374  bool readSymbology( const QDomNode& node, QString& errorMessage ) override;
375 
377  bool readStyle( const QDomNode &node, QString &errorMessage ) override;
378 
380  bool readXml( const QDomNode& layer_node ) override;
381 
383  bool writeSymbology( QDomNode&, QDomDocument& doc, QString& errorMessage ) const override;
384 
386  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const override;
387 
389  bool writeXml( QDomNode & layer_node, QDomDocument & doc ) const override;
390 
391  private:
393  void init();
394 
396  void closeDataProvider();
397 
399  bool update();
400 
402  void setRendererForDrawingStyle( QgsRaster::DrawingStyle theDrawingStyle );
403 
404  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm theAlgorithm,
406  const QgsRectangle& theExtent,
407  int theSampleSize,
408  bool theGenerateLookupTableFlag,
409  QgsRasterRenderer* rasterRenderer );
410 
411  void computeMinMax( int band,
412  const QgsRasterMinMaxOrigin& mmo,
414  const QgsRectangle& extent,
415  int sampleSize,
416  double& min, double& max );
417 
419  const QString QSTRING_NOT_SET;
420  const QString TRSTRING_NOT_SET;
421 
423  QgsRasterDataProvider* mDataProvider;
424 
426  QDateTime mLastModified;
427 
428  QgsRasterViewPort mLastViewPort;
429 
431  QString mProviderKey;
432 
433  LayerType mRasterType;
434 
435  QgsRasterPipe mPipe;
436 
438  QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;
439 };
440 
441 #endif
virtual QStringList subLayers() const
Returns the sublayers of this layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Base class for all map layer types.
Definition: qgsmaplayer.h:50
Base class for processing modules.
Definition: qgsrasterpipe.h:44
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type different from Byte.
QgsHueSaturationFilter * hueSaturationFilter() const
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
Definition: qgsraster.h:104
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:296
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 QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:696
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage) const =0
Write the symbology for the layer into the docment provided.
QgsBrightnessContrastFilter * brightnessFilter() const
ColorShadingAlgorithm
This enumerator describes the types of shading that can be used.
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type Byte.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
This class describes the origin of min/max values.
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 void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
LayerType rasterType()
Accessor for raster layer type (which is a read only property)
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
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.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:437
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
Limits
This enumerator describes the limits used to compute min/max values.
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.
QgsRasterResampleFilter * resampleFilter() const
Set raster resample filter. Takes ownership of the resample filter object.
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.
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...
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 QString metadata() const
Obtain Metadata for this 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.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type Byte.
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
Base class for raster data providers.