QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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_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 QgsAbstractProfileGenerator *createProfileGenerator( const QgsProfileRequest &request ) override SIP_FACTORY;
187
194 static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
195 // TODO QGIS 4.0 - rename fileNameQString to fileName
196
197 static bool isValidRasterFileName( const QString &fileNameQString );
198
200 static QDateTime lastModified( const QString &name );
201
206 Q_DECL_DEPRECATED void setDataProvider( const QString &provider ) SIP_DEPRECATED;
207
215 void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );
216
220 Qgis::RasterLayerType rasterType() const { return mRasterType; }
221
226 void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
227
233 QgsRasterRenderer *renderer() const;
234
241 QgsRasterResampleFilter *resampleFilter() const;
242
249 QgsBrightnessContrastFilter *brightnessFilter() const;
250
257 QgsHueSaturationFilter *hueSaturationFilter() const;
258
266 void setResamplingStage( Qgis::RasterResamplingStage stage );
267
275 Qgis::RasterResamplingStage resamplingStage() const;
276
280 QgsRasterPipe *pipe() { return mPipe.get(); }
281
286 int width() const;
287
292 int height() const;
293
297 int bandCount() const;
298
302 QString bandName( int bandNoInt ) const;
303
308 QgsRasterAttributeTable *attributeTable( int bandNumber ) const;
309
314 int attributeTableCount( ) const;
315
320 bool canCreateRasterAttributeTable( );
321
328
334 const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
335
336 void reload() override;
337 QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
338
340 void draw( QPainter *theQPainter,
341 QgsRasterViewPort *myRasterViewPort,
342 const QgsMapToPixel *qgsMapToPixel = nullptr );
343
349 Q_DECL_DEPRECATED QgsLegendColorList legendSymbologyItems() const SIP_DEPRECATED;
350
351 bool isSpatial() const override { return true; }
352
353 QString htmlMetadata() const override;
354 Qgis::MapLayerProperties properties() const override;
355
360 QPixmap paletteAsPixmap( int bandNumber = 1 );
361
363 QString providerType() const;
364
373 double rasterUnitsPerPixelX() const;
374
382 double rasterUnitsPerPixelY() const;
383
384 void setOpacity( double opacity ) FINAL;
385 double opacity() const FINAL;
386
395 void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
396 Qgis::RasterRangeLimit limits = Qgis::RasterRangeLimit::MinimumMaximum,
397 const QgsRectangle &extent = QgsRectangle(),
398 int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
399 bool generateLookupTableFlag = true );
400
405 void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
406
412 virtual QString subsetString() const;
413
422 virtual bool setSubsetString( const QString &subset );
423
428 bool defaultContrastEnhancementSettings(
429 QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm,
430 Qgis::RasterRangeLimit &myLimits ) const SIP_SKIP;
431
433 void setDefaultContrastEnhancement();
434
435 QStringList subLayers() const override;
436
440 QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
441 QImage::Format format = QImage::Format_ARGB32_Premultiplied );
442
443 void setLayerOrder( const QStringList &layers ) override;
444 void setSubLayerVisibility( const QString &name, bool vis ) override;
445 QDateTime timestamp() const override;
446 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
447
456 bool labelsEnabled() const;
457
468 void setLabelsEnabled( bool enabled );
469
480 const QgsAbstractRasterLayerLabeling *labeling() const SIP_SKIP;
481
492
500 void setLabeling( QgsAbstractRasterLayerLabeling *labeling SIP_TRANSFER );
501
511 bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const;
512
521 bool ignoreExtents() const;
522
523 QgsMapLayerTemporalProperties *temporalProperties() override;
524 QgsMapLayerElevationProperties *elevationProperties() override;
525
533 void computeMinMax( int band,
534 const QgsRasterMinMaxOrigin &mmo,
535 Qgis::RasterRangeLimit limits,
536 const QgsRectangle &extent,
537 int sampleSize,
538 double &min, double &max ) SIP_SKIP;
539
540 public slots:
541 void showStatusMessage( const QString &message );
542
548 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
549
550 signals:
551
556 void subsetStringChanged();
557
558 protected:
559 bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
560 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
561 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
562 bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
563 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
564 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
565 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
566 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
567 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
568 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
569
570 private:
572 void init();
573
575 void closeDataProvider();
576
578 bool update();
579
581 void setRendererForDrawingStyle( Qgis::RasterDrawingStyle drawingStyle );
582
583 void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
584 Qgis::RasterRangeLimit limits,
585 const QgsRectangle &extent,
586 int sampleSize,
587 bool generateLookupTableFlag,
588 QgsRasterRenderer *rasterRenderer );
589
601 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags ) override;
602
610 void writeRasterAttributeTableExternalPaths( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const;
611
618 void readRasterAttributeTableExternalPaths( const QDomNode &layerNode, QgsReadWriteContext &context ) const;
619
621 const QString QSTRING_NOT_SET;
622 const QString TRSTRING_NOT_SET;
623
625 QgsRasterDataProvider *mDataProvider = nullptr;
626
628 QgsRasterLayerTemporalProperties *mTemporalProperties = nullptr;
629
630 QgsRasterLayerElevationProperties *mElevationProperties = nullptr;
631
633 bool mLabelsEnabled = false;
634
636 std::unique_ptr< QgsAbstractRasterLayerLabeling > mLabeling;
637
639 QDateTime mLastModified;
640
641 QgsRasterViewPort mLastViewPort;
642
643 Qgis::RasterLayerType mRasterType = Qgis::RasterLayerType::GrayOrUndefined;
644
645 std::unique_ptr< QgsRasterPipe > mPipe;
646
647 QDomDocument mOriginalStyleDocument;
648 QDomElement mOriginalStyleElement;
649
650};
651
652// clazy:excludeall=qstring-allocations
653
654#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
RasterResamplingStage
Stage at which raster resampling occurs.
Definition qgis.h:1380
RasterRangeLimit
Describes the limits used to compute raster ranges (min/max values).
Definition qgis.h:1454
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2181
Abstract base class for objects which generate elevation profiles.
Interface for classes which can generate elevation profiles.
Abstract base class for labeling settings for raster layers.
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:76
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.
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:88
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...
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.
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.
This class describes the origin of min/max values.
Contains a pipeline of raster interfaces for sequential raster processing.
Raster renderer pipe that applies colors to a raster.
Resample filter pipe for rasters.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
A boolean settings entry.
A double settings entry.
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:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define FINAL
Definition qgis_sip.h:242
#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 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.