QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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>
155#endif
156
157
158#ifdef SIP_RUN
160 if ( dynamic_cast<QgsBrightnessContrastFilter *>( sipCpp ) )
161 sipType = sipType_QgsBrightnessContrastFilter;
162 else if ( dynamic_cast<QgsHueSaturationFilter *>( sipCpp ) )
163 sipType = sipType_QgsHueSaturationFilter;
164 else if ( dynamic_cast<QgsRasterDataProvider *>( sipCpp ) )
165 {
166 sipType = sipType_QgsRasterDataProvider;
167 // use static cast because QgsRasterDataProvider has multiple inheritance
168 // and we would end up with bad pointer otherwise!
169 *sipCppRet = static_cast<QgsRasterDataProvider *>( sipCpp );
170 }
171 else if ( dynamic_cast<QgsRasterNuller *>( sipCpp ) )
172 sipType = sipType_QgsRasterNuller;
173 else if ( dynamic_cast<QgsRasterProjector *>( sipCpp ) )
174 sipType = sipType_QgsRasterProjector;
175 else if ( dynamic_cast<QgsRasterRenderer *>( sipCpp ) )
176 {
177 if ( dynamic_cast<QgsHillshadeRenderer *>( sipCpp ) )
178 sipType = sipType_QgsHillshadeRenderer;
179 else if ( dynamic_cast<QgsMultiBandColorRenderer *>( sipCpp ) )
180 sipType = sipType_QgsMultiBandColorRenderer;
181 else if ( dynamic_cast<QgsPalettedRasterRenderer *>( sipCpp ) )
182 sipType = sipType_QgsPalettedRasterRenderer;
183 else if ( dynamic_cast<QgsSingleBandColorDataRenderer *>( sipCpp ) )
184 sipType = sipType_QgsSingleBandColorDataRenderer;
185 else if ( dynamic_cast<QgsSingleBandGrayRenderer *>( sipCpp ) )
186 sipType = sipType_QgsSingleBandGrayRenderer;
187 else if ( dynamic_cast<QgsSingleBandPseudoColorRenderer *>( sipCpp ) )
188 sipType = sipType_QgsSingleBandPseudoColorRenderer;
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:
206 {
207 NoCapabilities = 0,
208 Size = 1 << 1,
209 Create = 1 << 2,
210 Remove = 1 << 3,
211 BuildPyramids = 1 << 4,
212 Identify = 1 << 5,
213 IdentifyValue = 1 << 6,
214 IdentifyText = 1 << 7,
215 IdentifyHtml = 1 << 8,
216 IdentifyFeature = 1 << 9,
217 Prefetch = 1 << 10,
218 };
219
220 QgsRasterInterface( QgsRasterInterface *input = nullptr );
221
222 virtual ~QgsRasterInterface() = default;
223
226
228 virtual int capabilities() const
229 {
231 }
232
236 QString capabilitiesString() const;
237
239 virtual Qgis::DataType dataType( int bandNo ) const = 0;
240
245 virtual Qgis::DataType sourceDataType( int bandNo ) const { return mInput ? mInput->sourceDataType( bandNo ) : Qgis::DataType::UnknownDataType; }
246
251 virtual QgsRectangle extent() const { return mInput ? mInput->extent() : QgsRectangle(); }
252
256 int dataTypeSize( int bandNo ) const { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
257
259 virtual int bandCount() const = 0;
260
262 virtual int xBlockSize() const { return mInput ? mInput->xBlockSize() : 0; }
263 virtual int yBlockSize() const { return mInput ? mInput->yBlockSize() : 0; }
264
266 virtual int xSize() const { return mInput ? mInput->xSize() : 0; }
267 virtual int ySize() const { return mInput ? mInput->ySize() : 0; }
268
270 virtual QString generateBandName( int bandNumber ) const;
271
277 virtual QString colorInterpretationName( int bandNumber ) const;
278
284 QString displayBandName( int bandNumber ) const;
285
296 virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) = 0 SIP_FACTORY;
297
302 virtual bool setInput( QgsRasterInterface *input ) { mInput = input; return true; }
303
305 virtual QgsRasterInterface *input() const { return mInput; }
306
308 virtual bool on() const { return mOn; }
309
311 virtual void setOn( bool on ) { mOn = on; }
312
320 {
321 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
322 return mInput ? mInput->sourceInput() : this;
323 }
324
331 {
332 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
333 return mInput ? mInput->sourceInput() : this;
334 }
335
344 virtual QgsRasterBandStats bandStatistics( int bandNo,
345 int stats = QgsRasterBandStats::All,
346 const QgsRectangle &extent = QgsRectangle(),
347 int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr );
348
353 virtual bool hasStatistics( int bandNo,
354 int stats = QgsRasterBandStats::All,
355 const QgsRectangle &extent = QgsRectangle(),
356 int sampleSize = 0 );
357
358
372#ifndef SIP_RUN
373 virtual QgsRasterHistogram histogram( int bandNo,
374 int binCount = 0,
375 double minimum = std::numeric_limits<double>::quiet_NaN(),
376 double maximum = std::numeric_limits<double>::quiet_NaN(),
377 const QgsRectangle &extent = QgsRectangle(),
378 int sampleSize = 0,
379 bool includeOutOfRange = false,
380 QgsRasterBlockFeedback *feedback = nullptr );
381#else
382 virtual QgsRasterHistogram histogram( int bandNo,
383 int binCount = 0,
384 SIP_PYOBJECT minimum = Py_None,
385 SIP_PYOBJECT maximum = Py_None,
386 const QgsRectangle &extent = QgsRectangle(),
387 int sampleSize = 0,
388 bool includeOutOfRange = false,
389 QgsRasterBlockFeedback *feedback = nullptr )
390 [QgsRasterHistogram( int bandNo,
391 int binCount = 0,
392 double minimum = 0.0,
393 double maximum = 0.0,
394 const QgsRectangle &extent = QgsRectangle(),
395 int sampleSize = 0,
396 bool includeOutOfRange = false,
397 QgsRasterBlockFeedback *feedback = nullptr )];
398 % MethodCode
399 double minimum;
400 double maximum;
401 if ( a2 == Py_None )
402 {
403 minimum = std::numeric_limits<double>::quiet_NaN();
404 }
405 else
406 {
407 minimum = PyFloat_AsDouble( a2 );
408 }
409
410 if ( a3 == Py_None )
411 {
412 maximum = std::numeric_limits<double>::quiet_NaN();
413 }
414 else
415 {
416 maximum = PyFloat_AsDouble( a3 );
417 }
418
419 QgsRasterHistogram *h = new QgsRasterHistogram( sipCpp->histogram( a0, a1, minimum, maximum, *a4, a5, a6, a7 ) );
420 return sipConvertFromType( h, sipType_QgsRasterHistogram, Py_None );
421 % End
422#endif
423
424
429#ifndef SIP_RUN
430 virtual bool hasHistogram( int bandNo,
431 int binCount,
432 double minimum = std::numeric_limits<double>::quiet_NaN(),
433 double maximum = std::numeric_limits<double>::quiet_NaN(),
434 const QgsRectangle &extent = QgsRectangle(),
435 int sampleSize = 0,
436 bool includeOutOfRange = false );
437#else
438 virtual bool hasHistogram( int bandNo,
439 int binCount,
440 SIP_PYOBJECT minimum = Py_None,
441 SIP_PYOBJECT maximum = Py_None,
442 const QgsRectangle &extent = QgsRectangle(),
443 int sampleSize = 0,
444 bool includeOutOfRange = false )
445 [bool( int bandNo,
446 int binCount,
447 double minimum = 0.0,
448 double maximum = 0.0,
449 const QgsRectangle &extent = QgsRectangle(),
450 int sampleSize = 0,
451 bool includeOutOfRange = false )];
452 % MethodCode
453 double minimum;
454 double maximum;
455 if ( a2 == Py_None )
456 {
457 minimum = std::numeric_limits<double>::quiet_NaN();
458 }
459 else
460 {
461 minimum = PyFloat_AsDouble( a2 );
462 }
463
464 if ( a3 == Py_None )
465 {
466 maximum = std::numeric_limits<double>::quiet_NaN();
467 }
468 else
469 {
470 maximum = PyFloat_AsDouble( a3 );
471 }
472
473 sipRes = sipCpp->hasHistogram( a0, a1, minimum, maximum, *a4, a5, a6 );
474 % End
475#endif
476
477
488 virtual void cumulativeCut( int bandNo,
489 double lowerCount,
490 double upperCount,
491 double &lowerValue,
492 double &upperValue,
493 const QgsRectangle &extent = QgsRectangle(),
494 int sampleSize = 0 );
495
497 virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const { Q_UNUSED( doc ) Q_UNUSED( parentElem ); }
499 virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ) }
500
501 protected:
502 // QgsRasterInterface used as input
503 QgsRasterInterface *mInput = nullptr;
504
506 QList<QgsRasterBandStats> mStatistics;
507
509 QList<QgsRasterHistogram> mHistograms;
510
511 // On/off state, if off, it does not do anything, replicates input
512 bool mOn = true;
513
518#ifndef SIP_RUN
519 void initHistogram( QgsRasterHistogram &histogram,
520 int bandNo,
521 int binCount,
522 double minimum = std::numeric_limits<double>::quiet_NaN(),
523 double maximum = std::numeric_limits<double>::quiet_NaN(),
524 const QgsRectangle &boundingBox = QgsRectangle(),
525 int sampleSize = 0,
526 bool includeOutOfRange = false );
527#else
528 void initHistogram( QgsRasterHistogram &histogram,
529 int bandNo,
530 int binCount,
531 SIP_PYOBJECT minimum = Py_None,
532 SIP_PYOBJECT maximum = Py_None,
533 const QgsRectangle &boundingBox = QgsRectangle(),
534 int sampleSize = 0,
535 bool includeOutOfRange = false )
536 [void ( QgsRasterHistogram & histogram,
537 int bandNo,
538 int binCount,
539 double minimum = 0.0,
540 double maximum = 0.0,
541 const QgsRectangle &boundingBox = QgsRectangle(),
542 int sampleSize = 0,
543 bool includeOutOfRange = false )];
544 % MethodCode
545 double minimum;
546 double maximum;
547 if ( a3 == Py_None )
548 {
549 minimum = std::numeric_limits<double>::quiet_NaN();
550 }
551 else
552 {
553 minimum = PyFloat_AsDouble( a3 );
554 }
555
556 if ( a4 == Py_None )
557 {
558 maximum = std::numeric_limits<double>::quiet_NaN();
559 }
560 else
561 {
562 maximum = PyFloat_AsDouble( a4 );
563 }
564
565#if defined(SIP_PROTECTED_IS_PUBLIC) || (SIP_VERSION >= 0x050000 && !defined(_MSC_VER))
566 sipCpp->initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
567#else
568 sipCpp->sipProtect_initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
569#endif
570 % End
571#endif
572
574 void initStatistics( QgsRasterBandStats &statistics, int bandNo,
575 int stats = QgsRasterBandStats::All,
576 const QgsRectangle &boundingBox = QgsRectangle(),
577 int binCount = 0 ) const;
578
579 private:
580#ifdef SIP_RUN
582 QgsRasterInterface &operator=( const QgsRasterInterface & );
583#endif
584
585 Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
586};
587
588#endif
DataType
Raster data types.
Definition: qgis.h:241
@ 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.
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.
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