QGIS API Documentation 4.1.0-Master (60fea48833c)
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 <limits>
22
23#include "qgis.h"
24#include "qgis_core.h"
25#include "qgis_sip.h"
26#include "qgsfeedback.h"
27#include "qgsrasterbandstats.h"
28#include "qgsrasterblock.h"
29#include "qgsrasterhistogram.h"
30#include "qgsrectangle.h"
31#include "qgsrendercontext.h"
32
33#include <QCoreApplication>
34#include <QImage>
35#include <QString>
36
37using namespace Qt::StringLiterals;
38
44class CORE_EXPORT QgsRasterBlockFeedback : public QgsFeedback
45{
46 Q_OBJECT
47
48 public:
50 QgsRasterBlockFeedback( QObject *parent = nullptr )
51 : QgsFeedback( parent )
52 {}
53
58 virtual void onNewData() {}
59
65 bool isPreviewOnly() const { return mPreviewOnly; }
66
71 void setPreviewOnly( bool preview ) { mPreviewOnly = preview; }
72
77 bool renderPartialOutput() const { return mRenderPartialOutput; }
78
83 void setRenderPartialOutput( bool enable ) { mRenderPartialOutput = enable; }
84
92 void appendError( const QString &error ) { mErrors.append( error ); }
93
100 QStringList errors() const { return mErrors; }
101
108 QgsRenderContext renderContext() const;
109
116 void setRenderContext( const QgsRenderContext &renderContext );
117
118 private:
123 bool mPreviewOnly = false;
124
126 bool mRenderPartialOutput = false;
127
129 QStringList mErrors;
130
131 QgsRenderContext mRenderContext;
132};
133
134
139class CORE_EXPORT QgsRasterInterface
140{
141 // QgsRasterInterface subclasses
142 //SIP_TYPEHEADER_INCLUDE( "qgsbrightnesscontrastfilter.h" );
143 //SIP_TYPEHEADER_INCLUDE( "qgshuesaturationfilter.h" );
144 //SIP_TYPEHEADER_INCLUDE( "qgsrasterdataprovider.h" );
145 //SIP_TYPEHEADER_INCLUDE( "qgsrasternuller.h" );
146 //SIP_TYPEHEADER_INCLUDE( "qgsrasterprojector.h" );
147 //SIP_TYPEHEADER_INCLUDE( "qgsrasterrenderer.h" );
148 //SIP_TYPEHEADER_INCLUDE( "qgsrasterresamplefilter.h" );
149 // QgsRasterRenderer subclasses
150 //SIP_TYPEHEADER_INCLUDE( "qgshillshaderenderer.h" );
151 //SIP_TYPEHEADER_INCLUDE( "qgsmultibandcolorrenderer.h" );
152 //SIP_TYPEHEADER_INCLUDE( "qgspalettedrasterrenderer.h" );
153 //SIP_TYPEHEADER_INCLUDE( "qgssinglebandcolordatarenderer.h" );
154 //SIP_TYPEHEADER_INCLUDE( "qgssinglebandgrayrenderer.h" );
155 //SIP_TYPEHEADER_INCLUDE( "qgssinglebandpseudocolorrenderer.h" );
156 //SIP_TYPEHEADER_INCLUDE( "qgsrastersinglecolorrenderer.h" );
157 //SIP_TYPEHEADER_INCLUDE( "qgsrastercontourrenderer.h" );
158
159
160#ifdef SIP_RUN
162 if ( dynamic_cast<QgsBrightnessContrastFilter *>( sipCpp ) )
163 sipType = sipType_QgsBrightnessContrastFilter;
164 else if ( dynamic_cast<QgsHueSaturationFilter *>( sipCpp ) )
165 sipType = sipType_QgsHueSaturationFilter;
166 else if ( dynamic_cast<QgsRasterDataProvider *>( sipCpp ) )
167 {
168 sipType = sipType_QgsRasterDataProvider;
169 // use static cast because QgsRasterDataProvider has multiple inheritance
170 // and we would end up with bad pointer otherwise!
171 *sipCppRet = static_cast<QgsRasterDataProvider *>( sipCpp );
172 }
173 else if ( dynamic_cast<QgsRasterNuller *>( sipCpp ) )
174 sipType = sipType_QgsRasterNuller;
175 else if ( dynamic_cast<QgsRasterProjector *>( sipCpp ) )
176 sipType = sipType_QgsRasterProjector;
177 else if ( dynamic_cast<QgsRasterRenderer *>( sipCpp ) )
178 {
179 if ( dynamic_cast<QgsHillshadeRenderer *>( sipCpp ) )
180 sipType = sipType_QgsHillshadeRenderer;
181 else if ( dynamic_cast<QgsMultiBandColorRenderer *>( sipCpp ) )
182 sipType = sipType_QgsMultiBandColorRenderer;
183 else if ( dynamic_cast<QgsPalettedRasterRenderer *>( sipCpp ) )
184 sipType = sipType_QgsPalettedRasterRenderer;
185 else if ( dynamic_cast<QgsSingleBandColorDataRenderer *>( sipCpp ) )
186 sipType = sipType_QgsSingleBandColorDataRenderer;
187 else if ( dynamic_cast<QgsSingleBandGrayRenderer *>( sipCpp ) )
188 sipType = sipType_QgsSingleBandGrayRenderer;
189 else if ( dynamic_cast<QgsSingleBandPseudoColorRenderer *>( sipCpp ) )
190 sipType = sipType_QgsSingleBandPseudoColorRenderer;
191 else if ( dynamic_cast<QgsRasterSingleColorRenderer *>( sipCpp ) )
192 sipType = sipType_QgsRasterSingleColorRenderer;
193 else if ( dynamic_cast<QgsRasterContourRenderer *>( sipCpp ) )
194 sipType = sipType_QgsRasterContourRenderer;
195 else
196 sipType = sipType_QgsRasterRenderer;
197 }
198 else if ( dynamic_cast<QgsRasterResampleFilter *>( sipCpp ) )
199 sipType = sipType_QgsRasterResampleFilter;
200 else
201 sipType = 0;
202 SIP_END
203#endif
204
205 // clang-format off
206 Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface )
207
208 public:
209 // clang-format on
210
212
213 virtual ~QgsRasterInterface() = default;
214
217
218 // TODO QGIS 5.0 -- rename to interfaceCapabilities, to avoid confusion with QgsRasterDataProvider::providerCapabilities
219 // (which inherits this class)
220
225
231 Q_DECL_DEPRECATED QString capabilitiesString() const SIP_DEPRECATED;
232
234 virtual Qgis::DataType dataType( int bandNo ) const = 0;
235
240 virtual Qgis::DataType sourceDataType( int bandNo ) const { return mInput ? mInput->sourceDataType( bandNo ) : Qgis::DataType::UnknownDataType; }
241
246 virtual QgsRectangle extent() const { return mInput ? mInput->extent() : QgsRectangle(); }
247
251 int dataTypeSize( int bandNo ) const { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
252
254 virtual int bandCount() const = 0;
255
257 virtual int xBlockSize() const { return mInput ? mInput->xBlockSize() : 0; }
258 virtual int yBlockSize() const { return mInput ? mInput->yBlockSize() : 0; }
259
261 virtual int xSize() const { return mInput ? mInput->xSize() : 0; }
262 virtual int ySize() const { return mInput ? mInput->ySize() : 0; }
263
265 virtual QString generateBandName( int bandNumber ) const;
266
273 virtual QString colorInterpretationName( int bandNumber ) const;
274
280 QString displayBandName( int bandNumber ) const;
281
292 virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) = 0 SIP_FACTORY;
293
299 {
300 mInput = input;
301 return true;
302 }
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( u"Entered"_s, 4 );
322 return mInput ? mInput->sourceInput() : this;
323 }
324
331 {
332 QgsDebugMsgLevel( u"Entered"_s, 4 );
333 return mInput ? mInput->sourceInput() : this;
334 }
335
336 // clang-format off
346 Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) SIP_DEPRECATED;
347 // clang-format on
348
357 virtual QgsRasterBandStats bandStatistics(
358 int bandNo, Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr
359 );
360
367 Q_DECL_DEPRECATED bool hasStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 ) SIP_DEPRECATED;
368
374 virtual bool hasStatistics( int bandNo, Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 );
375
376
377 // clang-format off
391#ifndef SIP_RUN
392 virtual QgsRasterHistogram histogram( int bandNo,
393 int binCount = 0,
394 double minimum = std::numeric_limits<double>::quiet_NaN(),
395 double maximum = std::numeric_limits<double>::quiet_NaN(),
396 const QgsRectangle &extent = QgsRectangle(),
397 int sampleSize = 0,
398 bool includeOutOfRange = false,
399 QgsRasterBlockFeedback *feedback = nullptr );
400#else
401// clang-format off
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// clang-format on
443#endif
444 // clang-format on
445
446
447 // clang-format off
452#ifndef SIP_RUN
453 virtual bool hasHistogram( int bandNo,
454 int binCount,
455 double minimum = std::numeric_limits<double>::quiet_NaN(),
456 double maximum = std::numeric_limits<double>::quiet_NaN(),
457 const QgsRectangle &extent = QgsRectangle(),
458 int sampleSize = 0,
459 bool includeOutOfRange = false );
460#else
461// clang-format off
462 virtual bool hasHistogram( int bandNo,
463 int binCount,
464 SIP_PYOBJECT minimum = Py_None,
465 SIP_PYOBJECT maximum = Py_None,
466 const QgsRectangle &extent = QgsRectangle(),
467 int sampleSize = 0,
468 bool includeOutOfRange = false )
469 [bool( int bandNo,
470 int binCount,
471 double minimum = 0.0,
472 double maximum = 0.0,
473 const QgsRectangle &extent = QgsRectangle(),
474 int sampleSize = 0,
475 bool includeOutOfRange = false )];
476 % MethodCode
477 double minimum;
478 double maximum;
479 if ( a2 == Py_None )
480 {
481 minimum = std::numeric_limits<double>::quiet_NaN();
482 }
483 else
484 {
485 minimum = PyFloat_AsDouble( a2 );
486 }
487
488 if ( a3 == Py_None )
489 {
490 maximum = std::numeric_limits<double>::quiet_NaN();
491 }
492 else
493 {
494 maximum = PyFloat_AsDouble( a3 );
495 }
496
497 sipRes = sipCpp->hasHistogram( a0, a1, minimum, maximum, *a4, a5, a6 );
498 % End
499// clang-format on
500#endif
501 // clang-format on
502
503
514 virtual void cumulativeCut( int bandNo, double lowerCount, double upperCount, double &lowerValue, double &upperValue, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 );
515
517 virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const
518 {
519 Q_UNUSED( doc )
520 Q_UNUSED( parentElem );
521 }
522
523 virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ) }
524
525 protected:
526 // QgsRasterInterface used as input
528
530 QList<QgsRasterBandStats> mStatistics;
531
533 QList<QgsRasterHistogram> mHistograms;
534
535 // On/off state, if off, it does not do anything, replicates input
536 bool mOn = true;
537
538 // clang-format off
543#ifndef SIP_RUN
545 int bandNo,
546 int binCount,
547 double minimum = std::numeric_limits<double>::quiet_NaN(),
548 double maximum = std::numeric_limits<double>::quiet_NaN(),
549 const QgsRectangle &boundingBox = QgsRectangle(),
550 int sampleSize = 0,
551 bool includeOutOfRange = false );
552#else
553// clang-format off
555 int bandNo,
556 int binCount,
557 SIP_PYOBJECT minimum = Py_None,
558 SIP_PYOBJECT maximum = Py_None,
559 const QgsRectangle &boundingBox = QgsRectangle(),
560 int sampleSize = 0,
561 bool includeOutOfRange = false )
563 int bandNo,
564 int binCount,
565 double minimum = 0.0,
566 double maximum = 0.0,
567 const QgsRectangle &boundingBox = QgsRectangle(),
568 int sampleSize = 0,
569 bool includeOutOfRange = false )];
570 % MethodCode
571 double minimum;
572 double maximum;
573 if ( a3 == Py_None )
574 {
575 minimum = std::numeric_limits<double>::quiet_NaN();
576 }
577 else
578 {
579 minimum = PyFloat_AsDouble( a3 );
580 }
581
582 if ( a4 == Py_None )
583 {
584 maximum = std::numeric_limits<double>::quiet_NaN();
585 }
586 else
587 {
588 maximum = PyFloat_AsDouble( a4 );
589 }
590
591#if defined(SIP_PROTECTED_IS_PUBLIC) || (SIP_VERSION >= 0x050000 && !defined(_MSC_VER))
592 sipCpp->initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
593#else
594 sipCpp->sipProtect_initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
595#endif
596 % End
597// clang-format on
598#endif
599 // clang-format on
600
605 Q_DECL_DEPRECATED void initStatistics( QgsRasterBandStats &statistics, int bandNo, int stats, const QgsRectangle &boundingBox = QgsRectangle(), int binCount = 0 ) const SIP_DEPRECATED;
606
608 void initStatistics(
609 QgsRasterBandStats &statistics, int bandNo, Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All, const QgsRectangle &boundingBox = QgsRectangle(), int binCount = 0
610 ) const;
611
612 private:
613#ifdef SIP_RUN
614 QgsRasterInterface( const QgsRasterInterface & );
615 QgsRasterInterface &operator=( const QgsRasterInterface & );
616#endif
617
618 Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
619};
620
621#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
QFlags< RasterInterfaceCapability > RasterInterfaceCapabilities
Raster interface capabilities.
Definition qgis.h:5030
@ UnknownDataType
Unknown or unspecified type.
Definition qgis.h:394
Brightness/contrast and gamma correction filter pipe for rasters.
QgsFeedback(QObject *parent=nullptr)
Construct a feedback object.
Definition qgsfeedback.h:48
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.
A container for a histogram of a single raster band.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
virtual Qgis::RasterInterfaceCapabilities capabilities() const
Returns the capabilities supported by the interface.
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.
Q_DECL_DEPRECATED QString capabilitiesString() const
Returns the raster interface capabilities in friendly format.
void initHistogram(QgsRasterHistogram &histogram, int bandNo, int binCount, double minimum=std::numeric_limits< double >::quiet_NaN(), double maximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &boundingBox=QgsRectangle(), int sampleSize=0, bool includeOutOfRange=false)
Fill in histogram defaults if not specified.
virtual int xSize() const
Gets raster size.
virtual void setOn(bool on)
Sets whether the interface is on or off.
QgsRasterInterface(QgsRasterInterface *input=nullptr)
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.
QgsRasterInterface * mInput
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 QgsRasterHistogram histogram(int bandNo, int binCount=0, double minimum=std::numeric_limits< double >::quiet_NaN(), double maximum=std::numeric_limits< double >::quiet_NaN(), const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, bool includeOutOfRange=false, QgsRasterBlockFeedback *feedback=nullptr)
Returns a band histogram.
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:198
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63