QGIS API Documentation  3.2.0-Bonn (bc43194)
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 "qgis_core.h"
25 #include "qgis_sip.h"
26 #include <QColor>
27 #include <QDateTime>
28 #include <QList>
29 #include <QMap>
30 #include <QPair>
31 #include <QVector>
32 
33 #include "qgis.h"
34 #include "qgsmaplayer.h"
35 #include "qgsraster.h"
36 #include "qgsrasterdataprovider.h"
37 #include "qgsrasterpipe.h"
38 #include "qgsrasterviewport.h"
39 #include "qgsrasterminmaxorigin.h"
40 #include "qgscontrastenhancement.h"
41 
42 class QgsMapToPixel;
43 class QgsRasterRenderer;
44 class QgsRectangle;
45 class QImage;
46 class QLibrary;
47 class QPixmap;
48 class QSlider;
49 
50 typedef QList < QPair< QString, QColor > > QgsLegendColorList;
51 
139 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
140 {
141  Q_OBJECT
142  public:
143 
145  static const double SAMPLE_SIZE;
146 
149 
152 
155 
158 
161 
164 
166  QgsRasterLayer();
167 
173  {
174 
178  explicit LayerOptions( bool loadDefaultStyle = true )
179  : loadDefaultStyle( loadDefaultStyle )
180  {}
181 
183  bool loadDefaultStyle = true;
184  };
185 
203  explicit QgsRasterLayer( const QString &uri,
204  const QString &baseName = QString(),
205  const QString &providerKey = "gdal",
207 
208  ~QgsRasterLayer() override;
209 
216  QgsRasterLayer *clone() const override SIP_FACTORY;
217 
220  {
225  UserDefinedShader
226  };
227 
230  {
234  ColorLayer
235  };
236 
243  static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
244  // TODO QGIS 4.0 - rename fileNameQString to fileName
245 
246  static bool isValidRasterFileName( const QString &fileNameQString );
247 
249  static QDateTime lastModified( const QString &name );
250 
255  Q_DECL_DEPRECATED void setDataProvider( const QString &provider ) SIP_DEPRECATED;
256 
263  void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options );
264 
268  LayerType rasterType() { return mRasterType; }
269 
271  void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
272  QgsRasterRenderer *renderer() const { return mPipe.renderer(); }
273 
275  QgsRasterResampleFilter *resampleFilter() const { return mPipe.resampleFilter(); }
276 
277  QgsBrightnessContrastFilter *brightnessFilter() const { return mPipe.brightnessFilter(); }
278  QgsHueSaturationFilter *hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
279 
283  QgsRasterPipe *pipe() { return &mPipe; }
284 
289  int width() const;
290 
295  int height() const;
296 
300  int bandCount() const;
301 
305  QString bandName( int bandNoInt ) const;
306 
307  // Returns nullptr if not using the data provider model (i.e. directly using GDAL)
308  QgsRasterDataProvider *dataProvider() override;
309 
310  // Returns nullptr if not using the data provider model (i.e. directly using GDAL)
311  const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
312 
313  void reload() override;
314  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
315 
317  void draw( QPainter *theQPainter,
318  QgsRasterViewPort *myRasterViewPort,
319  const QgsMapToPixel *qgsMapToPixel = nullptr );
320 
322  QgsLegendColorList legendSymbologyItems() const;
323 
324  bool isSpatial() const override { return true; }
325 
326  QString htmlMetadata() const override;
327 
332  QPixmap paletteAsPixmap( int bandNumber = 1 );
333 
335  QString providerType() const;
336 
345  double rasterUnitsPerPixelX() const;
346 
354  double rasterUnitsPerPixelY() const;
355 
367  const QgsRectangle &extent = QgsRectangle(),
368  int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
369  bool generateLookupTableFlag = true );
370 
375  void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
376 
381  void refreshRendererIfNeeded( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent ) SIP_SKIP;
382 
387  bool defaultContrastEnhancementSettings(
389  QgsRasterMinMaxOrigin::Limits &myLimits ) const SIP_SKIP;
390 
392  void setDefaultContrastEnhancement();
393 
394  QStringList subLayers() const override;
395 
399  QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
400  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
401 
402  void setLayerOrder( const QStringList &layers ) override;
403  void setSubLayerVisibility( const QString &name, bool vis ) override;
404  QDateTime timestamp() const override;
405 
406  public slots:
407  void showStatusMessage( const QString &message );
408 
409  protected:
410  bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) override;
411  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context ) override;
412  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
413  bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
414  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
415  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
416  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
417  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
418  private:
420  void init();
421 
423  void closeDataProvider();
424 
426  bool update();
427 
429  void setRendererForDrawingStyle( QgsRaster::DrawingStyle drawingStyle );
430 
431  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
433  const QgsRectangle &extent,
434  int sampleSize,
435  bool generateLookupTableFlag,
436  QgsRasterRenderer *rasterRenderer );
437 
438  void computeMinMax( int band,
439  const QgsRasterMinMaxOrigin &mmo,
441  const QgsRectangle &extent,
442  int sampleSize,
443  double &min, double &max );
444 
446  const QString QSTRING_NOT_SET;
447  const QString TRSTRING_NOT_SET;
448 
450  QgsRasterDataProvider *mDataProvider = nullptr;
451 
453  QDateTime mLastModified;
454 
455  QgsRasterViewPort mLastViewPort;
456 
458  QString mProviderKey;
459 
460  LayerType mRasterType;
461 
462  QgsRasterPipe mPipe;
463 
465  QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;
466 };
467 
468 // clazy:excludeall=qstring-allocations
469 
470 #endif
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Base class for all map layer types.
Definition: qgsmaplayer.h:61
Base class for processing modules.
Definition: qgsrasterpipe.h:46
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:89
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsRasterPipe * pipe()
Returns the raster pipe.
Resample filter pipe for rasters.
QgsRasterRenderer * renderer() const
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
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:36
This class describes the origin of min/max values.
#define SIP_SKIP
Definition: qgis_sip.h:119
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
LayerType rasterType()
Returns the raster layer type (which is a read only property).
#define SIP_FACTORY
Definition: qgis_sip.h:69
#define SIP_DEPRECATED
Definition: qgis_sip.h:99
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
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
LayerOptions(bool loadDefaultStyle=true)
Constructor for LayerOptions.
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used...
Contains information about the context of a rendering operation.
Setting options for creating vector data providers.
QgsRasterResampleFilter * resampleFilter() const
Sets raster resample filter. Takes ownership of the resample filter object.
Brightness/contrast filter pipe for rasters.
Color and saturation filter pipe for rasters.
bool isSpatial() const override
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
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.
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.
Setting options for loading raster layers.
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74
Base class for raster data providers.