QGIS API Documentation  2.99.0-Master (19b062c)
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 
140 class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
141 {
142  Q_OBJECT
143  public:
144 
146  static const double SAMPLE_SIZE;
147 
150 
153 
156 
159 
162 
165 
167  QgsRasterLayer();
168 
174  {
175 
179  explicit LayerOptions( bool loadDefaultStyle = true )
180  : loadDefaultStyle( loadDefaultStyle )
181  {}
182 
184  bool loadDefaultStyle = true;
185  };
186 
204  explicit QgsRasterLayer( const QString &uri,
205  const QString &baseName = QString(),
206  const QString &providerKey = "gdal",
208 
209  ~QgsRasterLayer();
210 
217  virtual QgsRasterLayer *clone() const override SIP_FACTORY;
218 
221  {
226  UserDefinedShader
227  };
228 
231  {
235  ColorLayer
236  };
237 
244  static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
245  static bool isValidRasterFileName( const QString &fileNameQString );
246 
248  static QDateTime lastModified( const QString &name );
249 
251  void setDataProvider( const QString &provider );
252 
254  LayerType rasterType() { return mRasterType; }
255 
257  void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
258  QgsRasterRenderer *renderer() const { return mPipe.renderer(); }
259 
261  QgsRasterResampleFilter *resampleFilter() const { return mPipe.resampleFilter(); }
262 
263  QgsBrightnessContrastFilter *brightnessFilter() const { return mPipe.brightnessFilter(); }
264  QgsHueSaturationFilter *hueSaturationFilter() const { return mPipe.hueSaturationFilter(); }
265 
267  QgsRasterPipe *pipe() { return &mPipe; }
268 
270  int width() const;
271 
273  int height() const;
274 
276  int bandCount() const;
277 
279  QString bandName( int bandNoInt ) const;
280 
281  QgsRasterDataProvider *dataProvider() override;
282 
287  const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
288 
290  virtual void reload() override;
291 
296  virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
297 
299  void draw( QPainter *theQPainter,
300  QgsRasterViewPort *myRasterViewPort,
301  const QgsMapToPixel *qgsMapToPixel = nullptr );
302 
304  QgsLegendColorList legendSymbologyItems() const;
305 
306  virtual bool isSpatial() const override { return true; }
307 
308  QString htmlMetadata() const override;
309 
311  QPixmap paletteAsPixmap( int bandNumber = 1 );
312 
314  QString providerType() const;
315 
317  double rasterUnitsPerPixelX() const;
319  double rasterUnitsPerPixelY() const;
320 
330  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
332  const QgsRectangle &extent = QgsRectangle(),
333  int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
334  bool generateLookupTableFlag = true );
335 
340  // Used by QgisApp::legendLayerStretchUsingCurrentExtent()
341  void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
342 
347  // Used by QgsRasterLayerRenderer
348  void refreshRendererIfNeeded( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent ) SIP_SKIP;
349 
354  bool defaultContrastEnhancementSettings(
356  QgsRasterMinMaxOrigin::Limits &myLimits ) const SIP_SKIP;
357 
359  void setDefaultContrastEnhancement();
360 
362  virtual QStringList subLayers() const override;
363 
367  QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
368  QImage::Format format = QImage::Format_ARGB32_Premultiplied );
369 
376  virtual void setLayerOrder( const QStringList &layers ) override;
377 
381  virtual void setSubLayerVisibility( const QString &name, bool vis ) override;
382 
384  virtual QDateTime timestamp() const override;
385 
386  public slots:
387  void showStatusMessage( const QString &message );
388 
389  protected:
391  bool readSymbology( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) override;
392 
394  bool readStyle( const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context ) override;
395 
397  bool readXml( const QDomNode &layer_node, const QgsReadWriteContext &context ) override;
398 
400  bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
401 
403  bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const override;
404 
406  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
407 
408  private:
410  void init();
411 
413  void closeDataProvider();
414 
416  bool update();
417 
419  void setRendererForDrawingStyle( QgsRaster::DrawingStyle drawingStyle );
420 
421  void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
423  const QgsRectangle &extent,
424  int sampleSize,
425  bool generateLookupTableFlag,
426  QgsRasterRenderer *rasterRenderer );
427 
428  void computeMinMax( int band,
429  const QgsRasterMinMaxOrigin &mmo,
431  const QgsRectangle &extent,
432  int sampleSize,
433  double &min, double &max );
434 
436  const QString QSTRING_NOT_SET;
437  const QString TRSTRING_NOT_SET;
438 
440  QgsRasterDataProvider *mDataProvider = nullptr;
441 
443  QDateTime mLastModified;
444 
445  QgsRasterViewPort mLastViewPort;
446 
448  QString mProviderKey;
449 
450  LayerType mRasterType;
451 
452  QgsRasterPipe mPipe;
453 
455  QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;
456 };
457 
458 // clazy:excludeall=qstring-allocations
459 
460 #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:39
Base class for all map layer types.
Definition: qgsmaplayer.h:56
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()
Get raster pipe.
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.
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()
Accessor for raster layer type (which is a read only property)
#define SIP_FACTORY
Definition: qgis_sip.h:69
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.
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...
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.