QGIS API Documentation 3.99.0-Master (798f63fc3c0)
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_sip.h"
34#include "qgis.h"
35#include "qgsmaplayer.h"
37#include "qgsrasterviewport.h"
40
41class QgsMapToPixel;
43class QgsRectangle;
45class QgsRasterPipe;
54
55class QImage;
56class QPixmap;
57class QSlider;
58
59typedef QList < QPair< QString, QColor > > QgsLegendColorList;
60
78class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfileSource
79{
80 Q_OBJECT
81
82 public:
83
84 static const QgsSettingsEntryBool *settingsRasterDefaultEarlyResampling SIP_SKIP;
85 static const QgsSettingsEntryDouble *settingsRasterDefaultOversampling SIP_SKIP;
86
88 static const double SAMPLE_SIZE;
89
92
95
98
101
104
107
110
115 {
116
120 explicit LayerOptions( bool loadDefaultStyle = true,
122 : loadDefaultStyle( loadDefaultStyle )
123 , transformContext( transformContext )
124 {}
125
127 bool loadDefaultStyle = true;
128
134
148 bool skipCrsValidation = false;
149
150 };
151
164 explicit QgsRasterLayer( const QString &uri,
165 const QString &baseName = QString(),
166 const QString &providerType = "gdal",
168
169 ~QgsRasterLayer() override;
170
171#ifdef SIP_RUN
172 SIP_PYOBJECT __repr__();
173 % MethodCode
174 QString str = QStringLiteral( "<QgsRasterLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
175 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
176 % End
177#endif
178
184 QgsRasterLayer *clone() const override SIP_FACTORY;
185
186 QgsAbstractProfileSource *profileSource() override {return this;}
187
189
196 static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
197 // TODO QGIS 4.0 - rename fileNameQString to fileName
198
199 static bool isValidRasterFileName( const QString &fileNameQString );
200
202 static QDateTime lastModified( const QString &name );
203
208 Q_DECL_DEPRECATED void setDataProvider( const QString &provider ) SIP_DEPRECATED;
209
217 void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );
218
222 Qgis::RasterLayerType rasterType() const { return mRasterType; }
223
228 void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
229
235 QgsRasterRenderer *renderer() const;
236
243 QgsRasterResampleFilter *resampleFilter() const;
244
251 QgsBrightnessContrastFilter *brightnessFilter() const;
252
259 QgsHueSaturationFilter *hueSaturationFilter() const;
260
268 void setResamplingStage( Qgis::RasterResamplingStage stage );
269
277 Qgis::RasterResamplingStage resamplingStage() const;
278
282 QgsRasterPipe *pipe() { return mPipe.get(); }
283
288 int width() const;
289
294 int height() const;
295
299 int bandCount() const;
300
304 QString bandName( int bandNoInt ) const;
305
310 QgsRasterAttributeTable *attributeTable( int bandNumber ) const;
311
316 int attributeTableCount( ) const;
317
322 bool canCreateRasterAttributeTable( );
323
330
336 const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
337
338 void reload() override;
339 QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
340
342 void draw( QPainter *theQPainter,
343 QgsRasterViewPort *myRasterViewPort,
344 const QgsMapToPixel *qgsMapToPixel = nullptr );
345
351 Q_DECL_DEPRECATED QgsLegendColorList legendSymbologyItems() const SIP_DEPRECATED;
352
353 bool isSpatial() const override { return true; }
354
355 QString htmlMetadata() const override;
356 Qgis::MapLayerProperties properties() const override;
357
362 QPixmap paletteAsPixmap( int bandNumber = 1 );
363
375 double rasterUnitsPerPixelX() const;
376
387 double rasterUnitsPerPixelY() const;
388
389 void setOpacity( double opacity ) FINAL;
390 double opacity() const FINAL;
391
400 void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
401 Qgis::RasterRangeLimit limits = Qgis::RasterRangeLimit::MinimumMaximum,
402 const QgsRectangle &extent = QgsRectangle(),
403 int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
404 bool generateLookupTableFlag = true );
405
410 void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
411
417 virtual QString subsetString() const;
418
427 virtual bool setSubsetString( const QString &subset );
428
433 bool defaultContrastEnhancementSettings(
434 QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm,
435 Qgis::RasterRangeLimit &myLimits ) const SIP_SKIP;
436
438 void setDefaultContrastEnhancement();
439
440 QStringList subLayers() const override;
441
445 QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
446 QImage::Format format = QImage::Format_ARGB32_Premultiplied );
447
448 void setLayerOrder( const QStringList &layers ) override;
449 void setSubLayerVisibility( const QString &name, bool vis ) override;
450 QDateTime timestamp() const override;
451 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
452
461 bool labelsEnabled() const;
462
473 void setLabelsEnabled( bool enabled );
474
485 const QgsAbstractRasterLayerLabeling *labeling() const SIP_SKIP;
486
497
505 void setLabeling( QgsAbstractRasterLayerLabeling *labeling SIP_TRANSFER );
506
516 Q_DECL_DEPRECATED bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const SIP_DEPRECATED;
517
526 bool writeSld( QDomNode &node, QDomDocument &doc, QgsSldExportContext &context ) const;
527
536 bool ignoreExtents() const;
537
538 QgsMapLayerTemporalProperties *temporalProperties() override;
539 QgsMapLayerElevationProperties *elevationProperties() override;
540
548 void computeMinMax( int band,
549 const QgsRasterMinMaxOrigin &mmo,
550 Qgis::RasterRangeLimit limits,
551 const QgsRectangle &extent,
552 int sampleSize,
553 double &min, double &max ) SIP_SKIP;
554
555 public slots:
556 void showStatusMessage( const QString &message );
557
563 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
564
565 signals:
566
571 void subsetStringChanged();
572
573 protected:
574 bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
575 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
576 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
577 bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
578 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
579 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
580 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
581 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
582 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
583 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
584
585 private:
587 void init();
588
590 void closeDataProvider();
591
593 bool update();
594
596 void setRendererForDrawingStyle( Qgis::RasterDrawingStyle drawingStyle );
597
598 void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
599 Qgis::RasterRangeLimit limits,
600 const QgsRectangle &extent,
601 int sampleSize,
602 bool generateLookupTableFlag,
603 QgsRasterRenderer *rasterRenderer );
604
616 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags ) override;
617
625 void writeRasterAttributeTableExternalPaths( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const;
626
633 void readRasterAttributeTableExternalPaths( const QDomNode &layerNode, QgsReadWriteContext &context ) const;
634
636 const QString QSTRING_NOT_SET;
637 const QString TRSTRING_NOT_SET;
638
640 QgsRasterDataProvider *mDataProvider = nullptr;
641
643 QgsRasterLayerTemporalProperties *mTemporalProperties = nullptr;
644
645 QgsRasterLayerElevationProperties *mElevationProperties = nullptr;
646
648 bool mLabelsEnabled = false;
649
651 std::unique_ptr< QgsAbstractRasterLayerLabeling > mLabeling;
652
654 QDateTime mLastModified;
655
656 QgsRasterViewPort mLastViewPort;
657
658 Qgis::RasterLayerType mRasterType = Qgis::RasterLayerType::GrayOrUndefined;
659
660 std::unique_ptr< QgsRasterPipe > mPipe;
661
662 QDomDocument mOriginalStyleDocument;
663 QDomElement mOriginalStyleElement;
664
665};
666
667// clazy:excludeall=qstring-allocations
668
669#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
RasterResamplingStage
Stage at which raster resampling occurs.
Definition qgis.h:1433
RasterLayerType
Raster layer types.
Definition qgis.h:4644
RasterRangeLimit
Describes the limits used to compute raster ranges (min/max values).
Definition qgis.h:1507
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2235
Abstract base class for objects which generate elevation profiles.
Interface for classes which can generate elevation profiles.
virtual QgsAbstractProfileGenerator * createProfileGenerator(const QgsProfileRequest &request)=0
Given a profile request, returns a new profile generator ready for generating elevation profiles.
Abstract base class for labeling settings for raster layers.
Brightness/contrast and gamma correction filter pipe for rasters.
Handles contrast enhancement and clipping.
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used.
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
Color and saturation filter pipe for rasters.
Base class for storage of map layer elevation properties.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for storage of map layer temporal properties.
Base class for all map layer types.
Definition qgsmaplayer.h:78
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
virtual Qgis::MapLayerProperties properties() const
Returns the map layer properties of this layer.
QFlags< StyleCategory > StyleCategories
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
double opacity
Definition qgsmaplayer.h:90
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Perform transforms between map coordinates and device coordinates.
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
Represents a Raster Attribute Table (RAT).
Base class for raster data providers.
Raster layer specific subclass of QgsMapLayerElevationProperties.
Implementation of map layer temporal properties for raster layers.
Represents a raster layer.
Qgis::RasterLayerType rasterType() const
Returns the raster layer type (which is a read only property).
static const Qgis::RasterRangeLimit SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type Byte.
QgsRasterPipe * pipe()
Returns the raster pipe.
static const Qgis::RasterRangeLimit MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type different from Byte.
static const Qgis::RasterRangeLimit MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type Byte.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
Describes the origin of minimum and maximum values in a raster.
Contains a pipeline of raster interfaces for sequential raster processing.
Raster renderer pipe that applies colors to a raster.
Resample filter pipe for rasters.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
A boolean settings entry.
A double settings entry.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
An interface for classes which can visit style entity (e.g.
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
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_SKIP
Definition qgis_sip.h:134
#define FINAL
Definition qgis_sip.h:250
#define SIP_PYNAME(name)
Definition qgis_sip.h:89
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
constexpr int SAMPLE_SIZE
QList< QPair< QString, QColor > > QgsLegendColorList
Setting options for creating vector data providers.
Setting options for loading raster layers.
LayerOptions(bool loadDefaultStyle=true, const QgsCoordinateTransformContext &transformContext=QgsCoordinateTransformContext())
Constructor for LayerOptions.
This class provides details of the viewable area that a raster will be rendered into.