QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 <cmath>
27
28#include "qgis_core.h"
29#include "qgis_sip.h"
30#include "qgscolorrampshader.h"
31#include "qgsdataprovider.h"
32#include "qgsfields.h"
36#include "qgsrasterinterface.h"
37#include "qgsrasteriterator.h"
38#include "qgsrasterpyramid.h"
39#include "qgsrasterrange.h"
40#include "qgsrectangle.h"
41
42#include <QDateTime>
43#include <QImage>
44#include <QString>
45#include <QVariant>
46
47using namespace Qt::StringLiterals;
48
49class QImage;
50class QByteArray;
51
52class QgsPointXY;
54class QgsMapSettings;
55
60class CORE_EXPORT QgsImageFetcher : public QObject
61{
62 Q_OBJECT
63 public:
65 QgsImageFetcher( QObject *parent = nullptr )
66 : QObject( parent )
67 {}
68
73 virtual void start() = 0;
74
75 signals:
76
81 void finish( const QImage &legend );
83 void progress( qint64 received, qint64 total );
85 void error( const QString &msg );
86};
87
88
94{
95 Q_OBJECT
96
97 public:
99
110 );
111
112 QgsRasterDataProvider *clone() const override = 0;
113
114
120 virtual bool hasReportsDuringClose() const SIP_SKIP;
121
137 virtual bool closeWithProgress( QgsFeedback *feedback ) SIP_SKIP;
138
142 virtual Qgis::RasterProviderCapabilities providerCapabilities() const;
143
144 // It makes no sense to set input on provider
146 {
147 Q_UNUSED( input )
148 return false;
149 }
150
151 QgsRectangle extent() const override = 0;
152
154 Qgis::DataType dataType( int bandNo ) const override = 0;
155
161 virtual QgsFields fields() const { return QgsFields(); };
162
167 Qgis::DataType sourceDataType( int bandNo ) const override = 0;
168
170 virtual Qgis::RasterColorInterpretation colorInterpretation( int bandNo ) const;
171
177
179 virtual bool reload() { return true; }
180
181 QString colorInterpretationName( int bandNo ) const override;
182
186 virtual double bandScale( int bandNo ) const
187 {
188 Q_UNUSED( bandNo )
189 return 1.0;
190 }
191
195 virtual double bandOffset( int bandNo ) const
196 {
197 Q_UNUSED( bandNo )
198 return 0.0;
199 }
200
209
210 // TODO: remove or make protected all readBlock working with void*
211
213 QgsRasterBlock *block( int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
214
216 virtual bool sourceHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo - 1 ); }
217
219 virtual bool useSourceNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo - 1 ); }
220
222 virtual void setUseSourceNoDataValue( int bandNo, bool use );
223
225 virtual double sourceNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo - 1 ); }
226
227 virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList &noData );
228
230 virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo - 1 ); }
231
232 virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
233 {
234 Q_UNUSED( bandNo )
235 return QList<QgsColorRampShader::ColorRampItem>();
236 }
237
242 QStringList subLayers() const override { return QStringList(); }
243
244 QgsRasterDataProviderTemporalCapabilities *temporalCapabilities() override;
245 const QgsRasterDataProviderTemporalCapabilities *temporalCapabilities() const override SIP_SKIP;
246 QgsRasterDataProviderElevationProperties *elevationProperties() override;
247 const QgsRasterDataProviderElevationProperties *elevationProperties() const override SIP_SKIP;
248
250 virtual bool supportsLegendGraphic() const { return false; }
251
263 virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle *visibleExtent = nullptr ) SIP_SKIP
264 {
265 Q_UNUSED( scale )
266 Q_UNUSED( forceRefresh )
267 Q_UNUSED( visibleExtent )
268 return QImage();
269 }
270
284 {
285 Q_UNUSED( mapSettings )
286 return nullptr;
287 }
288
305 virtual QString buildPyramids(
306 const QList<QgsRasterPyramid> &pyramidList,
307 const QString &resamplingMethod = "NEAREST",
309 const QStringList &configOptions = QStringList(),
310 QgsRasterBlockFeedback *feedback = nullptr
311 )
312 {
313 Q_UNUSED( pyramidList )
314 Q_UNUSED( resamplingMethod )
315 Q_UNUSED( format )
316 Q_UNUSED( configOptions )
317 Q_UNUSED( feedback )
318 return u"FAILED_NOT_SUPPORTED"_s;
319 }
320
339 virtual QList<QgsRasterPyramid> buildPyramidList( const QList<int> &overviewList = QList<int>() )
340 {
341 Q_UNUSED( overviewList )
342 return QList<QgsRasterPyramid>();
343 }
344
354 bool hasPyramids();
355
380 virtual QgsRasterIdentifyResult identify( const QgsPointXY &point, Qgis::RasterIdentifyFormat format, const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
381
396 virtual double sample( const QgsPointXY &point, int band, bool *ok SIP_OUT = nullptr, const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
397
406 virtual QString lastErrorTitle() = 0;
407
417 virtual QString lastError() = 0;
418
420 virtual QString lastErrorFormat();
421
423 int dpi() const { return mDpi; }
424
426 void setDpi( int dpi ) { mDpi = dpi; }
427
429 QDateTime timestamp() const override { return mTimestamp; }
430
432 QDateTime dataTimestamp() const override { return QDateTime(); }
433
440 virtual bool isEditable() const { return false; }
441
452 virtual bool setEditable( bool enabled )
453 {
454 Q_UNUSED( enabled )
455 return false;
456 }
457
458 // TODO: add data type (may be different from band type)
459
461 virtual bool write( const void *data, int band, int width, int height, int xOffset, int yOffset )
462 {
463 Q_UNUSED( data )
464 Q_UNUSED( band )
465 Q_UNUSED( width )
466 Q_UNUSED( height )
467 Q_UNUSED( xOffset )
468 Q_UNUSED( yOffset )
469 return false;
470 }
471
488 bool writeBlock( QgsRasterBlock *block, int band, int xOffset = 0, int yOffset = 0 );
489
490 // TODO QGIS 5.0: rename createOptions to creationOptions for consistency with GDAL
491
493 static QgsRasterDataProvider *create(
494 const QString &providerKey,
495 const QString &uri,
496 const QString &format,
497 int nBands,
498 Qgis::DataType type,
499 int width,
500 int height,
501 double *geoTransform,
503 const QStringList &createOptions = QStringList()
504 );
505
511 virtual bool setNoDataValue( int bandNo, double noDataValue )
512 {
513 Q_UNUSED( bandNo )
514 Q_UNUSED( noDataValue );
515 return false;
516 }
517
519 virtual bool remove() { return false; }
520
525 static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
526
533 {
534 QString name;
535 QString uri;
536 QString provider;
537 };
538
545 {
548 int width;
550 QString formula;
551 QList<QgsRasterDataProvider::VirtualRasterInputLayers> rInputLayers;
552 };
553
559 static QgsRasterDataProvider::VirtualRasterParameters decodeVirtualRasterProviderUri( const QString &uri, bool *ok = nullptr );
560
566 static QString encodeVirtualRasterProviderUri( const VirtualRasterParameters &parts );
567
568 // TODO QGIS 5.0: rename createOptions to creationOptions for consistency with GDAL
569
575 virtual QString validateCreationOptions( const QStringList &createOptions, const QString &format )
576 {
577 Q_UNUSED( createOptions )
578 Q_UNUSED( format );
579 return QString();
580 }
581
586 virtual QString validatePyramidsConfigOptions( Qgis::RasterPyramidFormat pyramidsFormat, const QStringList &configOptions, const QString &fileFormat )
587 {
588 Q_UNUSED( pyramidsFormat )
589 Q_UNUSED( configOptions );
590 Q_UNUSED( fileFormat );
591 return QString();
592 }
593
599 static QString identifyFormatName( Qgis::RasterIdentifyFormat format );
600
606 static Qgis::RasterIdentifyFormat identifyFormatFromName( const QString &formatName );
607
611 static QString identifyFormatLabel( Qgis::RasterIdentifyFormat format );
612
616 static Qgis::RasterInterfaceCapability identifyFormatToCapability( Qgis::RasterIdentifyFormat format );
617
623
629
638 virtual QList< double > nativeResolutions() const;
639
646 virtual bool ignoreExtents() const;
647
657
670 virtual QgsPoint transformCoordinates( const QgsPoint &point, TransformType type );
671
672
679 virtual bool enableProviderResampling( bool enable )
680 {
681 Q_UNUSED( enable );
682 return false;
683 }
684
698
706 {
707 Q_UNUSED( method );
708 return false;
709 }
710
716
724 {
725 Q_UNUSED( method );
726 return false;
727 }
728
734
741 virtual bool setMaxOversampling( double factor )
742 {
743 Q_UNUSED( factor );
744 return false;
745 }
746
751 double maxOversampling() const { return mMaxOversampling; }
752
753 void readXml( const QDomElement &filterElem ) override;
754
755 void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
756
762 QgsRasterAttributeTable *attributeTable( int bandNumber ) const;
763
772 void setAttributeTable( int bandNumber, QgsRasterAttributeTable *attributeTable SIP_TRANSFER );
773
780 void removeAttributeTable( int bandNumber );
781
789 bool writeFileBasedAttributeTable( int bandNumber, const QString &path, QString *errorMessage SIP_OUT = nullptr ) const;
790
797 bool readFileBasedAttributeTable( int bandNumber, const QString &path, QString *errorMessage SIP_OUT = nullptr );
798
809 virtual bool writeNativeAttributeTable( QString *errorMessage SIP_OUT = nullptr ); //#spellok
810
819 virtual bool readNativeAttributeTable( QString *errorMessage SIP_OUT = nullptr );
820
826 // Note: This method is not const because GDAL init on demand
827 virtual QString bandDescription( int bandNumber );
828
829
830 signals:
831
835 void statusChanged( const QString & ) const;
836
837
838 protected:
844 virtual bool readBlock( int bandNo, int xBlock, int yBlock, void *data ) SIP_SKIP
845 {
846 Q_UNUSED( bandNo )
847 Q_UNUSED( xBlock );
848 Q_UNUSED( yBlock );
849 Q_UNUSED( data );
850 return false;
851 }
852
858 virtual bool readBlock( int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data, QgsRasterBlockFeedback *feedback = nullptr ) SIP_SKIP
859 {
860 Q_UNUSED( bandNo )
861 Q_UNUSED( viewExtent );
862 Q_UNUSED( width );
863 Q_UNUSED( height );
864 Q_UNUSED( data );
865 Q_UNUSED( feedback );
866 return false;
867 }
868
870 bool userNoDataValuesContains( int bandNo, double value ) const;
871
873 void copyBaseSettings( const QgsRasterDataProvider &other );
874
879 int mDpi = -1;
880
885 //bool hasNoDataValue ( int bandNo );
886
888 QList<double> mSrcNoDataValue;
889
892
899
904 QList< QgsRasterRangeList > mUserNoDataValue;
905
907
910
913
916
918 double mMaxOversampling = 2.0;
919
920 private:
924 std::unique_ptr< QgsRasterDataProviderTemporalCapabilities > mTemporalCapabilities;
925
926 std::unique_ptr< QgsRasterDataProviderElevationProperties > mElevationProperties;
927
928 std::map<int, std::unique_ptr<QgsRasterAttributeTable>> mAttributeTables;
929};
930
931// clazy:excludeall=qstring-allocations
932
933#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:4959
@ GeoTiff
Geotiff .ovr (external).
Definition qgis.h:4960
RasterResamplingMethod
Resampling method for raster provider-level resampling.
Definition qgis.h:1562
@ Nearest
Nearest-neighbour resampling.
Definition qgis.h:1563
RasterInterfaceCapability
Raster interface capabilities.
Definition qgis.h:5010
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:512
DataType
Raster data types.
Definition qgis.h:393
RasterColorInterpretation
Raster color interpretation.
Definition qgis.h:4869
RasterIdentifyFormat
Raster identify formats.
Definition qgis.h:4989
Represents a coordinate reference system (CRS).
virtual Qgis::DataProviderFlags flags() const
Returns the generic data provider flags.
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
QgsDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Create a new dataprovider with the specified in the uri.
QgsDataSourceUri uri() const
Gets the data source specification.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
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.
Contains configuration for rendering maps.
Represents a 2D point.
Definition qgspointxy.h:62
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
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...
double mMaxOversampling
Maximum boundary for oversampling (to avoid too much data traffic). Default: 2.0.
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 sourceHasNoDataValue(int bandNo) const
Returns true if source band has no data value.
static QString encodeVirtualRasterProviderUri(const VirtualRasterParameters &parts)
Encodes the URI starting from the struct .
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 lastErrorFormat()
Returns the format of the error text for the last error in this provider.
bool mProviderResamplingEnabled
Whether provider resampling is enabled.
Qgis::RasterResamplingMethod zoomedInResamplingMethod() const
Returns resampling method for zoomed-in operations.
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.
static QgsRasterDataProvider::VirtualRasterParameters decodeVirtualRasterProviderUri(const QString &uri, bool *ok=nullptr)
Decodes the URI returning a struct with all the parameters for QgsVirtualRasterProvider class.
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 setZoomedInResamplingMethod(Qgis::RasterResamplingMethod method)
Set resampling method to apply for zoomed-in operations.
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.
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 setZoomedOutResamplingMethod(Qgis::RasterResamplingMethod method)
Set resampling method to apply for zoomed-out operations.
Qgis::RasterResamplingMethod mZoomedInResamplingMethod
Resampling method for zoomed in pixel extraction.
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.
virtual bool closeWithProgress(QgsFeedback *feedback)
Close the provider with feedback.
virtual bool hasReportsDuringClose() const
Returns whether closeWithProgress() will actually report closing progress.
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.
Qgis::RasterResamplingMethod zoomedOutResamplingMethod() const
Returns resampling method for zoomed-out operations.
virtual Qgis::RasterColorInterpretation colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
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.
virtual Qgis::RasterProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
bool setInput(QgsRasterInterface *input) override
Set input.
QList< bool > mSrcHasNoDataValue
Source no data value exists.
Qgis::RasterResamplingMethod mZoomedOutResamplingMethod
Resampling method for zoomed out pixel extraction.
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 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.
virtual QString lastErrorTitle()=0
Returns the caption error text for the last error in this provider.
virtual bool supportsLegendGraphic() const
Returns whether the provider supplies a legend graphic.
virtual QList< QgsRasterPyramid > buildPyramidList(const QList< int > &overviewList=QList< int >())
Returns the raster layers pyramid list.
Raster identify results container.
QgsRasterInterface(QgsRasterInterface *input=nullptr)
virtual QgsRasterInterface * input() const
Current input.
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:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83
QList< QgsRasterRange > QgsRasterRangeList
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