QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 "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_sip.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;
46 
47 class QImage;
48 class QPixmap;
49 class QSlider;
50 
51 typedef QList < QPair< QString, QColor > > QgsLegendColorList;
52 
72 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
73 {
74  Q_OBJECT
75  public:
76 
78  static const double SAMPLE_SIZE;
79 
82 
85 
88 
91 
94 
97 
100 
106  {
107 
111  explicit LayerOptions( bool loadDefaultStyle = true,
113  : loadDefaultStyle( loadDefaultStyle )
114  , transformContext( transformContext )
115  {}
116 
118  bool loadDefaultStyle = true;
119 
125 
139  bool skipCrsValidation = false;
140 
141  };
142 
155  explicit QgsRasterLayer( const QString &uri,
156  const QString &baseName = QString(),
157  const QString &providerType = "gdal",
159 
160  ~QgsRasterLayer() override;
161 
168  QgsRasterLayer *clone() const override SIP_FACTORY;
169 
172  {
177  UserDefinedShader
178  };
179 
182  {
186  ColorLayer
187  };
188 
195  static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
196  // TODO QGIS 4.0 - rename fileNameQString to fileName
197 
198  static bool isValidRasterFileName( const QString &fileNameQString );
199 
201  static QDateTime lastModified( const QString &name );
202 
207  Q_DECL_DEPRECATED void setDataProvider( const QString &provider ) SIP_DEPRECATED;
208 
215  void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options );
216 
229  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false ) override;
230 
234  LayerType rasterType() { return mRasterType; }
235 
240  void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
241 
247  QgsRasterRenderer *renderer() const { return mPipe.renderer(); }
248 
255  QgsRasterResampleFilter *resampleFilter() const { return mPipe.resampleFilter(); }
256 
263  QgsBrightnessContrastFilter *brightnessFilter() const { return mPipe.brightnessFilter(); }
264 
271  QgsHueSaturationFilter *hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
272 
276  QgsRasterPipe *pipe() { return &mPipe; }
277 
282  int width() const;
283 
288  int height() const;
289 
293  int bandCount() const;
294 
298  QString bandName( int bandNoInt ) const;
299 
306 
312  const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
313 
314  void reload() override;
315  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
316 
318  void draw( QPainter *theQPainter,
319  QgsRasterViewPort *myRasterViewPort,
320  const QgsMapToPixel *qgsMapToPixel = nullptr );
321 
323  QgsLegendColorList legendSymbologyItems() const;
324 
325  bool isSpatial() const override { return true; }
326 
327  QString htmlMetadata() const override;
328 
333  QPixmap paletteAsPixmap( int bandNumber = 1 );
334 
336  QString providerType() const;
337 
346  double rasterUnitsPerPixelX() const;
347 
355  double rasterUnitsPerPixelY() const;
356 
368  const QgsRectangle &extent = QgsRectangle(),
369  int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
370  bool generateLookupTableFlag = true );
371 
376  void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
377 
382  void refreshRendererIfNeeded( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent ) SIP_SKIP;
383 
389  virtual QString subsetString() const;
390 
399  virtual bool setSubsetString( const QString &subset );
400 
405  bool defaultContrastEnhancementSettings(
407  QgsRasterMinMaxOrigin::Limits &myLimits ) const SIP_SKIP;
408 
410  void setDefaultContrastEnhancement();
411 
412  QStringList subLayers() const override;
413 
417  QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
418  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
419 
420  void setLayerOrder( const QStringList &layers ) override;
421  void setSubLayerVisibility( const QString &name, bool vis ) override;
422  QDateTime timestamp() const override;
423  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
424 
434  bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props = QgsStringMap() ) const;
435 
444  bool ignoreExtents() const;
445 
447 
448  public slots:
449  void showStatusMessage( const QString &message );
450 
456  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
457 
458  signals:
459 
464  void subsetStringChanged();
465 
466 
467  protected:
468  bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
469  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
470  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
471  bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
472  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
473  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
474  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
475  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
476  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
477  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
478 
479  private:
481  void init();
482 
484  void closeDataProvider();
485 
487  bool update();
488 
490  void setRendererForDrawingStyle( QgsRaster::DrawingStyle drawingStyle );
491 
494  const QgsRectangle &extent,
495  int sampleSize,
496  bool generateLookupTableFlag,
497  QgsRasterRenderer *rasterRenderer );
498 
500  void refreshRenderer( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent );
501 
502  void computeMinMax( int band,
503  const QgsRasterMinMaxOrigin &mmo,
505  const QgsRectangle &extent,
506  int sampleSize,
507  double &min, double &max );
508 
510  const QString QSTRING_NOT_SET;
511  const QString TRSTRING_NOT_SET;
512 
514  QgsRasterDataProvider *mDataProvider = nullptr;
515 
517  QgsRasterLayerTemporalProperties *mTemporalProperties = nullptr;
518 
520  QDateTime mLastModified;
521 
522  QgsRasterViewPort mLastViewPort;
523 
524  LayerType mRasterType;
525 
526  QgsRasterPipe mPipe;
527 
529  QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;
530 
531  QDomDocument mOriginalStyleDocument;
532  QDomElement mOriginalStyleElement;
533 };
534 
535 // clazy:excludeall=qstring-allocations
536 
537 #endif
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
qgsrasterminmaxorigin.h
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
QgsMapLayer::writeXml
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by children to write state specific to them to project files.
Definition: qgsmaplayer.cpp:596
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:104
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
qgsrasterpipe.h
QgsRasterLayer::UndefinedShader
@ UndefinedShader
Definition: qgsrasterlayer.h:173
qgsrasterviewport.h
QgsMapLayer::clone
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
QgsRasterMinMaxOrigin::Limits
Limits
This enumerator describes the limits used to compute min/max values.
Definition: qgsrasterminmaxorigin.h:71
algorithm
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
qgscontrastenhancement.h
QgsMapLayer::subLayers
virtual QStringList subLayers() const
Returns the sublayers of this layer.
Definition: qgsmaplayer.cpp:746
QgsRasterLayer::GrayOrUndefined
@ GrayOrUndefined
Definition: qgsrasterlayer.h:183
QgsRasterLayer::SAMPLE_SIZE
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
Definition: qgsrasterlayer.h:78
QgsRaster::DrawingStyle
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
Definition: qgsraster.h:102
QgsRasterPipe
Definition: qgsrasterpipe.h:46
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
QgsRasterLayer::Multiband
@ Multiband
Definition: qgsrasterlayer.h:185
QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type Byte.
Definition: qgsrasterlayer.h:84
QgsRasterViewPort
Definition: qgsrasterviewport.h:34
QgsMapLayer::htmlMetadata
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
Definition: qgsmaplayer.cpp:1834
QgsMapLayer::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
Definition: qgsmaplayer.cpp:1885
QgsRasterLayer::LayerOptions::LayerOptions
LayerOptions(bool loadDefaultStyle=true, const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions.
Definition: qgsrasterlayer.h:111
QgsRasterLayer::SINGLE_BAND_ENHANCEMENT_ALGORITHM
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
Definition: qgsrasterlayer.h:81
QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
Definition: qgsrasterlayer.h:96
QgsRectangle
Definition: qgsrectangle.h:41
QgsRasterLayerTemporalProperties
Definition: qgsrasterlayertemporalproperties.h:35
QgsMapLayerRenderer
Definition: qgsmaplayerrenderer.h:50
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMapLayer::providerType
QString providerType() const
Returns the provider type (provider key) for this layer.
Definition: qgsmaplayer.cpp:1614
QgsRasterMinMaxOrigin
Definition: qgsrasterminmaxorigin.h:33
QgsRasterLayer::Palette
@ Palette
Definition: qgsrasterlayer.h:184
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsRasterLayer::ColorRampShader
@ ColorRampShader
Definition: qgsrasterlayer.h:176
QgsMapLayer::setSubLayerVisibility
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
Definition: qgsmaplayer.cpp:757
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgsraster.h
QgsMapLayer::encodedSource
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
Definition: qgsmaplayer.cpp:606
QgsContrastEnhancement::ContrastEnhancementAlgorithm
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used.
Definition: qgscontrastenhancement.h:48
QgsMapLayer::dataProvider
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Definition: qgsmaplayer.cpp:169
QgsRasterMinMaxOrigin::MinMax
@ MinMax
Real min-max values.
Definition: qgsrasterminmaxorigin.h:74
QgsRasterRenderer
Definition: qgsrasterrenderer.h:38
qgsmaplayer.h
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMapLayer::temporalProperties
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1194
QgsMapLayerTemporalProperties
Definition: qgsmaplayertemporalproperties.h:42
QgsHueSaturationFilter
Definition: qgshuesaturationfilter.h:31
QgsRasterLayer::FreakOutShader
@ FreakOutShader
Definition: qgsrasterlayer.h:175
QgsRasterLayer::LayerType
LayerType
This enumerator describes the type of raster layer.
Definition: qgsrasterlayer.h:181
QgsRasterLayer::ColorShadingAlgorithm
ColorShadingAlgorithm
This enumerator describes the types of shading that can be used.
Definition: qgsrasterlayer.h:171
QgsMapLayer::decodedSource
virtual QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
Definition: qgsmaplayer.cpp:612
QgsRasterLayer
Definition: qgsrasterlayer.h:72
QgsMapLayer::setTransformContext
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
QgsRasterLayer::resampleFilter
QgsRasterResampleFilter * resampleFilter() const
Returns the raster's resample filter.
Definition: qgsrasterlayer.h:255
QgsMapLayer::readSymbology
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
QgsMapLayer::setDataSource
virtual void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
Definition: qgsmaplayer.cpp:1604
QgsRasterLayer::LayerOptions
Setting options for loading raster layers.
Definition: qgsrasterlayer.h:105
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:714
QgsMapLayer::writeSymbology
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the docment provided.
QgsBrightnessContrastFilter
Definition: qgsbrightnesscontrastfilter.h:31
QgsMapToPixel
Definition: qgsmaptopixel.h:37
QgsRasterLayer::pipe
QgsRasterPipe * pipe()
Returns the raster pipe.
Definition: qgsrasterlayer.h:276
QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type different from Byte.
Definition: qgsrasterlayer.h:87
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsRasterResampleFilter
Definition: qgsrasterresamplefilter.h:32
QgsRasterLayer::SINGLE_BAND_MIN_MAX_LIMITS
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
Definition: qgsrasterlayer.h:90
QgsMapLayer::readXml
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files.
Definition: qgsmaplayer.cpp:381
QgsRasterLayer::hueSaturationFilter
QgsHueSaturationFilter * hueSaturationFilter() const
Returns the raster's hue/saturation filter.
Definition: qgsrasterlayer.h:271
QgsLegendColorList
QList< QPair< QString, QColor > > QgsLegendColorList
Definition: qgsrasterlayer.h:49
QgsRasterLayer::brightnessFilter
QgsBrightnessContrastFilter * brightnessFilter() const
Returns the raster's brightness/contrast filter.
Definition: qgsrasterlayer.h:263
QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type Byte.
Definition: qgsrasterlayer.h:93
QgsMapLayer::readStyle
virtual bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read the style for the current layer from the DOM node supplied.
Definition: qgsmaplayer.cpp:1584
QgsRasterLayer::renderer
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
Definition: qgsrasterlayer.h:247
QgsMapLayer::AllStyleCategories
@ AllStyleCategories
Definition: qgsmaplayer.h:171
QgsRasterLayer::rasterType
LayerType rasterType()
Returns the raster layer type (which is a read only property).
Definition: qgsrasterlayer.h:234
QgsRasterDataProvider
Definition: qgsrasterdataprovider.h:88
QgsMapLayer::writeStyle
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write just the symbology information for the layer into the document.
Definition: qgsmaplayer.cpp:1593
QgsRasterLayer::PseudoColorShader
@ PseudoColorShader
Definition: qgsrasterlayer.h:174
QgsMapLayer::timestamp
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.cpp:1839
QgsMapLayer::setLayerOrder
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top.
Definition: qgsmaplayer.cpp:751
qgsrasterdataprovider.h