QGIS API Documentation  2.99.0-Master (69af2f5)
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.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 
184  QgsRasterLayer( const QString &uri,
185  const QString &baseName = QString(),
186  const QString &providerKey = "gdal",
187  bool loadDefaultStyleFlag = true );
188 
189  ~QgsRasterLayer();
190 
196  virtual QgsRasterLayer *clone() const override SIP_FACTORY;
197 
200  {
205  UserDefinedShader
206  };
207 
210  {
214  ColorLayer
215  };
216 
222  static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
223  static bool isValidRasterFileName( const QString &fileNameQString );
224 
226  static QDateTime lastModified( const QString &name );
227 
229  void setDataProvider( const QString &provider );
230 
232  LayerType rasterType() { return mRasterType; }
233 
235  void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
236  QgsRasterRenderer *renderer() const { return mPipe.renderer(); }
237 
239  QgsRasterResampleFilter *resampleFilter() const { return mPipe.resampleFilter(); }
240 
241  QgsBrightnessContrastFilter *brightnessFilter() const { return mPipe.brightnessFilter(); }
242  QgsHueSaturationFilter *hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
243 
245  QgsRasterPipe *pipe() { return &mPipe; }
246 
248  int width() const;
249 
251  int height() const;
252 
254  int bandCount() const;
255 
257  QString bandName( int bandNoInt ) const;
258 
260 
264  const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
265 
267  virtual void reload() override;
268 
272  virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
273 
275  void draw( QPainter *theQPainter,
276  QgsRasterViewPort *myRasterViewPort,
277  const QgsMapToPixel *qgsMapToPixel = nullptr );
278 
280  QgsLegendColorList legendSymbologyItems() const;
281 
282  virtual bool isSpatial() const override { return true; }
283 
284  QString htmlMetadata() const override;
285 
287  QPixmap paletteAsPixmap( int bandNumber = 1 );
288 
290  QString providerType() const;
291 
293  double rasterUnitsPerPixelX() const;
295  double rasterUnitsPerPixelY() const;
296 
305  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
307  const QgsRectangle &extent = QgsRectangle(),
308  int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
309  bool generateLookupTableFlag = true );
310 
314  // Used by QgisApp::legendLayerStretchUsingCurrentExtent()
315  void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
316 
320  // Used by QgsRasterLayerRenderer
321  void refreshRendererIfNeeded( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent ) SIP_SKIP;
322 
326  bool defaultContrastEnhancementSettings(
328  QgsRasterMinMaxOrigin::Limits &myLimits ) const SIP_SKIP;
329 
331  void setDefaultContrastEnhancement();
332 
334  virtual QStringList subLayers() const override;
335 
338  QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
339  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
340 
347  virtual void setLayerOrder( const QStringList &layers ) override;
348 
352  virtual void setSubLayerVisibility( const QString &name, bool vis ) override;
353 
355  virtual QDateTime timestamp() const override;
356 
357  public slots:
358  void showStatusMessage( const QString &message );
359 
360  protected:
362  bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) override;
363 
365  bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) override;
366 
368  bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context ) override;
369 
371  bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
372 
374  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
375 
377  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
378 
379  private:
381  void init();
382 
384  void closeDataProvider();
385 
387  bool update();
388 
390  void setRendererForDrawingStyle( QgsRaster::DrawingStyle drawingStyle );
391 
392  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
394  const QgsRectangle &extent,
395  int sampleSize,
396  bool generateLookupTableFlag,
397  QgsRasterRenderer *rasterRenderer );
398 
399  void computeMinMax( int band,
400  const QgsRasterMinMaxOrigin &mmo,
402  const QgsRectangle &extent,
403  int sampleSize,
404  double &min, double &max );
405 
407  const QString QSTRING_NOT_SET;
408  const QString TRSTRING_NOT_SET;
409 
411  QgsRasterDataProvider *mDataProvider = nullptr;
412 
414  QDateTime mLastModified;
415 
416  QgsRasterViewPort mLastViewPort;
417 
419  QString mProviderKey;
420 
421  LayerType mRasterType;
422 
423  QgsRasterPipe mPipe;
424 
426  QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;
427 };
428 
429 #endif
virtual QStringList subLayers() const
Returns the sublayers of this layer.
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:38
Base class for all map layer types.
Definition: qgsmaplayer.h:54
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
Base class for processing modules.
Definition: qgsrasterpipe.h:45
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type different from Byte.
virtual QgsDataProvider * dataProvider()
Returns the layer&#39;s data provider.
QgsHueSaturationFilter * hueSaturationFilter() const
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
Definition: qgsraster.h:88
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsRasterPipe * pipe()
Get raster pipe.
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:347
virtual bool readXml(const QDomNode &layer_node, const QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files...
virtual bool isSpatial() const override
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
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...
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 bool readSymbology(const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context)=0
Read the symbology for the current layer from the Dom node supplied.
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
QgsBrightnessContrastFilter * brightnessFilter() const
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const =0
Write the symbology for the layer into the docment provided.
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:35
This class describes the origin of min/max values.
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
#define SIP_SKIP
Definition: qgis_sip.h:107
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
#define SIP_TRANSFER
Definition: qgis_sip.h:24
LayerType rasterType()
Accessor for raster layer type (which is a read only property)
#define SIP_FACTORY
Definition: qgis_sip.h:57
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
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
virtual bool readStyle(const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context)
Read the style for the current layer from the Dom node supplied.
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.
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 bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const
Write just the style information for the layer into the document.
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 QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
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.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:62
Base class for raster data providers.