QGIS API Documentation 3.37.0-Master (fa0c88a90b0)
qgsrasterdataprovider.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterdataprovider.h - DataProvider Interface for raster layers
3 --------------------------------------
4 Date : Mar 11, 2005
5 Copyright : (C) 2005 by Brendan Morley
6 email : morb at ozemail dot com dot au
7
8 async legend fetcher : Sandro Santilli < strk at keybit dot net >
9
10 ***************************************************************************/
11
12/***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
20
21/* Thank you to Marco Hugentobler for the original vector DataProvider */
22
23#ifndef QGSRASTERDATAPROVIDER_H
24#define QGSRASTERDATAPROVIDER_H
25
26#include "qgis_core.h"
27#include "qgis_sip.h"
28#include <cmath>
29
30#include <QDateTime>
31#include <QVariant>
32#include <QImage>
33
34#include "qgscolorrampshader.h"
35#include "qgsdataprovider.h"
37#include "qgsfields.h"
38#include "qgsrasterinterface.h"
39#include "qgsrasterpyramid.h"
40#include "qgsrasterrange.h"
41#include "qgsrectangle.h"
42#include "qgsrasteriterator.h"
45
46class QImage;
47class QByteArray;
48
49class QgsPointXY;
51class QgsMapSettings;
52
57class CORE_EXPORT QgsImageFetcher : public QObject
58{
59 Q_OBJECT
60 public:
62 QgsImageFetcher( QObject *parent = nullptr ) : QObject( parent ) {}
63
68 virtual void start() = 0;
69
70 signals:
71
76 void finish( const QImage &legend );
78 void progress( qint64 received, qint64 total );
80 void error( const QString &msg );
81};
82
83
89{
90 Q_OBJECT
91
92 public:
93
98 {
99 NoProviderCapabilities = 0,
100 ReadLayerMetadata = 1 << 1,
101 WriteLayerMetadata = 1 << 2,
102 ProviderHintBenefitsFromResampling = 1 << 3,
103 ProviderHintCanPerformProviderResampling = 1 << 4,
104 ReloadData = 1 << 5,
105 DpiDependentData = 1 << 6,
106 NativeRasterAttributeTable = 1 << 7,
107 };
108
110 Q_DECLARE_FLAGS( ProviderCapabilities, ProviderCapability )
111
113
122 QgsRasterDataProvider( const QString &uri,
124 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
125
126 QgsRasterDataProvider *clone() const override = 0;
127
131 virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const;
132
133 /* It makes no sense to set input on provider */
134 bool setInput( QgsRasterInterface *input ) override { Q_UNUSED( input ) return false; }
135
136 QgsRectangle extent() const override = 0;
137
139 Qgis::DataType dataType( int bandNo ) const override = 0;
140
146 virtual QgsFields fields() const { return QgsFields(); };
147
152 Qgis::DataType sourceDataType( int bandNo ) const override = 0;
153
155 virtual Qgis::RasterColorInterpretation colorInterpretation( int bandNo ) const;
156
160 QString colorName( Qgis::RasterColorInterpretation colorInterpretation ) const
161 {
162 // Modified copy from GDAL
163 switch ( colorInterpretation )
164 {
166 return QStringLiteral( "Undefined" );
167
169 return QStringLiteral( "Gray" );
170
172 return QStringLiteral( "Palette" );
173
175 return QStringLiteral( "Red" );
176
178 return QStringLiteral( "Green" );
179
181 return QStringLiteral( "Blue" );
182
184 return QStringLiteral( "Alpha" );
185
187 return QStringLiteral( "Hue" );
188
190 return QStringLiteral( "Saturation" );
191
193 return QStringLiteral( "Lightness" );
194
196 return QStringLiteral( "Cyan" );
197
199 return QStringLiteral( "Magenta" );
200
202 return QStringLiteral( "Yellow" );
203
205 return QStringLiteral( "Black" );
206
208 return QStringLiteral( "YCbCr_Y" );
209
211 return QStringLiteral( "YCbCr_Cb" );
212
214 return QStringLiteral( "YCbCr_Cr" );
215
217 return QStringLiteral( "Continuous Palette" );
218 }
219 return QString();
220 }
221
223 virtual bool reload() { return true; }
224
225 QString colorInterpretationName( int bandNo ) const override;
226
230 virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ) return 1.0; }
231
235 virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ) return 0.0; }
236
237 // TODO: remove or make protected all readBlock working with void*
238
240 QgsRasterBlock *block( int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
241
243 virtual bool sourceHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo - 1 ); }
244
246 virtual bool useSourceNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo - 1 ); }
247
249 virtual void setUseSourceNoDataValue( int bandNo, bool use );
250
252 virtual double sourceNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo - 1 ); }
253
254 virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList &noData );
255
257 virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo - 1 ); }
258
259 virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
260 { Q_UNUSED( bandNo ) return QList<QgsColorRampShader::ColorRampItem>(); }
261
266 QStringList subLayers() const override
267 {
268 return QStringList();
269 }
270
271 QgsRasterDataProviderTemporalCapabilities *temporalCapabilities() override;
272 const QgsRasterDataProviderTemporalCapabilities *temporalCapabilities() const override SIP_SKIP;
273 QgsRasterDataProviderElevationProperties *elevationProperties() override;
274 const QgsRasterDataProviderElevationProperties *elevationProperties() const override SIP_SKIP;
275
277 virtual bool supportsLegendGraphic() const { return false; }
278
290 virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle *visibleExtent = nullptr ) SIP_SKIP
291 {
292 Q_UNUSED( scale )
293 Q_UNUSED( forceRefresh )
294 Q_UNUSED( visibleExtent )
295 return QImage();
296 }
297
311 {
312 Q_UNUSED( mapSettings )
313 return nullptr;
314 }
315
332 virtual QString buildPyramids( const QList<QgsRasterPyramid> &pyramidList,
333 const QString &resamplingMethod = "NEAREST",
335 const QStringList &configOptions = QStringList(),
336 QgsRasterBlockFeedback *feedback = nullptr )
337 {
338 Q_UNUSED( pyramidList )
339 Q_UNUSED( resamplingMethod )
340 Q_UNUSED( format )
341 Q_UNUSED( configOptions )
342 Q_UNUSED( feedback )
343 return QStringLiteral( "FAILED_NOT_SUPPORTED" );
344 }
345
364 virtual QList<QgsRasterPyramid> buildPyramidList( const QList<int> &overviewList = QList<int>() )
365 { Q_UNUSED( overviewList ) return QList<QgsRasterPyramid>(); }
366
376 bool hasPyramids();
377
402 virtual QgsRasterIdentifyResult identify( const QgsPointXY &point, Qgis::RasterIdentifyFormat format, const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
403
418 virtual double sample( const QgsPointXY &point, int band,
419 bool *ok SIP_OUT = nullptr,
420 const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
421
430 virtual QString lastErrorTitle() = 0;
431
441 virtual QString lastError() = 0;
442
444 virtual QString lastErrorFormat();
445
447 int dpi() const { return mDpi; }
448
450 void setDpi( int dpi ) { mDpi = dpi; }
451
453 QDateTime timestamp() const override { return mTimestamp; }
454
456 QDateTime dataTimestamp() const override { return QDateTime(); }
457
463 virtual bool isEditable() const { return false; }
464
474 virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ) return false; }
475
476 // TODO: add data type (may be different from band type)
477
479 virtual bool write( void *data, int band, int width, int height, int xOffset, int yOffset )
480 {
481 Q_UNUSED( data )
482 Q_UNUSED( band )
483 Q_UNUSED( width )
484 Q_UNUSED( height )
485 Q_UNUSED( xOffset )
486 Q_UNUSED( yOffset )
487 return false;
488 }
489
505 bool writeBlock( QgsRasterBlock *block, int band, int xOffset = 0, int yOffset = 0 );
506
508 static QgsRasterDataProvider *create( const QString &providerKey,
509 const QString &uri,
510 const QString &format, int nBands,
511 Qgis::DataType type,
512 int width, int height, double *geoTransform,
514 const QStringList &createOptions = QStringList() );
515
521 virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ) Q_UNUSED( noDataValue ); return false; }
522
524 virtual bool remove() { return false; }
525
530 static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
531
538 {
539 QString name;
540 QString uri;
541 QString provider;
542 };
543
550 {
553 int width;
555 QString formula;
556 QList <QgsRasterDataProvider::VirtualRasterInputLayers> rInputLayers;
557
558 };
559
565 static QgsRasterDataProvider::VirtualRasterParameters decodeVirtualRasterProviderUri( const QString &uri, bool *ok = nullptr );
566
572 static QString encodeVirtualRasterProviderUri( const VirtualRasterParameters &parts );
573
579 virtual QString validateCreationOptions( const QStringList &createOptions, const QString &format )
580 { Q_UNUSED( createOptions ) Q_UNUSED( format ); return QString(); }
581
587 const QStringList &configOptions, const QString &fileFormat )
588 { Q_UNUSED( pyramidsFormat ) Q_UNUSED( configOptions ); Q_UNUSED( fileFormat ); return QString(); }
589
595 static QString identifyFormatName( Qgis::RasterIdentifyFormat format );
596
602 static Qgis::RasterIdentifyFormat identifyFormatFromName( const QString &formatName );
603
607 static QString identifyFormatLabel( Qgis::RasterIdentifyFormat format );
608
612 static Capability identifyFormatToCapability( Qgis::RasterIdentifyFormat format );
613
619
625
634 virtual QList< double > nativeResolutions() const;
635
642 virtual bool ignoreExtents() const;
643
649 {
652 };
653
666 virtual QgsPoint transformCoordinates( const QgsPoint &point, TransformType type );
667
668
675 virtual bool enableProviderResampling( bool enable ) { Q_UNUSED( enable ); return false; }
676
689 bool isProviderResamplingEnabled() const { return mProviderResamplingEnabled; }
690
696 {
697 Nearest,
698 Bilinear,
699 Cubic,
700 CubicSpline,
701 Lanczos,
702 Average,
703 Mode,
704 Gauss
705 };
706
713 virtual bool setZoomedInResamplingMethod( ResamplingMethod method ) { Q_UNUSED( method ); return false; }
714
719 ResamplingMethod zoomedInResamplingMethod() const { return mZoomedInResamplingMethod; }
720
727 virtual bool setZoomedOutResamplingMethod( ResamplingMethod method ) { Q_UNUSED( method ); return false; }
728
733 ResamplingMethod zoomedOutResamplingMethod() const { return mZoomedOutResamplingMethod; }
734
741 virtual bool setMaxOversampling( double factor ) { Q_UNUSED( factor ); return false; }
742
747 double maxOversampling() const { return mMaxOversampling; }
748
749 void readXml( const QDomElement &filterElem ) override;
750
751 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
752
758 QgsRasterAttributeTable *attributeTable( int bandNumber ) const;
759
768 void setAttributeTable( int bandNumber, QgsRasterAttributeTable *attributeTable SIP_TRANSFER );
769
776 void removeAttributeTable( int bandNumber );
777
785 bool writeFileBasedAttributeTable( int bandNumber, const QString &path, QString *errorMessage SIP_OUT = nullptr ) const;
786
793 bool readFileBasedAttributeTable( int bandNumber, const QString &path, QString *errorMessage SIP_OUT = nullptr );
794
805 virtual bool writeNativeAttributeTable( QString *errorMessage SIP_OUT = nullptr ); //#spellok
806
815 virtual bool readNativeAttributeTable( QString *errorMessage SIP_OUT = nullptr );
816
822 // Note: This method is not const because GDAL init on demand
823 virtual QString bandDescription( int bandNumber );
824
825
826 signals:
827
831 void statusChanged( const QString & ) const;
832
833
834 protected:
835
841 virtual bool readBlock( int bandNo, int xBlock, int yBlock, void *data ) SIP_SKIP
842 { Q_UNUSED( bandNo ) Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); return false; }
843
849 virtual bool readBlock( int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data, QgsRasterBlockFeedback *feedback = nullptr ) SIP_SKIP
850 { Q_UNUSED( bandNo ) Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); return false; }
851
853 bool userNoDataValuesContains( int bandNo, double value ) const;
854
856 void copyBaseSettings( const QgsRasterDataProvider &other );
857
862 int mDpi = -1;
863
868 //bool hasNoDataValue ( int bandNo );
869
871 QList<double> mSrcNoDataValue;
872
875
882
887 QList< QgsRasterRangeList > mUserNoDataValue;
888
890
892 bool mProviderResamplingEnabled = false;
893
895 ResamplingMethod mZoomedInResamplingMethod = ResamplingMethod::Nearest;
896
898 ResamplingMethod mZoomedOutResamplingMethod = ResamplingMethod::Nearest;
899
901 double mMaxOversampling = 2.0;
902
903 private:
904
908 std::unique_ptr< QgsRasterDataProviderTemporalCapabilities > mTemporalCapabilities;
909
910 std::unique_ptr< QgsRasterDataProviderElevationProperties > mElevationProperties;
911
912 std::map<int, std::unique_ptr<QgsRasterAttributeTable>> mAttributeTables;
913
914};
915
916Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRasterDataProvider::ProviderCapabilities )
917
918// clazy:excludeall=qstring-allocations
919
920#endif
RasterPyramidFormat
Raster pyramid formats.
Definition: qgis.h:3921
@ GeoTiff
Geotiff .ovr (external)
DataType
Raster data types.
Definition: qgis.h:269
RasterColorInterpretation
Raster color interpretation.
Definition: qgis.h:3852
@ GreenBand
Green band of RGBA image.
@ SaturationBand
Saturation band of HLS image.
@ MagentaBand
Magenta band of CMYK image.
@ BlackBand
Black band of CMLY image.
@ AlphaBand
Alpha (0=transparent, 255=opaque)
@ BlueBand
Blue band of RGBA image.
@ YellowBand
Yellow band of CMYK image.
@ CyanBand
Cyan band of CMYK image.
@ LightnessBand
Lightness band of HLS image.
@ HueBand
Hue band of HLS image.
@ PaletteIndex
Paletted (see associated color table)
@ RedBand
Red band of RGBA image.
@ ContinuousPalette
Continuous palette, QGIS addition, GRASS.
RasterIdentifyFormat
Raster identify formats.
Definition: qgis.h:3951
This class represents a coordinate reference system (CRS).
Abstract base class for spatial data provider implementations.
Container of fields for a vector layer.
Definition: qgsfields.h:45
Handles asynchronous download of images.
QgsImageFetcher(QObject *parent=nullptr)
Constructor.
void progress(qint64 received, qint64 total)
Emitted to report progress.
void error(const QString &msg)
Emitted when an error occurs.
void finish(const QImage &legend)
Emitted when the download completes.
virtual void start()=0
Starts the image download.
The QgsMapSettings class contains configuration for rendering of the map.
A class to represent a 2D point.
Definition: qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT).
Feedback object tailored for raster block reading.
Raster data container.
Handles elevation related properties for a raster data provider.
Implementation of data provider temporal properties for QgsRasterDataProviders.
Base class for raster data providers.
virtual QgsFields fields() const
Returns the fields of the raster layer for data providers that expose them, the default implementatio...
QList< bool > mUseSrcNoDataValue
Use source nodata value.
TransformType
Types of transformation in transformCoordinates() function.
@ TransformLayerToImage
Transforms layer (georeferenced) coordinates to image coordinates.
@ TransformImageToLayer
Transforms image coordinates to layer (georeferenced) coordinates.
QgsRasterDataProvider * clone() const override=0
Clone itself, create deep copy.
virtual bool setNoDataValue(int bandNo, double noDataValue)
Set no data value on created dataset.
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
virtual QString buildPyramids(const QList< QgsRasterPyramid > &pyramidList, const QString &resamplingMethod="NEAREST", Qgis::RasterPyramidFormat format=Qgis::RasterPyramidFormat::GeoTiff, const QStringList &configOptions=QStringList(), QgsRasterBlockFeedback *feedback=nullptr)
Creates pyramid overviews.
virtual bool readBlock(int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data, QgsRasterBlockFeedback *feedback=nullptr)
Reads a block of raster data into data, using the given extent and size.
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
virtual QString validateCreationOptions(const QStringList &createOptions, const QString &format)
Validates creation options for a specific dataset and destination format.
virtual QString lastError()=0
Returns the verbose error text for the last error in this provider.
Qgis::DataType sourceDataType(int bandNo) const override=0
Returns source data type for the band specified by number, source data type may be shorter than dataT...
bool isProviderResamplingEnabled() const
Returns whether provider-level resampling is enabled.
virtual bool remove()
Remove dataset.
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
virtual QImage getLegendGraphic(double scale=0, bool forceRefresh=false, const QgsRectangle *visibleExtent=nullptr)
Returns the legend rendered as pixmap.
virtual bool reload()
Reload data (data could change)
QList< QgsRasterRangeList > mUserNoDataValue
List of lists of user defined additional no data values for each band, indexed from 0.
ResamplingMethod zoomedOutResamplingMethod() const
Returns resampling method for zoomed-out operations.
virtual bool isEditable() const
Checks whether the provider is in editing mode, i.e.
QString colorName(Qgis::RasterColorInterpretation colorInterpretation) const
Returns a string color name representation of a color interpretation.
virtual bool enableProviderResampling(bool enable)
Enable or disable provider-level resampling.
void setDpi(int dpi)
Sets the output device resolution.
QDateTime timestamp() const override
Time stamp of data source in the moment when data/metadata were loaded by provider.
QgsRectangle extent() const override=0
Returns the extent of the layer.
virtual bool setMaxOversampling(double factor)
Sets maximum oversampling factor for zoomed-out operations.
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
virtual QString validatePyramidsConfigOptions(Qgis::RasterPyramidFormat pyramidsFormat, const QStringList &configOptions, const QString &fileFormat)
Validates pyramid creation options for a specific dataset and destination format.
double maxOversampling() const
Returns maximum oversampling factor for zoomed-out operations.
QStringList subLayers() const override
Returns the sublayers of this layer - useful for providers that manage their own layers,...
virtual double bandScale(int bandNo) const
Read band scale for raster value.
ProviderCapability
Enumeration with capabilities that raster providers might implement.
int dpi() const
Returns the dpi of the output device.
QDateTime dataTimestamp() const override
Current time stamp of data source.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Returns a new image downloader for the raster legend.
virtual bool readBlock(int bandNo, int xBlock, int yBlock, void *data)
Reads a block of raster data into data.
bool setInput(QgsRasterInterface *input) override
Set input.
QList< bool > mSrcHasNoDataValue
Source no data value exists.
void statusChanged(const QString &) const
Emit a message to be displayed on status bar, usually used by network providers (WMS,...
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
virtual bool setZoomedInResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-in operations.
virtual int stepHeight() const
Step height for raster iterations.
virtual bool setEditable(bool enabled)
Turns on/off editing mode of the provider.
virtual int stepWidth() const
Step width for raster iterations.
ResamplingMethod zoomedInResamplingMethod() const
Returns resampling method for zoomed-in operations.
ResamplingMethod
Resampling method for provider-level resampling.
virtual QString lastErrorTitle()=0
Returns the caption error text for the last error in this provider.
virtual bool write(void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
virtual bool setZoomedOutResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-out operations.
virtual QList< QgsRasterPyramid > buildPyramidList(const QList< int > &overviewList=QList< int >())
Returns the raster layers pyramid list.
Raster identify results container.
Base class for processing filters like renderers, reprojector, resampler etc.
static const int DEFAULT_MAXIMUM_TILE_WIDTH
Default maximum tile width.
static const int DEFAULT_MAXIMUM_TILE_HEIGHT
Default maximum tile height.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
#define SIP_ENUM_BASETYPE(type)
Definition: qgis_sip.h:278
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
QList< QgsRasterRange > QgsRasterRangeList
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.
Struct that stores information of the raster used in QgsVirtualRasterProvider for the calculations,...
Struct that stores the information about the parameters that should be given to the QgsVirtualRasterP...
QList< QgsRasterDataProvider::VirtualRasterInputLayers > rInputLayers