QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsrasterinterface.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterface.h - Internal raster processing modules interface
3 --------------------------------------
4 Date : Jun 21, 2012
5 Copyright : (C) 2012 by Radim Blazek
6 email : radim dot blazek at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSRASTERINTERFACE_H
19#define QGSRASTERINTERFACE_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include <limits>
24
25#include <QCoreApplication> // for tr()
26#include <QImage>
27
28#include "qgsfeedback.h"
29#include "qgis.h"
30#include "qgsrasterblock.h"
31#include "qgsrasterhistogram.h"
32#include "qgsrectangle.h"
33#include "qgsrendercontext.h"
34#include "qgsrasterbandstats.h"
35
41class CORE_EXPORT QgsRasterBlockFeedback : public QgsFeedback
42{
43 Q_OBJECT
44
45 public:
47 QgsRasterBlockFeedback( QObject *parent = nullptr ) : QgsFeedback( parent ) {}
48
53 virtual void onNewData() {}
54
60 bool isPreviewOnly() const { return mPreviewOnly; }
61
66 void setPreviewOnly( bool preview ) { mPreviewOnly = preview; }
67
72 bool renderPartialOutput() const { return mRenderPartialOutput; }
73
78 void setRenderPartialOutput( bool enable ) { mRenderPartialOutput = enable; }
79
87 void appendError( const QString &error ) { mErrors.append( error ); }
88
95 QStringList errors() const { return mErrors; }
96
103 QgsRenderContext renderContext() const;
104
111 void setRenderContext( const QgsRenderContext &renderContext );
112
113 private:
114
119 bool mPreviewOnly = false;
120
122 bool mRenderPartialOutput = false;
123
125 QStringList mErrors;
126
127 QgsRenderContext mRenderContext;
128};
129
130
135class CORE_EXPORT QgsRasterInterface
136{
137// QgsRasterInterface subclasses
138 //SIP_TYPEHEADER_INCLUDE( "qgsbrightnesscontrastfilter.h" );
139 //SIP_TYPEHEADER_INCLUDE( "qgshuesaturationfilter.h" );
140 //SIP_TYPEHEADER_INCLUDE( "qgsrasterdataprovider.h" );
141 //SIP_TYPEHEADER_INCLUDE( "qgsrasternuller.h" );
142 //SIP_TYPEHEADER_INCLUDE( "qgsrasterprojector.h" );
143 //SIP_TYPEHEADER_INCLUDE( "qgsrasterrenderer.h" );
144 //SIP_TYPEHEADER_INCLUDE( "qgsrasterresamplefilter.h" );
145// QgsRasterRenderer subclasses
146 //SIP_TYPEHEADER_INCLUDE( "qgshillshaderenderer.h" );
147 //SIP_TYPEHEADER_INCLUDE( "qgsmultibandcolorrenderer.h" );
148 //SIP_TYPEHEADER_INCLUDE( "qgspalettedrasterrenderer.h" );
149 //SIP_TYPEHEADER_INCLUDE( "qgssinglebandcolordatarenderer.h" );
150 //SIP_TYPEHEADER_INCLUDE( "qgssinglebandgrayrenderer.h" );
151 //SIP_TYPEHEADER_INCLUDE( "qgssinglebandpseudocolorrenderer.h" );
152 //SIP_TYPEHEADER_INCLUDE( "qgsrastersinglecolorrenderer.h" );
153 //SIP_TYPEHEADER_INCLUDE( "qgsrastercontourrenderer.h" );
154
155
156#ifdef SIP_RUN
158 if ( dynamic_cast<QgsBrightnessContrastFilter *>( sipCpp ) )
159 sipType = sipType_QgsBrightnessContrastFilter;
160 else if ( dynamic_cast<QgsHueSaturationFilter *>( sipCpp ) )
161 sipType = sipType_QgsHueSaturationFilter;
162 else if ( dynamic_cast<QgsRasterDataProvider *>( sipCpp ) )
163 {
164 sipType = sipType_QgsRasterDataProvider;
165 // use static cast because QgsRasterDataProvider has multiple inheritance
166 // and we would end up with bad pointer otherwise!
167 *sipCppRet = static_cast<QgsRasterDataProvider *>( sipCpp );
168 }
169 else if ( dynamic_cast<QgsRasterNuller *>( sipCpp ) )
170 sipType = sipType_QgsRasterNuller;
171 else if ( dynamic_cast<QgsRasterProjector *>( sipCpp ) )
172 sipType = sipType_QgsRasterProjector;
173 else if ( dynamic_cast<QgsRasterRenderer *>( sipCpp ) )
174 {
175 if ( dynamic_cast<QgsHillshadeRenderer *>( sipCpp ) )
176 sipType = sipType_QgsHillshadeRenderer;
177 else if ( dynamic_cast<QgsMultiBandColorRenderer *>( sipCpp ) )
178 sipType = sipType_QgsMultiBandColorRenderer;
179 else if ( dynamic_cast<QgsPalettedRasterRenderer *>( sipCpp ) )
180 sipType = sipType_QgsPalettedRasterRenderer;
181 else if ( dynamic_cast<QgsSingleBandColorDataRenderer *>( sipCpp ) )
182 sipType = sipType_QgsSingleBandColorDataRenderer;
183 else if ( dynamic_cast<QgsSingleBandGrayRenderer *>( sipCpp ) )
184 sipType = sipType_QgsSingleBandGrayRenderer;
185 else if ( dynamic_cast<QgsSingleBandPseudoColorRenderer *>( sipCpp ) )
186 sipType = sipType_QgsSingleBandPseudoColorRenderer;
187 else if ( dynamic_cast<QgsRasterSingleColorRenderer *>( sipCpp ) )
188 sipType = sipType_QgsRasterSingleColorRenderer;
189 else if ( dynamic_cast<QgsRasterContourRenderer *>( sipCpp ) )
190 sipType = sipType_QgsRasterContourRenderer;
191 else
192 sipType = sipType_QgsRasterRenderer;
193 }
194 else if ( dynamic_cast<QgsRasterResampleFilter *>( sipCpp ) )
195 sipType = sipType_QgsRasterResampleFilter;
196 else
197 sipType = 0;
198 SIP_END
199#endif
200
201 Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface )
202
203 public:
204
205 QgsRasterInterface( QgsRasterInterface *input = nullptr );
206
207 virtual ~QgsRasterInterface() = default;
208
211
212 // TODO QGIS 4.0 -- rename to interfaceCapabilities, to avoid confusion with QgsRasterDataProvider::providerCapabilities
213 // (which inherits this class)
214
218 virtual Qgis::RasterInterfaceCapabilities capabilities() const;
219
225 Q_DECL_DEPRECATED QString capabilitiesString() const SIP_DEPRECATED;
226
228 virtual Qgis::DataType dataType( int bandNo ) const = 0;
229
234 virtual Qgis::DataType sourceDataType( int bandNo ) const { return mInput ? mInput->sourceDataType( bandNo ) : Qgis::DataType::UnknownDataType; }
235
240 virtual QgsRectangle extent() const { return mInput ? mInput->extent() : QgsRectangle(); }
241
245 int dataTypeSize( int bandNo ) const { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
246
248 virtual int bandCount() const = 0;
249
251 virtual int xBlockSize() const { return mInput ? mInput->xBlockSize() : 0; }
252 virtual int yBlockSize() const { return mInput ? mInput->yBlockSize() : 0; }
253
255 virtual int xSize() const { return mInput ? mInput->xSize() : 0; }
256 virtual int ySize() const { return mInput ? mInput->ySize() : 0; }
257
259 virtual QString generateBandName( int bandNumber ) const;
260
267 virtual QString colorInterpretationName( int bandNumber ) const;
268
274 QString displayBandName( int bandNumber ) const;
275
286 virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) = 0 SIP_FACTORY;
287
292 virtual bool setInput( QgsRasterInterface *input ) { mInput = input; return true; }
293
295 virtual QgsRasterInterface *input() const { return mInput; }
296
298 virtual bool on() const { return mOn; }
299
301 virtual void setOn( bool on ) { mOn = on; }
302
310 {
311 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
312 return mInput ? mInput->sourceInput() : this;
313 }
314
321 {
322 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
323 return mInput ? mInput->sourceInput() : this;
324 }
325
335 Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) SIP_DEPRECATED;
336
345 virtual QgsRasterBandStats bandStatistics( int bandNo,
346 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
347 const QgsRectangle &extent = QgsRectangle(),
348 int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr );
349
356 Q_DECL_DEPRECATED bool hasStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 ) SIP_DEPRECATED;
357
363 virtual bool hasStatistics( int bandNo,
364 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
365 const QgsRectangle &extent = QgsRectangle(),
366 int sampleSize = 0 );
367
368
382#ifndef SIP_RUN
383 virtual QgsRasterHistogram histogram( int bandNo,
384 int binCount = 0,
385 double minimum = std::numeric_limits<double>::quiet_NaN(),
386 double maximum = std::numeric_limits<double>::quiet_NaN(),
387 const QgsRectangle &extent = QgsRectangle(),
388 int sampleSize = 0,
389 bool includeOutOfRange = false,
390 QgsRasterBlockFeedback *feedback = nullptr );
391#else
392 virtual QgsRasterHistogram histogram( int bandNo,
393 int binCount = 0,
394 SIP_PYOBJECT minimum = Py_None,
395 SIP_PYOBJECT maximum = Py_None,
396 const QgsRectangle &extent = QgsRectangle(),
397 int sampleSize = 0,
398 bool includeOutOfRange = false,
399 QgsRasterBlockFeedback *feedback = nullptr )
400 [QgsRasterHistogram( int bandNo,
401 int binCount = 0,
402 double minimum = 0.0,
403 double maximum = 0.0,
404 const QgsRectangle &extent = QgsRectangle(),
405 int sampleSize = 0,
406 bool includeOutOfRange = false,
407 QgsRasterBlockFeedback *feedback = nullptr )];
408 % MethodCode
409 double minimum;
410 double maximum;
411 if ( a2 == Py_None )
412 {
413 minimum = std::numeric_limits<double>::quiet_NaN();
414 }
415 else
416 {
417 minimum = PyFloat_AsDouble( a2 );
418 }
419
420 if ( a3 == Py_None )
421 {
422 maximum = std::numeric_limits<double>::quiet_NaN();
423 }
424 else
425 {
426 maximum = PyFloat_AsDouble( a3 );
427 }
428
429 QgsRasterHistogram *h = new QgsRasterHistogram( sipCpp->histogram( a0, a1, minimum, maximum, *a4, a5, a6, a7 ) );
430 return sipConvertFromType( h, sipType_QgsRasterHistogram, Py_None );
431 % End
432#endif
433
434
439#ifndef SIP_RUN
440 virtual bool hasHistogram( int bandNo,
441 int binCount,
442 double minimum = std::numeric_limits<double>::quiet_NaN(),
443 double maximum = std::numeric_limits<double>::quiet_NaN(),
444 const QgsRectangle &extent = QgsRectangle(),
445 int sampleSize = 0,
446 bool includeOutOfRange = false );
447#else
448 virtual bool hasHistogram( int bandNo,
449 int binCount,
450 SIP_PYOBJECT minimum = Py_None,
451 SIP_PYOBJECT maximum = Py_None,
452 const QgsRectangle &extent = QgsRectangle(),
453 int sampleSize = 0,
454 bool includeOutOfRange = false )
455 [bool( int bandNo,
456 int binCount,
457 double minimum = 0.0,
458 double maximum = 0.0,
459 const QgsRectangle &extent = QgsRectangle(),
460 int sampleSize = 0,
461 bool includeOutOfRange = false )];
462 % MethodCode
463 double minimum;
464 double maximum;
465 if ( a2 == Py_None )
466 {
467 minimum = std::numeric_limits<double>::quiet_NaN();
468 }
469 else
470 {
471 minimum = PyFloat_AsDouble( a2 );
472 }
473
474 if ( a3 == Py_None )
475 {
476 maximum = std::numeric_limits<double>::quiet_NaN();
477 }
478 else
479 {
480 maximum = PyFloat_AsDouble( a3 );
481 }
482
483 sipRes = sipCpp->hasHistogram( a0, a1, minimum, maximum, *a4, a5, a6 );
484 % End
485#endif
486
487
498 virtual void cumulativeCut( int bandNo,
499 double lowerCount,
500 double upperCount,
501 double &lowerValue,
502 double &upperValue,
503 const QgsRectangle &extent = QgsRectangle(),
504 int sampleSize = 0 );
505
507 virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const { Q_UNUSED( doc ) Q_UNUSED( parentElem ); }
509 virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ) }
510
511 protected:
512 // QgsRasterInterface used as input
513 QgsRasterInterface *mInput = nullptr;
514
516 QList<QgsRasterBandStats> mStatistics;
517
519 QList<QgsRasterHistogram> mHistograms;
520
521 // On/off state, if off, it does not do anything, replicates input
522 bool mOn = true;
523
528#ifndef SIP_RUN
529 void initHistogram( QgsRasterHistogram &histogram,
530 int bandNo,
531 int binCount,
532 double minimum = std::numeric_limits<double>::quiet_NaN(),
533 double maximum = std::numeric_limits<double>::quiet_NaN(),
534 const QgsRectangle &boundingBox = QgsRectangle(),
535 int sampleSize = 0,
536 bool includeOutOfRange = false );
537#else
538 void initHistogram( QgsRasterHistogram &histogram,
539 int bandNo,
540 int binCount,
541 SIP_PYOBJECT minimum = Py_None,
542 SIP_PYOBJECT maximum = Py_None,
543 const QgsRectangle &boundingBox = QgsRectangle(),
544 int sampleSize = 0,
545 bool includeOutOfRange = false )
546 [void ( QgsRasterHistogram & histogram,
547 int bandNo,
548 int binCount,
549 double minimum = 0.0,
550 double maximum = 0.0,
551 const QgsRectangle &boundingBox = QgsRectangle(),
552 int sampleSize = 0,
553 bool includeOutOfRange = false )];
554 % MethodCode
555 double minimum;
556 double maximum;
557 if ( a3 == Py_None )
558 {
559 minimum = std::numeric_limits<double>::quiet_NaN();
560 }
561 else
562 {
563 minimum = PyFloat_AsDouble( a3 );
564 }
565
566 if ( a4 == Py_None )
567 {
568 maximum = std::numeric_limits<double>::quiet_NaN();
569 }
570 else
571 {
572 maximum = PyFloat_AsDouble( a4 );
573 }
574
575#if defined(SIP_PROTECTED_IS_PUBLIC) || (SIP_VERSION >= 0x050000 && !defined(_MSC_VER))
576 sipCpp->initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
577#else
578 sipCpp->sipProtect_initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
579#endif
580 % End
581#endif
582
587 Q_DECL_DEPRECATED void initStatistics( QgsRasterBandStats &statistics, int bandNo, int stats, const QgsRectangle &boundingBox = QgsRectangle(), int binCount = 0 ) const SIP_DEPRECATED;
588
590 void initStatistics( QgsRasterBandStats &statistics, int bandNo,
591 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
592 const QgsRectangle &boundingBox = QgsRectangle(),
593 int binCount = 0 ) const;
594
595 private:
596#ifdef SIP_RUN
598 QgsRasterInterface &operator=( const QgsRasterInterface & );
599#endif
600
601 Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
602};
603
604#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QFlags< RasterInterfaceCapability > RasterInterfaceCapabilities
Raster interface capabilities.
Definition qgis.h:4582
@ UnknownDataType
Unknown or unspecified type.
Brightness/contrast and gamma correction filter pipe for rasters.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
A renderer for generating live hillshade models.
Color and saturation filter pipe for rasters.
Renderer for multiband images with the color components.
Renderer for paletted raster images.
The RasterBandStats struct is a container for statistics about a single raster band.
Feedback object tailored for raster block reading.
bool isPreviewOnly() const
Whether the raster provider should return only data that are already available without waiting for fu...
QStringList errors() const
Returns a list of any errors encountered while retrieving the raster block.
virtual void onNewData()
May be emitted by raster data provider to indicate that some partial data are available and a new pre...
QgsRasterBlockFeedback(QObject *parent=nullptr)
Construct a new raster block feedback object.
void setPreviewOnly(bool preview)
set flag whether the block request is for preview purposes only
bool renderPartialOutput() const
Whether our painter is drawing to a temporary image used just by this layer.
void appendError(const QString &error)
Appends an error message to the stored list of errors.
void setRenderPartialOutput(bool enable)
Set whether our painter is drawing to a temporary image used just by this layer.
Raster data container.
static int typeSize(Qgis::DataType dataType)
Returns the size in bytes for the specified dataType.
Raster renderer that generates contours on the fly for a source raster band.
Base class for raster data providers.
The QgsRasterHistogram is a container for histogram of a single raster band.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
virtual int yBlockSize() const
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)=0
Read block of data using given extent and size.
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
virtual int xSize() const
Gets raster size.
virtual void setOn(bool on)
Sets whether the interface is on or off.
virtual int xBlockSize() const
Gets block size.
virtual int bandCount() const =0
Gets number of bands.
virtual bool on() const
Returns whether the interface is on or off.
virtual QgsRasterInterface * sourceInput()
Gets source / raw input, the first in pipe, usually provider.
virtual ~QgsRasterInterface()=default
int dataTypeSize(int bandNo) const
Returns the size (in bytes) for the data type for the specified band.
virtual void readXml(const QDomElement &filterElem)
Sets base class members from xml. Usually called from create() methods of subclasses.
virtual int ySize() const
virtual QgsRectangle extent() const
Gets the extent of the interface.
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
virtual void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
virtual QgsRasterInterface * input() const
Current input.
virtual const QgsRasterInterface * sourceInput() const
Gets source / raw input, the first in pipe, usually provider.
virtual bool setInput(QgsRasterInterface *input)
Set input.
Raster pipe that deals with null values.
Implements approximate projection support for optimised raster transformation.
Raster renderer pipe that applies colors to a raster.
Resample filter pipe for rasters.
Raster renderer which renders all data pixels using a single color.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Raster renderer pipe for single band color.
Raster renderer pipe for single band gray.
Raster renderer pipe for single band pseudocolor.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39