QGIS API Documentation  3.13.0-Master (b73bd58cfb)
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"
42 
43 class QgsMapToPixel;
44 class QgsRasterRenderer;
45 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 
158  explicit QgsRasterLayer( const QString &uri,
159  const QString &baseName = QString(),
160  const QString &providerType = "gdal",
162 
163  ~QgsRasterLayer() override;
164 
171  QgsRasterLayer *clone() const override SIP_FACTORY;
172 
175  {
180  UserDefinedShader
181  };
182 
185  {
189  ColorLayer
190  };
191 
198  static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
199  // TODO QGIS 4.0 - rename fileNameQString to fileName
200 
201  static bool isValidRasterFileName( const QString &fileNameQString );
202 
204  static QDateTime lastModified( const QString &name );
205 
210  Q_DECL_DEPRECATED void setDataProvider( const QString &provider ) SIP_DEPRECATED;
211 
218  void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options );
219 
232  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false ) override;
233 
237  LayerType rasterType() { return mRasterType; }
238 
243  void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
244 
250  QgsRasterRenderer *renderer() const { return mPipe.renderer(); }
251 
258  QgsRasterResampleFilter *resampleFilter() const { return mPipe.resampleFilter(); }
259 
266  QgsBrightnessContrastFilter *brightnessFilter() const { return mPipe.brightnessFilter(); }
267 
274  QgsHueSaturationFilter *hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
275 
279  QgsRasterPipe *pipe() { return &mPipe; }
280 
285  int width() const;
286 
291  int height() const;
292 
296  int bandCount() const;
297 
301  QString bandName( int bandNoInt ) const;
302 
308  QgsRasterDataProvider *dataProvider() override;
309 
315  const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
316 
317  void reload() override;
318  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
319 
321  void draw( QPainter *theQPainter,
322  QgsRasterViewPort *myRasterViewPort,
323  const QgsMapToPixel *qgsMapToPixel = nullptr );
324 
326  QgsLegendColorList legendSymbologyItems() const;
327 
328  bool isSpatial() const override { return true; }
329 
330  QString htmlMetadata() const override;
331 
336  QPixmap paletteAsPixmap( int bandNumber = 1 );
337 
339  QString providerType() const;
340 
349  double rasterUnitsPerPixelX() const;
350 
358  double rasterUnitsPerPixelY() const;
359 
371  const QgsRectangle &extent = QgsRectangle(),
372  int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
373  bool generateLookupTableFlag = true );
374 
379  void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
380 
385  void refreshRendererIfNeeded( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent ) SIP_SKIP;
386 
392  virtual QString subsetString() const;
393 
402  virtual bool setSubsetString( const QString &subset );
403 
408  bool defaultContrastEnhancementSettings(
410  QgsRasterMinMaxOrigin::Limits &myLimits ) const SIP_SKIP;
411 
413  void setDefaultContrastEnhancement();
414 
415  QStringList subLayers() const override;
416 
420  QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
421  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
422 
423  void setLayerOrder( const QStringList &layers ) override;
424  void setSubLayerVisibility( const QString &name, bool vis ) override;
425  QDateTime timestamp() const override;
426  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
427 
437  bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props = QgsStringMap() ) const;
438 
447  bool ignoreExtents() const;
448 
452  QgsRasterLayerTemporalProperties *temporalProperties() override;
453 
454  public slots:
455  void showStatusMessage( const QString &message );
456 
462  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
463 
464  signals:
465 
470  void subsetStringChanged();
471 
472 
473  protected:
474  bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
475  bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
476  bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
477  bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
478  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
479  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
480  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
481  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
482  QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
483  QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
484 
485  private:
487  void init();
488 
490  void closeDataProvider();
491 
493  bool update();
494 
496  void setRendererForDrawingStyle( QgsRaster::DrawingStyle drawingStyle );
497 
498  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
500  const QgsRectangle &extent,
501  int sampleSize,
502  bool generateLookupTableFlag,
503  QgsRasterRenderer *rasterRenderer );
504 
506  void refreshRenderer( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent );
507 
508  void computeMinMax( int band,
509  const QgsRasterMinMaxOrigin &mmo,
511  const QgsRectangle &extent,
512  int sampleSize,
513  double &min, double &max );
514 
516  const QString QSTRING_NOT_SET;
517  const QString TRSTRING_NOT_SET;
518 
520  QgsRasterDataProvider *mDataProvider = nullptr;
521 
523  QgsRasterLayerTemporalProperties *mTemporalProperties = nullptr;
524 
526  QDateTime mLastModified;
527 
528  QgsRasterViewPort mLastViewPort;
529 
530  LayerType mRasterType;
531 
532  QgsRasterPipe mPipe;
533 
535  QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;
536 
537  QDomDocument mOriginalStyleDocument;
538  QDomElement mOriginalStyleElement;
539 };
540 
541 // clazy:excludeall=qstring-allocations
542 
543 #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:41
Base class for all map layer types.
Definition: qgsmaplayer.h:81
LayerOptions(bool loadDefaultStyle=true, const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions.
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
Returns the raster&#39;s hue/saturation filter.
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
Definition: qgsraster.h:89
Represents a raster layer.
QgsRasterPipe * pipe()
Returns the raster pipe.
Resample filter pipe for rasters.
QgsRasterRenderer * renderer() const
Returns the raster&#39;s renderer.
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
An interface for classes which can visit style entity (e.g.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:694
QgsBrightnessContrastFilter * brightnessFilter() const
Returns the raster&#39;s brightness/contrast filter.
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:37
This class describes the origin of min/max values.
#define SIP_SKIP
Definition: qgis_sip.h:126
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:76
Contains information about the context in which a coordinate transform is executed.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
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
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
Returns the raster&#39;s resample filter.
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...
Implementation of map layer temporal properties for raster 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:81
Base class for raster data providers.