QGIS API Documentation 4.1.0-Master (467af3bbe65)
Loading...
Searching...
No Matches
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
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.h"
25#include "qgis_core.h"
26#include "qgis_sip.h"
29#include "qgsmaplayer.h"
31#include "qgsrasterviewport.h"
32
33#include <QColor>
34#include <QDateTime>
35#include <QList>
36#include <QMap>
37#include <QPair>
38#include <QString>
39#include <QVector>
40
41using namespace Qt::StringLiterals;
42
43class QgsMapToPixel;
45class QgsRectangle;
47class QgsRasterPipe;
57
58class QImage;
59class QPixmap;
60class QSlider;
61
62typedef QList< QPair< QString, QColor > > QgsLegendColorList;
63
81class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfileSource
82{
83 Q_OBJECT
84
85 public:
90
92 static const double SAMPLE_SIZE;
93
96
99
102
105
108
111
114
152
165 explicit QgsRasterLayer( const QString &uri, const QString &baseName = QString(), const QString &providerType = "gdal", const QgsRasterLayer::LayerOptions &options = QgsRasterLayer::LayerOptions() );
166
167 ~QgsRasterLayer() override;
168
169#ifdef SIP_RUN
170 // clang-format off
171 SIP_PYOBJECT __repr__();
172 % MethodCode
173 QString str = u"<QgsRasterLayer: '%1' (%2)>"_s.arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : u"Invalid"_s );
174 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
175 % End
176// clang-format on
177#endif
178
184 QgsRasterLayer *clone() const override SIP_FACTORY;
185
186 QgsAbstractProfileSource *profileSource() override { return this; }
187 QString profileSourceId() const override { return id(); }
188 QString profileSourceName() const override { return name(); }
189
191
198 static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
199 // TODO QGIS 5.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
219 void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );
220
224 Qgis::RasterLayerType rasterType() const { return mRasterType; }
225
230 void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
231
237 QgsRasterRenderer *renderer() const;
238
245 QgsRasterResampleFilter *resampleFilter() const;
246
253 QgsBrightnessContrastFilter *brightnessFilter() const;
254
261 QgsHueSaturationFilter *hueSaturationFilter() const;
262
270 void setResamplingStage( Qgis::RasterResamplingStage stage );
271
279 Qgis::RasterResamplingStage resamplingStage() const;
280
284 QgsRasterPipe *pipe() { return mPipe.get(); }
285
290 int width() const;
291
296 int height() const;
297
301 int bandCount() const;
302
306 QString bandName( int bandNoInt ) const;
307
312 QgsRasterAttributeTable *attributeTable( int bandNumber ) const;
313
318 int attributeTableCount() const;
319
324 bool canCreateRasterAttributeTable();
325
332
338 const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
339
340 void reload() override;
341 QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
342
344 void draw( QPainter *theQPainter, QgsRasterViewPort *myRasterViewPort, 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(
401 QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
402 Qgis::RasterRangeLimit limits = Qgis::RasterRangeLimit::MinimumMaximum,
403 const QgsRectangle &extent = QgsRectangle(),
404 int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
405 bool generateLookupTableFlag = true
406 );
407
412 void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
413
419 virtual QString subsetString() const;
420
429 virtual bool setSubsetString( const QString &subset );
430
435 bool defaultContrastEnhancementSettings( QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, 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, QImage::Format format = QImage::Format_ARGB32_Premultiplied );
446
447 void setLayerOrder( const QStringList &layers ) override;
448 void setSubLayerVisibility( const QString &name, bool vis ) override;
449 QDateTime timestamp() const override;
450
451 using QgsMapLayer::accept;
452 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
453
462 bool labelsEnabled() const;
463
474 void setLabelsEnabled( bool enabled );
475
486 const QgsAbstractRasterLayerLabeling *labeling() const SIP_SKIP;
487
498
506 void setLabeling( QgsAbstractRasterLayerLabeling *labeling SIP_TRANSFER );
507
517 Q_DECL_DEPRECATED bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const SIP_DEPRECATED;
518
527 bool writeSld( QDomNode &node, QDomDocument &doc, QgsSldExportContext &context ) const;
528
537 bool ignoreExtents() const;
538
539 QgsMapLayerTemporalProperties *temporalProperties() override;
540 QgsMapLayerElevationProperties *elevationProperties() override;
541
549 void computeMinMax( int band, const QgsRasterMinMaxOrigin &mmo, Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, double &min, double &max ) SIP_SKIP;
550
551 public slots:
552 void showStatusMessage( const QString &message );
553
559 void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
560
561 signals:
562
568
569 protected:
570 bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
571 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
572 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
573 bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
574 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
575 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
576 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
577 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
578
579 private:
581 void init();
582
584 void closeDataProvider();
585
587 bool update();
588
590 void setRendererForDrawingStyle( Qgis::RasterDrawingStyle drawingStyle );
591
593 QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, bool generateLookupTableFlag, QgsRasterRenderer *rasterRenderer
594 );
595
607 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags ) override;
608
616 void writeRasterAttributeTableExternalPaths( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const;
617
624 void readRasterAttributeTableExternalPaths( const QDomNode &layerNode, QgsReadWriteContext &context ) const;
625
627 const QString QSTRING_NOT_SET;
628 const QString TRSTRING_NOT_SET;
629
631 QgsRasterDataProvider *mDataProvider = nullptr;
632
634 QgsRasterLayerTemporalProperties *mTemporalProperties = nullptr;
635
636 QgsRasterLayerElevationProperties *mElevationProperties = nullptr;
637
639 bool mLabelsEnabled = false;
640
642 std::unique_ptr< QgsAbstractRasterLayerLabeling > mLabeling;
643
645 QDateTime mLastModified;
646
647 QgsRasterViewPort mLastViewPort;
648
649 Qgis::RasterLayerType mRasterType = Qgis::RasterLayerType::GrayOrUndefined;
650
651 std::unique_ptr< QgsRasterPipe > mPipe;
652
653 QDomDocument mOriginalStyleDocument;
654 QDomElement mOriginalStyleElement;
655};
656
657// clazy:excludeall=qstring-allocations
658
659#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
RasterResamplingStage
Stage at which raster resampling occurs.
Definition qgis.h:1588
RasterLayerType
Raster layer types.
Definition qgis.h:5019
RasterRangeLimit
Describes the limits used to compute raster ranges (min/max values).
Definition qgis.h:1663
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:512
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2419
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:83
QString name
Definition qgsmaplayer.h:87
virtual Q_INVOKABLE QgsRectangle extent() const
Returns the extent of the layer.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
QString id
Definition qgsmaplayer.h:86
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
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
QgsMapLayer::LayerFlags flags
Definition qgsmaplayer.h:99
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:95
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.
void subsetStringChanged()
Emitted when the layer's subset string has changed.
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
Qgis::RasterLayerType rasterType() const
Returns the raster layer type (which is a read only property).
bool writeSymbology(QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
Write the style for the layer into the document provided.
static const QgsSettingsEntryBool * settingsRasterDefaultEarlyResampling
static const Qgis::RasterRangeLimit SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
QString profileSourceName() const override
Returns a name for displaying this profile source in the elevation profile layer tree.
QgsAbstractProfileSource * profileSource() override
Returns the layer's profile source if it has profile capabilities.
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.
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
static const QgsSettingsEntryDouble * settingsRasterDefaultOversampling
QString profileSourceId() const override
Returns a unique identifier for this profile source.
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files.
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
Write just the symbology information for the layer into the document.
static const Qgis::RasterRangeLimit MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
void setContrastEnhancement(QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, Qgis::RasterRangeLimit limits=Qgis::RasterRangeLimit::MinimumMaximum, const QgsRectangle &extent=QgsRectangle(), int sampleSize=QgsRasterLayer::SAMPLE_SIZE, bool generateLookupTableFlag=true)
Set contrast enhancement algorithm.
static const QgsSettingsEntryString * settingsRasterDefaultZoomedInResampling
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.
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
bool isSpatial() const override
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
Read the symbology for the current layer from the DOM node supplied.
static const QgsSettingsEntryString * settingsRasterDefaultZoomedOutResampling
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
QgsRasterLayer()
Constructor. Provider is not set.
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
Read the style for the current layer from the DOM node supplied.
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.
A string 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:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_PYNAME(name)
Definition qgis_sip.h:88
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
constexpr int SAMPLE_SIZE
QList< QPair< QString, QColor > > QgsLegendColorList
Setting options for creating vector data providers.
Setting options for loading raster layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
bool loadDefaultStyle
Sets to true if the default layer style should be loaded.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
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.