QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 "qgsrasterbandstats.h"
30#include "qgsrasterblock.h"
31#include "qgsrasterhistogram.h"
32#include "qgsrectangle.h"
33#include "qgsrendercontext.h"
34
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#ifdef SIP_RUN
138// QgsRasterInterface subclasses
142#include <qgsrasternuller.h>
143#include <qgsrasterprojector.h>
144#include <qgsrasterrenderer.h>
146
147// QgsRasterRenderer subclasses
148#include <qgshillshaderenderer.h>
154#endif
155
156
157#ifdef SIP_RUN
159 if ( dynamic_cast<QgsBrightnessContrastFilter *>( sipCpp ) )
160 sipType = sipType_QgsBrightnessContrastFilter;
161 else if ( dynamic_cast<QgsHueSaturationFilter *>( sipCpp ) )
162 sipType = sipType_QgsHueSaturationFilter;
163 else if ( dynamic_cast<QgsRasterDataProvider *>( sipCpp ) )
164 {
165 sipType = sipType_QgsRasterDataProvider;
166 // use static cast because QgsRasterDataProvider has multiple inheritance
167 // and we would end up with bad pointer otherwise!
168 *sipCppRet = static_cast<QgsRasterDataProvider *>( sipCpp );
169 }
170 else if ( dynamic_cast<QgsRasterNuller *>( sipCpp ) )
171 sipType = sipType_QgsRasterNuller;
172 else if ( dynamic_cast<QgsRasterProjector *>( sipCpp ) )
173 sipType = sipType_QgsRasterProjector;
174 else if ( dynamic_cast<QgsRasterRenderer *>( sipCpp ) )
175 {
176 if ( dynamic_cast<QgsHillshadeRenderer *>( sipCpp ) )
177 sipType = sipType_QgsHillshadeRenderer;
178 else if ( dynamic_cast<QgsMultiBandColorRenderer *>( sipCpp ) )
179 sipType = sipType_QgsMultiBandColorRenderer;
180 else if ( dynamic_cast<QgsPalettedRasterRenderer *>( sipCpp ) )
181 sipType = sipType_QgsPalettedRasterRenderer;
182 else if ( dynamic_cast<QgsSingleBandColorDataRenderer *>( sipCpp ) )
183 sipType = sipType_QgsSingleBandColorDataRenderer;
184 else if ( dynamic_cast<QgsSingleBandGrayRenderer *>( sipCpp ) )
185 sipType = sipType_QgsSingleBandGrayRenderer;
186 else if ( dynamic_cast<QgsSingleBandPseudoColorRenderer *>( sipCpp ) )
187 sipType = sipType_QgsSingleBandPseudoColorRenderer;
188 else
189 sipType = sipType_QgsRasterRenderer;
190 }
191 else if ( dynamic_cast<QgsRasterResampleFilter *>( sipCpp ) )
192 sipType = sipType_QgsRasterResampleFilter;
193 else
194 sipType = 0;
195 SIP_END
196#endif
197
198 Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface )
199
200 public:
203 {
204 NoCapabilities = 0,
205 Size = 1 << 1,
206 Create = 1 << 2,
207 Remove = 1 << 3,
208 BuildPyramids = 1 << 4,
209 Identify = 1 << 5,
210 IdentifyValue = 1 << 6,
211 IdentifyText = 1 << 7,
212 IdentifyHtml = 1 << 8,
213 IdentifyFeature = 1 << 9,
214 Prefetch = 1 << 10,
215 };
216
217 QgsRasterInterface( QgsRasterInterface *input = nullptr );
218
219 virtual ~QgsRasterInterface() = default;
220
223
225 virtual int capabilities() const
226 {
228 }
229
233 QString capabilitiesString() const;
234
236 virtual Qgis::DataType dataType( int bandNo ) const = 0;
237
242 virtual Qgis::DataType sourceDataType( int bandNo ) const { return mInput ? mInput->sourceDataType( bandNo ) : Qgis::DataType::UnknownDataType; }
243
248 virtual QgsRectangle extent() const { return mInput ? mInput->extent() : QgsRectangle(); }
249
253 int dataTypeSize( int bandNo ) const { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
254
256 virtual int bandCount() const = 0;
257
259 virtual int xBlockSize() const { return mInput ? mInput->xBlockSize() : 0; }
260 virtual int yBlockSize() const { return mInput ? mInput->yBlockSize() : 0; }
261
263 virtual int xSize() const { return mInput ? mInput->xSize() : 0; }
264 virtual int ySize() const { return mInput ? mInput->ySize() : 0; }
265
267 virtual QString generateBandName( int bandNumber ) const;
268
274 virtual QString colorInterpretationName( int bandNumber ) const;
275
281 QString displayBandName( int bandNumber ) const;
282
293 virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) = 0 SIP_FACTORY;
294
299 virtual bool setInput( QgsRasterInterface *input ) { mInput = input; return true; }
300
302 virtual QgsRasterInterface *input() const { return mInput; }
303
305 virtual bool on() const { return mOn; }
306
308 virtual void setOn( bool on ) { mOn = on; }
309
317 {
318 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
319 return mInput ? mInput->sourceInput() : this;
320 }
321
328 {
329 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
330 return mInput ? mInput->sourceInput() : this;
331 }
332
341 virtual QgsRasterBandStats bandStatistics( int bandNo,
342 int stats = QgsRasterBandStats::All,
343 const QgsRectangle &extent = QgsRectangle(),
344 int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr );
345
350 virtual bool hasStatistics( int bandNo,
351 int stats = QgsRasterBandStats::All,
352 const QgsRectangle &extent = QgsRectangle(),
353 int sampleSize = 0 );
354
355
369#ifndef SIP_RUN
370 virtual QgsRasterHistogram histogram( int bandNo,
371 int binCount = 0,
372 double minimum = std::numeric_limits<double>::quiet_NaN(),
373 double maximum = std::numeric_limits<double>::quiet_NaN(),
374 const QgsRectangle &extent = QgsRectangle(),
375 int sampleSize = 0,
376 bool includeOutOfRange = false,
377 QgsRasterBlockFeedback *feedback = nullptr );
378#else
379 virtual QgsRasterHistogram histogram( int bandNo,
380 int binCount = 0,
381 SIP_PYOBJECT minimum = Py_None,
382 SIP_PYOBJECT maximum = Py_None,
383 const QgsRectangle &extent = QgsRectangle(),
384 int sampleSize = 0,
385 bool includeOutOfRange = false,
386 QgsRasterBlockFeedback *feedback = nullptr )
387 [QgsRasterHistogram( int bandNo,
388 int binCount = 0,
389 double minimum = 0.0,
390 double maximum = 0.0,
391 const QgsRectangle &extent = QgsRectangle(),
392 int sampleSize = 0,
393 bool includeOutOfRange = false,
394 QgsRasterBlockFeedback *feedback = nullptr )];
395 % MethodCode
396 double minimum;
397 double maximum;
398 if ( a2 == Py_None )
399 {
400 minimum = std::numeric_limits<double>::quiet_NaN();
401 }
402 else
403 {
404 minimum = PyFloat_AsDouble( a2 );
405 }
406
407 if ( a3 == Py_None )
408 {
409 maximum = std::numeric_limits<double>::quiet_NaN();
410 }
411 else
412 {
413 maximum = PyFloat_AsDouble( a3 );
414 }
415
416 QgsRasterHistogram *h = new QgsRasterHistogram( sipCpp->histogram( a0, a1, minimum, maximum, *a4, a5, a6, a7 ) );
417 return sipConvertFromType( h, sipType_QgsRasterHistogram, Py_None );
418 % End
419#endif
420
421
426#ifndef SIP_RUN
427 virtual bool hasHistogram( int bandNo,
428 int binCount,
429 double minimum = std::numeric_limits<double>::quiet_NaN(),
430 double maximum = std::numeric_limits<double>::quiet_NaN(),
431 const QgsRectangle &extent = QgsRectangle(),
432 int sampleSize = 0,
433 bool includeOutOfRange = false );
434#else
435 virtual bool hasHistogram( int bandNo,
436 int binCount,
437 SIP_PYOBJECT minimum = Py_None,
438 SIP_PYOBJECT maximum = Py_None,
439 const QgsRectangle &extent = QgsRectangle(),
440 int sampleSize = 0,
441 bool includeOutOfRange = false )
442 [bool( int bandNo,
443 int binCount,
444 double minimum = 0.0,
445 double maximum = 0.0,
446 const QgsRectangle &extent = QgsRectangle(),
447 int sampleSize = 0,
448 bool includeOutOfRange = false )];
449 % MethodCode
450 double minimum;
451 double maximum;
452 if ( a2 == Py_None )
453 {
454 minimum = std::numeric_limits<double>::quiet_NaN();
455 }
456 else
457 {
458 minimum = PyFloat_AsDouble( a2 );
459 }
460
461 if ( a3 == Py_None )
462 {
463 maximum = std::numeric_limits<double>::quiet_NaN();
464 }
465 else
466 {
467 maximum = PyFloat_AsDouble( a3 );
468 }
469
470 sipRes = sipCpp->hasHistogram( a0, a1, minimum, maximum, *a4, a5, a6 );
471 % End
472#endif
473
474
485 virtual void cumulativeCut( int bandNo,
486 double lowerCount,
487 double upperCount,
488 double &lowerValue,
489 double &upperValue,
490 const QgsRectangle &extent = QgsRectangle(),
491 int sampleSize = 0 );
492
494 virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const { Q_UNUSED( doc ) Q_UNUSED( parentElem ); }
496 virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ) }
497
498 protected:
499 // QgsRasterInterface used as input
500 QgsRasterInterface *mInput = nullptr;
501
503 QList<QgsRasterBandStats> mStatistics;
504
506 QList<QgsRasterHistogram> mHistograms;
507
508 // On/off state, if off, it does not do anything, replicates input
509 bool mOn = true;
510
515#ifndef SIP_RUN
516 void initHistogram( QgsRasterHistogram &histogram,
517 int bandNo,
518 int binCount,
519 double minimum = std::numeric_limits<double>::quiet_NaN(),
520 double maximum = std::numeric_limits<double>::quiet_NaN(),
521 const QgsRectangle &boundingBox = QgsRectangle(),
522 int sampleSize = 0,
523 bool includeOutOfRange = false );
524#else
525 void initHistogram( QgsRasterHistogram &histogram,
526 int bandNo,
527 int binCount,
528 SIP_PYOBJECT minimum = Py_None,
529 SIP_PYOBJECT maximum = Py_None,
530 const QgsRectangle &boundingBox = QgsRectangle(),
531 int sampleSize = 0,
532 bool includeOutOfRange = false )
533 [void ( QgsRasterHistogram & histogram,
534 int bandNo,
535 int binCount,
536 double minimum = 0.0,
537 double maximum = 0.0,
538 const QgsRectangle &boundingBox = QgsRectangle(),
539 int sampleSize = 0,
540 bool includeOutOfRange = false )];
541 % MethodCode
542 double minimum;
543 double maximum;
544 if ( a3 == Py_None )
545 {
546 minimum = std::numeric_limits<double>::quiet_NaN();
547 }
548 else
549 {
550 minimum = PyFloat_AsDouble( a3 );
551 }
552
553 if ( a4 == Py_None )
554 {
555 maximum = std::numeric_limits<double>::quiet_NaN();
556 }
557 else
558 {
559 maximum = PyFloat_AsDouble( a4 );
560 }
561
562#if defined(SIP_PROTECTED_IS_PUBLIC) || (SIP_VERSION >= 0x050000 && !defined(_MSC_VER))
563 sipCpp->initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
564#else
565 sipCpp->sipProtect_initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
566#endif
567 % End
568#endif
569
571 void initStatistics( QgsRasterBandStats &statistics, int bandNo,
572 int stats = QgsRasterBandStats::All,
573 const QgsRectangle &boundingBox = QgsRectangle(),
574 int binCount = 0 ) const;
575
576 private:
577#ifdef SIP_RUN
579 QgsRasterInterface &operator=( const QgsRasterInterface & );
580#endif
581
582 Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
583};
584
585#endif
DataType
Raster data types.
Definition: qgis.h:129
@ 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:45
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) SIP_HOLDGIL
Returns the size in bytes for the specified dataType.
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.
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
Capability
If you add to this, please also add to capabilitiesString()
virtual int xSize() const
Gets raster size.
virtual void setOn(bool on)
Sets whether the interface is on or off.
virtual Qgis::DataType sourceDataType(int bandNo) const
Returns source data type for the band specified by number, source data type may be shorter than dataT...
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 capabilities() const
Returns a bitmask containing the supported capabilities.
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.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
Raster renderer pipe that applies colors to a raster.
Resample filter pipe for rasters.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
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:186
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:203
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39