QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
95
104 QgsRasterDataProvider( const QString &uri,
107
108 QgsRasterDataProvider *clone() const override = 0;
109
113 virtual Qgis::RasterProviderCapabilities providerCapabilities() const;
114
115 // It makes no sense to set input on provider
116 bool setInput( QgsRasterInterface *input ) override { Q_UNUSED( input ) return false; }
117
118 QgsRectangle extent() const override = 0;
119
121 Qgis::DataType dataType( int bandNo ) const override = 0;
122
128 virtual QgsFields fields() const { return QgsFields(); };
129
134 Qgis::DataType sourceDataType( int bandNo ) const override = 0;
135
137 virtual Qgis::RasterColorInterpretation colorInterpretation( int bandNo ) const;
138
143 QString colorName( Qgis::RasterColorInterpretation colorInterpretation ) const;
144
146 virtual bool reload() { return true; }
147
148 QString colorInterpretationName( int bandNo ) const override;
149
153 virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ) return 1.0; }
154
158 virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ) return 0.0; }
159
168
169 // TODO: remove or make protected all readBlock working with void*
170
172 QgsRasterBlock *block( int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
173
175 virtual bool sourceHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo - 1 ); }
176
178 virtual bool useSourceNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo - 1 ); }
179
181 virtual void setUseSourceNoDataValue( int bandNo, bool use );
182
184 virtual double sourceNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo - 1 ); }
185
186 virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList &noData );
187
189 virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo - 1 ); }
190
191 virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
192 { Q_UNUSED( bandNo ) return QList<QgsColorRampShader::ColorRampItem>(); }
193
198 QStringList subLayers() const override
199 {
200 return QStringList();
201 }
202
203 QgsRasterDataProviderTemporalCapabilities *temporalCapabilities() override;
204 const QgsRasterDataProviderTemporalCapabilities *temporalCapabilities() const override SIP_SKIP;
205 QgsRasterDataProviderElevationProperties *elevationProperties() override;
206 const QgsRasterDataProviderElevationProperties *elevationProperties() const override SIP_SKIP;
207
209 virtual bool supportsLegendGraphic() const { return false; }
210
222 virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle *visibleExtent = nullptr ) SIP_SKIP
223 {
224 Q_UNUSED( scale )
225 Q_UNUSED( forceRefresh )
226 Q_UNUSED( visibleExtent )
227 return QImage();
228 }
229
243 {
244 Q_UNUSED( mapSettings )
245 return nullptr;
246 }
247
264 virtual QString buildPyramids( const QList<QgsRasterPyramid> &pyramidList,
265 const QString &resamplingMethod = "NEAREST",
267 const QStringList &configOptions = QStringList(),
268 QgsRasterBlockFeedback *feedback = nullptr )
269 {
270 Q_UNUSED( pyramidList )
271 Q_UNUSED( resamplingMethod )
272 Q_UNUSED( format )
273 Q_UNUSED( configOptions )
274 Q_UNUSED( feedback )
275 return QStringLiteral( "FAILED_NOT_SUPPORTED" );
276 }
277
296 virtual QList<QgsRasterPyramid> buildPyramidList( const QList<int> &overviewList = QList<int>() )
297 { Q_UNUSED( overviewList ) return QList<QgsRasterPyramid>(); }
298
308 bool hasPyramids();
309
334 virtual QgsRasterIdentifyResult identify( const QgsPointXY &point, Qgis::RasterIdentifyFormat format, const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
335
350 virtual double sample( const QgsPointXY &point, int band,
351 bool *ok SIP_OUT = nullptr,
352 const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
353
362 virtual QString lastErrorTitle() = 0;
363
373 virtual QString lastError() = 0;
374
376 virtual QString lastErrorFormat();
377
379 int dpi() const { return mDpi; }
380
382 void setDpi( int dpi ) { mDpi = dpi; }
383
385 QDateTime timestamp() const override { return mTimestamp; }
386
388 QDateTime dataTimestamp() const override { return QDateTime(); }
389
396 virtual bool isEditable() const { return false; }
397
408 virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ) return false; }
409
410 // TODO: add data type (may be different from band type)
411
413 virtual bool write( const void *data, int band, int width, int height, int xOffset, int yOffset )
414 {
415 Q_UNUSED( data )
416 Q_UNUSED( band )
417 Q_UNUSED( width )
418 Q_UNUSED( height )
419 Q_UNUSED( xOffset )
420 Q_UNUSED( yOffset )
421 return false;
422 }
423
440 bool writeBlock( QgsRasterBlock *block, int band, int xOffset = 0, int yOffset = 0 );
441
443 static QgsRasterDataProvider *create( const QString &providerKey,
444 const QString &uri,
445 const QString &format, int nBands,
446 Qgis::DataType type,
447 int width, int height, double *geoTransform,
449 const QStringList &createOptions = QStringList() );
450
456 virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ) Q_UNUSED( noDataValue ); return false; }
457
459 virtual bool remove() { return false; }
460
465 static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
466
473 {
474 QString name;
475 QString uri;
476 QString provider;
477 };
478
485 {
488 int width;
490 QString formula;
491 QList <QgsRasterDataProvider::VirtualRasterInputLayers> rInputLayers;
492
493 };
494
500 static QgsRasterDataProvider::VirtualRasterParameters decodeVirtualRasterProviderUri( const QString &uri, bool *ok = nullptr );
501
507 static QString encodeVirtualRasterProviderUri( const VirtualRasterParameters &parts );
508
514 virtual QString validateCreationOptions( const QStringList &createOptions, const QString &format )
515 { Q_UNUSED( createOptions ) Q_UNUSED( format ); return QString(); }
516
522 const QStringList &configOptions, const QString &fileFormat )
523 { Q_UNUSED( pyramidsFormat ) Q_UNUSED( configOptions ); Q_UNUSED( fileFormat ); return QString(); }
524
530 static QString identifyFormatName( Qgis::RasterIdentifyFormat format );
531
537 static Qgis::RasterIdentifyFormat identifyFormatFromName( const QString &formatName );
538
542 static QString identifyFormatLabel( Qgis::RasterIdentifyFormat format );
543
547 static Qgis::RasterInterfaceCapability identifyFormatToCapability( Qgis::RasterIdentifyFormat format );
548
554
560
569 virtual QList< double > nativeResolutions() const;
570
577 virtual bool ignoreExtents() const;
578
588
601 virtual QgsPoint transformCoordinates( const QgsPoint &point, TransformType type );
602
603
610 virtual bool enableProviderResampling( bool enable ) { Q_UNUSED( enable ); return false; }
611
624 bool isProviderResamplingEnabled() const { return mProviderResamplingEnabled; }
625
631 {
632 Nearest,
633 Bilinear,
634 Cubic,
635 CubicSpline,
636 Lanczos,
637 Average,
638 Mode,
639 Gauss
640 };
641
648 virtual bool setZoomedInResamplingMethod( ResamplingMethod method ) { Q_UNUSED( method ); return false; }
649
654 ResamplingMethod zoomedInResamplingMethod() const { return mZoomedInResamplingMethod; }
655
662 virtual bool setZoomedOutResamplingMethod( ResamplingMethod method ) { Q_UNUSED( method ); return false; }
663
668 ResamplingMethod zoomedOutResamplingMethod() const { return mZoomedOutResamplingMethod; }
669
676 virtual bool setMaxOversampling( double factor ) { Q_UNUSED( factor ); return false; }
677
682 double maxOversampling() const { return mMaxOversampling; }
683
684 void readXml( const QDomElement &filterElem ) override;
685
686 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
687
693 QgsRasterAttributeTable *attributeTable( int bandNumber ) const;
694
703 void setAttributeTable( int bandNumber, QgsRasterAttributeTable *attributeTable SIP_TRANSFER );
704
711 void removeAttributeTable( int bandNumber );
712
720 bool writeFileBasedAttributeTable( int bandNumber, const QString &path, QString *errorMessage SIP_OUT = nullptr ) const;
721
728 bool readFileBasedAttributeTable( int bandNumber, const QString &path, QString *errorMessage SIP_OUT = nullptr );
729
740 virtual bool writeNativeAttributeTable( QString *errorMessage SIP_OUT = nullptr ); //#spellok
741
750 virtual bool readNativeAttributeTable( QString *errorMessage SIP_OUT = nullptr );
751
757 // Note: This method is not const because GDAL init on demand
758 virtual QString bandDescription( int bandNumber );
759
760
761 signals:
762
766 void statusChanged( const QString & ) const;
767
768
769 protected:
770
776 virtual bool readBlock( int bandNo, int xBlock, int yBlock, void *data ) SIP_SKIP
777 { Q_UNUSED( bandNo ) Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); return false; }
778
784 virtual bool readBlock( int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data, QgsRasterBlockFeedback *feedback = nullptr ) SIP_SKIP
785 { Q_UNUSED( bandNo ) Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); return false; }
786
788 bool userNoDataValuesContains( int bandNo, double value ) const;
789
791 void copyBaseSettings( const QgsRasterDataProvider &other );
792
797 int mDpi = -1;
798
803 //bool hasNoDataValue ( int bandNo );
804
806 QList<double> mSrcNoDataValue;
807
810
817
822 QList< QgsRasterRangeList > mUserNoDataValue;
823
825
827 bool mProviderResamplingEnabled = false;
828
830 ResamplingMethod mZoomedInResamplingMethod = ResamplingMethod::Nearest;
831
833 ResamplingMethod mZoomedOutResamplingMethod = ResamplingMethod::Nearest;
834
836 double mMaxOversampling = 2.0;
837
838 private:
839
843 std::unique_ptr< QgsRasterDataProviderTemporalCapabilities > mTemporalCapabilities;
844
845 std::unique_ptr< QgsRasterDataProviderElevationProperties > mElevationProperties;
846
847 std::map<int, std::unique_ptr<QgsRasterAttributeTable>> mAttributeTables;
848
849};
850
851// clazy:excludeall=qstring-allocations
852
853#endif
QFlags< RasterProviderCapability > RasterProviderCapabilities
Raster data provider capabilities.
Definition qgis.h:4562
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:4458
@ GeoTiff
Geotiff .ovr (external)
RasterInterfaceCapability
Raster interface capabilities.
Definition qgis.h:4509
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
DataType
Raster data types.
Definition qgis.h:351
RasterColorInterpretation
Raster color interpretation.
Definition qgis.h:4368
RasterIdentifyFormat
Raster identify formats.
Definition qgis.h:4488
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:46
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.
double value(int row, int column) const
Read a single value if type of block is numeric.
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...
virtual bool write(const void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
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 QSize maximumTileSize() const
Returns the maximum tile size in pixels for the data provider.
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.
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.
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 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.
#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
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