QGIS API Documentation 3.41.0-Master (3440c17df1d)
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"
41
42class QgsMapToPixel;
44class QgsRectangle;
46class QgsRasterPipe;
53
54class QImage;
55class QPixmap;
56class QSlider;
57
58typedef QList < QPair< QString, QColor > > QgsLegendColorList;
59
77class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfileSource
78{
79 Q_OBJECT
80
81 public:
82
83 static const QgsSettingsEntryBool *settingsRasterDefaultEarlyResampling SIP_SKIP;
84 static const QgsSettingsEntryDouble *settingsRasterDefaultOversampling SIP_SKIP;
85
87 static const double SAMPLE_SIZE;
88
91
94
97
100
103
106
109
114 {
115
119 explicit LayerOptions( bool loadDefaultStyle = true,
121 : loadDefaultStyle( loadDefaultStyle )
122 , transformContext( transformContext )
123 {}
124
126 bool loadDefaultStyle = true;
127
133
147 bool skipCrsValidation = false;
148
149 };
150
163 explicit QgsRasterLayer( const QString &uri,
164 const QString &baseName = QString(),
165 const QString &providerType = "gdal",
167
168 ~QgsRasterLayer() override;
169
170#ifdef SIP_RUN
171 SIP_PYOBJECT __repr__();
172 % MethodCode
173 QString str = QStringLiteral( "<QgsRasterLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
174 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
175 % End
176#endif
177
183 QgsRasterLayer *clone() const override SIP_FACTORY;
184
185 QgsAbstractProfileGenerator *createProfileGenerator( const QgsProfileRequest &request ) override SIP_FACTORY;
186
193 static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
194 // TODO QGIS 4.0 - rename fileNameQString to fileName
195
196 static bool isValidRasterFileName( const QString &fileNameQString );
197
199 static QDateTime lastModified( const QString &name );
200
205 Q_DECL_DEPRECATED void setDataProvider( const QString &provider ) SIP_DEPRECATED;
206
214 void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() );
215
219 Qgis::RasterLayerType rasterType() const { return mRasterType; }
220
225 void setRenderer( QgsRasterRenderer *renderer SIP_TRANSFER );
226
232 QgsRasterRenderer *renderer() const;
233
240 QgsRasterResampleFilter *resampleFilter() const;
241
248 QgsBrightnessContrastFilter *brightnessFilter() const;
249
256 QgsHueSaturationFilter *hueSaturationFilter() const;
257
265 void setResamplingStage( Qgis::RasterResamplingStage stage );
266
274 Qgis::RasterResamplingStage resamplingStage() const;
275
279 QgsRasterPipe *pipe() { return mPipe.get(); }
280
285 int width() const;
286
291 int height() const;
292
296 int bandCount() const;
297
301 QString bandName( int bandNoInt ) const;
302
307 QgsRasterAttributeTable *attributeTable( int bandNumber ) const;
308
313 int attributeTableCount( ) const;
314
319 bool canCreateRasterAttributeTable( );
320
327
333 const QgsRasterDataProvider *dataProvider() const SIP_PYNAME( constDataProvider ) override;
334
335 void reload() override;
336 QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
337
339 void draw( QPainter *theQPainter,
340 QgsRasterViewPort *myRasterViewPort,
341 const QgsMapToPixel *qgsMapToPixel = nullptr );
342
348 Q_DECL_DEPRECATED QgsLegendColorList legendSymbologyItems() const SIP_DEPRECATED;
349
350 bool isSpatial() const override { return true; }
351
352 QString htmlMetadata() const override;
353 Qgis::MapLayerProperties properties() const override;
354
359 QPixmap paletteAsPixmap( int bandNumber = 1 );
360
362 QString providerType() const;
363
372 double rasterUnitsPerPixelX() const;
373
381 double rasterUnitsPerPixelY() const;
382
383 void setOpacity( double opacity ) FINAL;
384 double opacity() const FINAL;
385
394 void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
395 QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax,
396 const QgsRectangle &extent = QgsRectangle(),
397 int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
398 bool generateLookupTableFlag = true );
399
404 void refreshContrastEnhancement( const QgsRectangle &extent ) SIP_SKIP;
405
410 void refreshRendererIfNeeded( QgsRasterRenderer *rasterRenderer, 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 QgsRasterMinMaxOrigin::Limits &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
462 bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props = QVariantMap() ) const;
463
472 bool ignoreExtents() const;
473
474 QgsMapLayerTemporalProperties *temporalProperties() override;
475 QgsMapLayerElevationProperties *elevationProperties() override;
476
477 public slots:
478 void showStatusMessage( const QString &message );
479
485 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
486
487 signals:
488
493 void subsetStringChanged();
494
495 protected:
496 bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
497 bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) override;
498 bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) override;
499 bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
500 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
501 bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
502 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const override;
503 bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
504 QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const override;
505 QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const override;
506
507 private:
509 void init();
510
512 void closeDataProvider();
513
515 bool update();
516
518 void setRendererForDrawingStyle( Qgis::RasterDrawingStyle drawingStyle );
519
520 void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
521 QgsRasterMinMaxOrigin::Limits limits,
522 const QgsRectangle &extent,
523 int sampleSize,
524 bool generateLookupTableFlag,
525 QgsRasterRenderer *rasterRenderer );
526
528 void refreshRenderer( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent );
529
530 void computeMinMax( int band,
531 const QgsRasterMinMaxOrigin &mmo,
532 QgsRasterMinMaxOrigin::Limits limits,
533 const QgsRectangle &extent,
534 int sampleSize,
535 double &min, double &max );
536
548 void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags ) override;
549
557 void writeRasterAttributeTableExternalPaths( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const;
558
565 void readRasterAttributeTableExternalPaths( const QDomNode &layerNode, QgsReadWriteContext &context ) const;
566
568 const QString QSTRING_NOT_SET;
569 const QString TRSTRING_NOT_SET;
570
572 QgsRasterDataProvider *mDataProvider = nullptr;
573
575 QgsRasterLayerTemporalProperties *mTemporalProperties = nullptr;
576
577 QgsRasterLayerElevationProperties *mElevationProperties = nullptr;
578
580 QDateTime mLastModified;
581
582 QgsRasterViewPort mLastViewPort;
583
584 Qgis::RasterLayerType mRasterType = Qgis::RasterLayerType::GrayOrUndefined;
585
586 std::unique_ptr< QgsRasterPipe > mPipe;
587
589 QgsRectangle mLastRectangleUsedByRefreshContrastEnhancementIfNeeded;
590
591 QDomDocument mOriginalStyleDocument;
592 QDomElement mOriginalStyleElement;
593
594};
595
596// clazy:excludeall=qstring-allocations
597
598#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
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2118
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: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 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.
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.
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 str(x)
Definition qgis.cpp:39
#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.