QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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#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
345 Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) SIP_DEPRECATED;
346
355 virtual QgsRasterBandStats bandStatistics( int bandNo,
356 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
357 const QgsRectangle &extent = QgsRectangle(),
358 int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr );
359
366 Q_DECL_DEPRECATED bool hasStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 ) SIP_DEPRECATED;
367
373 virtual bool hasStatistics( int bandNo,
374 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
375 const QgsRectangle &extent = QgsRectangle(),
376 int sampleSize = 0 );
377
378
392#ifndef SIP_RUN
393 virtual QgsRasterHistogram histogram( int bandNo,
394 int binCount = 0,
395 double minimum = std::numeric_limits<double>::quiet_NaN(),
396 double maximum = std::numeric_limits<double>::quiet_NaN(),
397 const QgsRectangle &extent = QgsRectangle(),
398 int sampleSize = 0,
399 bool includeOutOfRange = false,
400 QgsRasterBlockFeedback *feedback = nullptr );
401#else
402 virtual QgsRasterHistogram histogram( int bandNo,
403 int binCount = 0,
404 SIP_PYOBJECT minimum = Py_None,
405 SIP_PYOBJECT maximum = Py_None,
406 const QgsRectangle &extent = QgsRectangle(),
407 int sampleSize = 0,
408 bool includeOutOfRange = false,
409 QgsRasterBlockFeedback *feedback = nullptr )
410 [QgsRasterHistogram( int bandNo,
411 int binCount = 0,
412 double minimum = 0.0,
413 double maximum = 0.0,
414 const QgsRectangle &extent = QgsRectangle(),
415 int sampleSize = 0,
416 bool includeOutOfRange = false,
417 QgsRasterBlockFeedback *feedback = nullptr )];
418 % MethodCode
419 double minimum;
420 double maximum;
421 if ( a2 == Py_None )
422 {
423 minimum = std::numeric_limits<double>::quiet_NaN();
424 }
425 else
426 {
427 minimum = PyFloat_AsDouble( a2 );
428 }
429
430 if ( a3 == Py_None )
431 {
432 maximum = std::numeric_limits<double>::quiet_NaN();
433 }
434 else
435 {
436 maximum = PyFloat_AsDouble( a3 );
437 }
438
439 QgsRasterHistogram *h = new QgsRasterHistogram( sipCpp->histogram( a0, a1, minimum, maximum, *a4, a5, a6, a7 ) );
440 return sipConvertFromType( h, sipType_QgsRasterHistogram, Py_None );
441 % End
442#endif
443
444
449#ifndef SIP_RUN
450 virtual bool hasHistogram( int bandNo,
451 int binCount,
452 double minimum = std::numeric_limits<double>::quiet_NaN(),
453 double maximum = std::numeric_limits<double>::quiet_NaN(),
454 const QgsRectangle &extent = QgsRectangle(),
455 int sampleSize = 0,
456 bool includeOutOfRange = false );
457#else
458 virtual bool hasHistogram( int bandNo,
459 int binCount,
460 SIP_PYOBJECT minimum = Py_None,
461 SIP_PYOBJECT maximum = Py_None,
462 const QgsRectangle &extent = QgsRectangle(),
463 int sampleSize = 0,
464 bool includeOutOfRange = false )
465 [bool( int bandNo,
466 int binCount,
467 double minimum = 0.0,
468 double maximum = 0.0,
469 const QgsRectangle &extent = QgsRectangle(),
470 int sampleSize = 0,
471 bool includeOutOfRange = false )];
472 % MethodCode
473 double minimum;
474 double maximum;
475 if ( a2 == Py_None )
476 {
477 minimum = std::numeric_limits<double>::quiet_NaN();
478 }
479 else
480 {
481 minimum = PyFloat_AsDouble( a2 );
482 }
483
484 if ( a3 == Py_None )
485 {
486 maximum = std::numeric_limits<double>::quiet_NaN();
487 }
488 else
489 {
490 maximum = PyFloat_AsDouble( a3 );
491 }
492
493 sipRes = sipCpp->hasHistogram( a0, a1, minimum, maximum, *a4, a5, a6 );
494 % End
495#endif
496
497
508 virtual void cumulativeCut( int bandNo,
509 double lowerCount,
510 double upperCount,
511 double &lowerValue,
512 double &upperValue,
513 const QgsRectangle &extent = QgsRectangle(),
514 int sampleSize = 0 );
515
517 virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const { Q_UNUSED( doc ) Q_UNUSED( parentElem ); }
519 virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ) }
520
521 protected:
522 // QgsRasterInterface used as input
523 QgsRasterInterface *mInput = nullptr;
524
526 QList<QgsRasterBandStats> mStatistics;
527
529 QList<QgsRasterHistogram> mHistograms;
530
531 // On/off state, if off, it does not do anything, replicates input
532 bool mOn = true;
533
538#ifndef SIP_RUN
539 void initHistogram( QgsRasterHistogram &histogram,
540 int bandNo,
541 int binCount,
542 double minimum = std::numeric_limits<double>::quiet_NaN(),
543 double maximum = std::numeric_limits<double>::quiet_NaN(),
544 const QgsRectangle &boundingBox = QgsRectangle(),
545 int sampleSize = 0,
546 bool includeOutOfRange = false );
547#else
548 void initHistogram( QgsRasterHistogram &histogram,
549 int bandNo,
550 int binCount,
551 SIP_PYOBJECT minimum = Py_None,
552 SIP_PYOBJECT maximum = Py_None,
553 const QgsRectangle &boundingBox = QgsRectangle(),
554 int sampleSize = 0,
555 bool includeOutOfRange = false )
556 [void ( QgsRasterHistogram & histogram,
557 int bandNo,
558 int binCount,
559 double minimum = 0.0,
560 double maximum = 0.0,
561 const QgsRectangle &boundingBox = QgsRectangle(),
562 int sampleSize = 0,
563 bool includeOutOfRange = false )];
564 % MethodCode
565 double minimum;
566 double maximum;
567 if ( a3 == Py_None )
568 {
569 minimum = std::numeric_limits<double>::quiet_NaN();
570 }
571 else
572 {
573 minimum = PyFloat_AsDouble( a3 );
574 }
575
576 if ( a4 == Py_None )
577 {
578 maximum = std::numeric_limits<double>::quiet_NaN();
579 }
580 else
581 {
582 maximum = PyFloat_AsDouble( a4 );
583 }
584
585#if defined(SIP_PROTECTED_IS_PUBLIC) || (SIP_VERSION >= 0x050000 && !defined(_MSC_VER))
586 sipCpp->initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
587#else
588 sipCpp->sipProtect_initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
589#endif
590 % End
591#endif
592
597 Q_DECL_DEPRECATED void initStatistics( QgsRasterBandStats &statistics, int bandNo, int stats, const QgsRectangle &boundingBox = QgsRectangle(), int binCount = 0 ) const SIP_DEPRECATED;
598
600 void initStatistics( QgsRasterBandStats &statistics, int bandNo,
601 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
602 const QgsRectangle &boundingBox = QgsRectangle(),
603 int binCount = 0 ) const;
604
605 private:
606#ifdef SIP_RUN
608 QgsRasterInterface &operator=( const QgsRasterInterface & );
609#endif
610
611 Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
612};
613
614#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
DataType
Raster data types.
Definition qgis.h:269
@ 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.
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.
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_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#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