QGIS API Documentation 3.29.0-Master (006c3c0232)
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_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"
36#include "qgsraster.h"
38#include "qgsrasterviewport.h"
42
43class QgsMapToPixel;
45class QgsRectangle;
47class QgsRasterPipe;
52
53class QImage;
54class QPixmap;
55class QSlider;
56
57typedef QList < QPair< QString, QColor > > QgsLegendColorList;
58
76class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfileSource
77{
78 Q_OBJECT
79
80 public:
81
83 static const double SAMPLE_SIZE;
84
87
90
93
96
99
102
105
111 {
112
116 explicit LayerOptions( bool loadDefaultStyle = true,
118 : loadDefaultStyle( loadDefaultStyle )
119 , transformContext( transformContext )
120 {}
121
123 bool loadDefaultStyle = true;
124
130
144 bool skipCrsValidation = false;
145
146 };
147
160 explicit QgsRasterLayer( const QString &uri,
161 const QString &baseName = QString(),
162 const QString &providerType = "gdal",
164
165 ~QgsRasterLayer() override;
166
167#ifdef SIP_RUN
168 SIP_PYOBJECT __repr__();
169 % MethodCode
170 QString str = QStringLiteral( "<QgsRasterLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
171 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
172 % End
173#endif
174
181 QgsRasterLayer *clone() const override SIP_FACTORY;
182
183 QgsAbstractProfileGenerator *createProfileGenerator( const QgsProfileRequest &request ) override SIP_FACTORY;
184
187 {
192 UserDefinedShader
193 };
194
197 {
201 ColorLayer
202 };
203
210 static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
211 // TODO QGIS 4.0 - rename fileNameQString to fileName
212
213 static bool isValidRasterFileName( const QString &fileNameQString );
214
216 static QDateTime lastModified( const QString &name );
217
222 Q_DECL_DEPRECATED void setDataProvider( const QString &provider ) SIP_DEPRECATED;
223
231 void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
232
236 LayerType rasterType() { return mRasterType; }
237
242 void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
243
249 QgsRasterRenderer *renderer() const;
250
257 QgsRasterResampleFilter *resampleFilter() const;
258
265 QgsBrightnessContrastFilter *brightnessFilter() const;
266
273 QgsHueSaturationFilter *hueSaturationFilter() const;
274
282 void setResamplingStage( Qgis::RasterResamplingStage stage );
283
291 Qgis::RasterResamplingStage resamplingStage() const;
292
296 QgsRasterPipe *pipe() { return mPipe.get(); }
297
302 int width() const;
303
308 int height() const;
309
313 int bandCount() const;
314
318 QString bandName( int bandNoInt ) const;
319
324 QgsRasterAttributeTable *attributeTable( int bandNumber ) const;
325
330 int attributeTableCount( ) const;
331
336 bool canCreateRasterAttributeTable( );
337
344
350 const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
351
352 void reload() override;
353 QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
354
356 void draw( QPainter *theQPainter,
357 QgsRasterViewPort *myRasterViewPort,
358 const QgsMapToPixel *qgsMapToPixel = nullptr );
359
365 Q_DECL_DEPRECATED QgsLegendColorList legendSymbologyItems() const SIP_DEPRECATED;
366
367 bool isSpatial() const override { return true; }
368
369 QString htmlMetadata() const override;
370 Qgis::MapLayerProperties properties() const override;
371
376 QPixmap paletteAsPixmap( int bandNumber = 1 );
377
379 QString providerType() const;
380
389 double rasterUnitsPerPixelX() const;
390
398 double rasterUnitsPerPixelY() const;
399
400 void setOpacity( double opacity ) FINAL;
401 double opacity() const FINAL;
402
411 void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
412 QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax,
413 const QgsRectangle &extent = QgsRectangle(),
414 int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
415 bool generateLookupTableFlag = true );
416
421 void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
422
427 void refreshRendererIfNeeded( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent ) SIP_SKIP;
428
434 virtual QString subsetString() const;
435
444 virtual bool setSubsetString( const QString &subset );
445
450 bool defaultContrastEnhancementSettings(
451 QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm,
452 QgsRasterMinMaxOrigin::Limits &myLimits ) const SIP_SKIP;
453
455 void setDefaultContrastEnhancement();
456
457 QStringList subLayers() const override;
458
463 QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
464 QImage::Format format = QImage::Format_ARGB32_Premultiplied );
465
466 void setLayerOrder( const QStringList &layers ) override;
467 void setSubLayerVisibility( const QString &name, bool vis ) override;
468 QDateTime timestamp() const override;
469 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
470
480 bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const;
481
490 bool ignoreExtents() const;
491
492 QgsMapLayerTemporalProperties *temporalProperties() override;
493 QgsMapLayerElevationProperties *elevationProperties() override;
494
495 public slots:
496 void showStatusMessage( const QString &message );
497
503 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
504
505 signals:
506
511 void subsetStringChanged();
512
513 protected:
514 bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
515 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
516 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
517 bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
518 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
519 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
520 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
521 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
522 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
523 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
524
525 private:
527 void init();
528
530 void closeDataProvider();
531
533 bool update();
534
536 void setRendererForDrawingStyle( QgsRaster::DrawingStyle drawingStyle );
537
538 void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
539 QgsRasterMinMaxOrigin::Limits limits,
540 const QgsRectangle &extent,
541 int sampleSize,
542 bool generateLookupTableFlag,
543 QgsRasterRenderer *rasterRenderer );
544
546 void refreshRenderer( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent );
547
548 void computeMinMax( int band,
549 const QgsRasterMinMaxOrigin &mmo,
550 QgsRasterMinMaxOrigin::Limits limits,
551 const QgsRectangle &extent,
552 int sampleSize,
553 double &min, double &max );
554
566 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags ) override;
567
575 void writeRasterAttributeTableExternalPaths( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const;
576
583 void readRasterAttributeTableExternalPaths( const QDomNode &layerNode, QgsReadWriteContext &context ) const;
584
586 const QString QSTRING_NOT_SET;
587 const QString TRSTRING_NOT_SET;
588
590 QgsRasterDataProvider *mDataProvider = nullptr;
591
593 QgsRasterLayerTemporalProperties *mTemporalProperties = nullptr;
594
595 QgsRasterLayerElevationProperties *mElevationProperties = nullptr;
596
598 QDateTime mLastModified;
599
600 QgsRasterViewPort mLastViewPort;
601
602 LayerType mRasterType = GrayOrUndefined;
603
604 std::unique_ptr< QgsRasterPipe > mPipe;
605
607 QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;
608
609 QDomDocument mOriginalStyleDocument;
610 QDomElement mOriginalStyleElement;
611
612};
613
614// clazy:excludeall=qstring-allocations
615
616#endif
RasterResamplingStage
Stage at which raster resampling occurs.
Definition: qgis.h:721
Abstract base class for objects which generate elevation profiles.
Interface for classes which can generate elevation profiles.
Brightness/contrast and gamma correction filter pipe for rasters.
Manipulates raster or point cloud pixel values so that they enhanceContrast or clip into a specified ...
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:73
QString providerType() const
Returns the provider type (provider key) for this layer.
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.
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:82
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
The QgsRasterAttributeTable class 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.
LayerType
This enumerator describes the type of raster layer.
ColorShadingAlgorithm
This enumerator describes the types of shading that can be used.
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 QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
LayerType rasterType()
Returns the raster layer type (which is a read only property).
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type Byte.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type different from Byte.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
This class describes the origin of min/max values.
Limits
This enumerator describes the limits used to compute min/max values.
Contains a pipeline of raster interfaces for sequential raster processing.
Definition: qgsrasterpipe.h:50
Raster renderer pipe that applies colors to a raster.
Resample filter pipe for rasters.
Raster namespace.
Definition: qgsraster.h:32
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:42
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:74
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 str(x)
Definition: qgis.cpp:37
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126
#define FINAL
Definition: qgis_sip.h:237
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
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.