QGIS API Documentation 4.3.0-Master (e0370aa57ef)
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 //SIP_TYPEHEADER_INCLUDE( "qgsrastervectorfieldrenderer.h" );
159
160
161#ifdef SIP_RUN
163 if ( dynamic_cast<QgsBrightnessContrastFilter *>( sipCpp ) )
164 sipType = sipType_QgsBrightnessContrastFilter;
165 else if ( dynamic_cast<QgsHueSaturationFilter *>( sipCpp ) )
166 sipType = sipType_QgsHueSaturationFilter;
167 else if ( dynamic_cast<QgsRasterDataProvider *>( sipCpp ) )
168 {
169 sipType = sipType_QgsRasterDataProvider;
170 // use static cast because QgsRasterDataProvider has multiple inheritance
171 // and we would end up with bad pointer otherwise!
172 *sipCppRet = static_cast<QgsRasterDataProvider *>( sipCpp );
173 }
174 else if ( dynamic_cast<QgsRasterNuller *>( sipCpp ) )
175 sipType = sipType_QgsRasterNuller;
176 else if ( dynamic_cast<QgsRasterProjector *>( sipCpp ) )
177 sipType = sipType_QgsRasterProjector;
178 else if ( dynamic_cast<QgsRasterRenderer *>( sipCpp ) )
179 {
180 if ( dynamic_cast<QgsHillshadeRenderer *>( sipCpp ) )
181 sipType = sipType_QgsHillshadeRenderer;
182 else if ( dynamic_cast<QgsMultiBandColorRenderer *>( sipCpp ) )
183 sipType = sipType_QgsMultiBandColorRenderer;
184 else if ( dynamic_cast<QgsPalettedRasterRenderer *>( sipCpp ) )
185 sipType = sipType_QgsPalettedRasterRenderer;
186 else if ( dynamic_cast<QgsSingleBandColorDataRenderer *>( sipCpp ) )
187 sipType = sipType_QgsSingleBandColorDataRenderer;
188 else if ( dynamic_cast<QgsSingleBandGrayRenderer *>( sipCpp ) )
189 sipType = sipType_QgsSingleBandGrayRenderer;
190 else if ( dynamic_cast<QgsSingleBandPseudoColorRenderer *>( sipCpp ) )
191 sipType = sipType_QgsSingleBandPseudoColorRenderer;
192 else if ( dynamic_cast<QgsRasterSingleColorRenderer *>( sipCpp ) )
193 sipType = sipType_QgsRasterSingleColorRenderer;
194 else if ( dynamic_cast<QgsRasterContourRenderer *>( sipCpp ) )
195 sipType = sipType_QgsRasterContourRenderer;
196 else if ( dynamic_cast<QgsRasterVectorFieldRenderer *>( sipCpp ) )
197 sipType = sipType_QgsRasterVectorFieldRenderer;
198 else
199 sipType = sipType_QgsRasterRenderer;
200 }
201 else if ( dynamic_cast<QgsRasterResampleFilter *>( sipCpp ) )
202 sipType = sipType_QgsRasterResampleFilter;
203 else
204 sipType = 0;
205 SIP_END
206#endif
207
208 // clang-format off
209 Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface )
210
211 public:
212 // clang-format on
213
215
216 virtual ~QgsRasterInterface() = default;
217
220
221 // TODO QGIS 5.0 -- rename to interfaceCapabilities, to avoid confusion with QgsRasterDataProvider::providerCapabilities
222 // (which inherits this class)
223
228
234 Q_DECL_DEPRECATED QString capabilitiesString() const SIP_DEPRECATED;
235
237 virtual Qgis::DataType dataType( int bandNo ) const = 0;
238
243 virtual Qgis::DataType sourceDataType( int bandNo ) const { return mInput ? mInput->sourceDataType( bandNo ) : Qgis::DataType::UnknownDataType; }
244
249 virtual QgsRectangle extent() const { return mInput ? mInput->extent() : QgsRectangle(); }
250
254 int dataTypeSize( int bandNo ) const { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
255
257 virtual int bandCount() const = 0;
258
260 virtual int xBlockSize() const { return mInput ? mInput->xBlockSize() : 0; }
261 virtual int yBlockSize() const { return mInput ? mInput->yBlockSize() : 0; }
262
264 virtual int xSize() const { return mInput ? mInput->xSize() : 0; }
265 virtual int ySize() const { return mInput ? mInput->ySize() : 0; }
266
268 virtual QString generateBandName( int bandNumber ) const;
269
276 virtual QString colorInterpretationName( int bandNumber ) const;
277
283 QString displayBandName( int bandNumber ) const;
284
295 virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) = 0 SIP_FACTORY;
296
302 {
303 mInput = input;
304 return true;
305 }
306
308 virtual QgsRasterInterface *input() const { return mInput; }
309
311 virtual bool on() const { return mOn; }
312
314 virtual void setOn( bool on ) { mOn = on; }
315
323 {
324 QgsDebugMsgLevel( u"Entered"_s, 4 );
325 return mInput ? mInput->sourceInput() : this;
326 }
327
334 {
335 QgsDebugMsgLevel( u"Entered"_s, 4 );
336 return mInput ? mInput->sourceInput() : this;
337 }
338
339 // clang-format off
349 Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) SIP_DEPRECATED;
350 // clang-format on
351
360 virtual QgsRasterBandStats bandStatistics(
361 int bandNo, Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr
362 );
363
370 Q_DECL_DEPRECATED bool hasStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 ) SIP_DEPRECATED;
371
377 virtual bool hasStatistics( int bandNo, Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 );
378
379
380 // clang-format off
394#ifndef SIP_RUN
395 virtual QgsRasterHistogram histogram( int bandNo,
396 int binCount = 0,
397 double minimum = std::numeric_limits<double>::quiet_NaN(),
398 double maximum = std::numeric_limits<double>::quiet_NaN(),
399 const QgsRectangle &extent = QgsRectangle(),
400 int sampleSize = 0,
401 bool includeOutOfRange = false,
402 QgsRasterBlockFeedback *feedback = nullptr );
403#else
404// clang-format off
405 virtual QgsRasterHistogram histogram( int bandNo,
406 int binCount = 0,
407 SIP_PYOBJECT minimum = Py_None,
408 SIP_PYOBJECT maximum = Py_None,
409 const QgsRectangle &extent = QgsRectangle(),
410 int sampleSize = 0,
411 bool includeOutOfRange = false,
412 QgsRasterBlockFeedback *feedback = nullptr )
413 [QgsRasterHistogram( int bandNo,
414 int binCount = 0,
415 double minimum = 0.0,
416 double maximum = 0.0,
417 const QgsRectangle &extent = QgsRectangle(),
418 int sampleSize = 0,
419 bool includeOutOfRange = false,
420 QgsRasterBlockFeedback *feedback = nullptr )];
421 % MethodCode
422 double minimum;
423 double maximum;
424 if ( a2 == Py_None )
425 {
426 minimum = std::numeric_limits<double>::quiet_NaN();
427 }
428 else
429 {
430 minimum = PyFloat_AsDouble( a2 );
431 }
432
433 if ( a3 == Py_None )
434 {
435 maximum = std::numeric_limits<double>::quiet_NaN();
436 }
437 else
438 {
439 maximum = PyFloat_AsDouble( a3 );
440 }
441
442 QgsRasterHistogram *h = new QgsRasterHistogram( sipCpp->histogram( a0, a1, minimum, maximum, *a4, a5, a6, a7 ) );
443 return sipConvertFromType( h, sipType_QgsRasterHistogram, Py_None );
444 % End
445// clang-format on
446#endif
447 // clang-format on
448
449
450 // clang-format off
455#ifndef SIP_RUN
456 virtual bool hasHistogram( int bandNo,
457 int binCount,
458 double minimum = std::numeric_limits<double>::quiet_NaN(),
459 double maximum = std::numeric_limits<double>::quiet_NaN(),
460 const QgsRectangle &extent = QgsRectangle(),
461 int sampleSize = 0,
462 bool includeOutOfRange = false );
463#else
464// clang-format off
465 virtual bool hasHistogram( int bandNo,
466 int binCount,
467 SIP_PYOBJECT minimum = Py_None,
468 SIP_PYOBJECT maximum = Py_None,
469 const QgsRectangle &extent = QgsRectangle(),
470 int sampleSize = 0,
471 bool includeOutOfRange = false )
472 [bool( int bandNo,
473 int binCount,
474 double minimum = 0.0,
475 double maximum = 0.0,
476 const QgsRectangle &extent = QgsRectangle(),
477 int sampleSize = 0,
478 bool includeOutOfRange = false )];
479 % MethodCode
480 double minimum;
481 double maximum;
482 if ( a2 == Py_None )
483 {
484 minimum = std::numeric_limits<double>::quiet_NaN();
485 }
486 else
487 {
488 minimum = PyFloat_AsDouble( a2 );
489 }
490
491 if ( a3 == Py_None )
492 {
493 maximum = std::numeric_limits<double>::quiet_NaN();
494 }
495 else
496 {
497 maximum = PyFloat_AsDouble( a3 );
498 }
499
500 sipRes = sipCpp->hasHistogram( a0, a1, minimum, maximum, *a4, a5, a6 );
501 % End
502// clang-format on
503#endif
504 // clang-format on
505
506
517 virtual void cumulativeCut( int bandNo, double lowerCount, double upperCount, double &lowerValue, double &upperValue, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 );
518
520 virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const
521 {
522 Q_UNUSED( doc )
523 Q_UNUSED( parentElem );
524 }
525
526 virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ) }
527
528 protected:
529 // QgsRasterInterface used as input
531
533 QList<QgsRasterBandStats> mStatistics;
534
536 QList<QgsRasterHistogram> mHistograms;
537
538 // On/off state, if off, it does not do anything, replicates input
539 bool mOn = true;
540
541 // clang-format off
546#ifndef SIP_RUN
548 int bandNo,
549 int binCount,
550 double minimum = std::numeric_limits<double>::quiet_NaN(),
551 double maximum = std::numeric_limits<double>::quiet_NaN(),
552 const QgsRectangle &boundingBox = QgsRectangle(),
553 int sampleSize = 0,
554 bool includeOutOfRange = false );
555#else
556// clang-format off
558 int bandNo,
559 int binCount,
560 SIP_PYOBJECT minimum = Py_None,
561 SIP_PYOBJECT maximum = Py_None,
562 const QgsRectangle &boundingBox = QgsRectangle(),
563 int sampleSize = 0,
564 bool includeOutOfRange = false )
566 int bandNo,
567 int binCount,
568 double minimum = 0.0,
569 double maximum = 0.0,
570 const QgsRectangle &boundingBox = QgsRectangle(),
571 int sampleSize = 0,
572 bool includeOutOfRange = false )];
573 % MethodCode
574 double minimum;
575 double maximum;
576 if ( a3 == Py_None )
577 {
578 minimum = std::numeric_limits<double>::quiet_NaN();
579 }
580 else
581 {
582 minimum = PyFloat_AsDouble( a3 );
583 }
584
585 if ( a4 == Py_None )
586 {
587 maximum = std::numeric_limits<double>::quiet_NaN();
588 }
589 else
590 {
591 maximum = PyFloat_AsDouble( a4 );
592 }
593
594#if defined(SIP_PROTECTED_IS_PUBLIC) || !defined(_MSC_VER)
595 sipCpp->initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
596#else
597 sipCpp->sipProtect_initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
598#endif
599 % End
600// clang-format on
601#endif
602 // clang-format on
603
608 Q_DECL_DEPRECATED void initStatistics( QgsRasterBandStats &statistics, int bandNo, int stats, const QgsRectangle &boundingBox = QgsRectangle(), int binCount = 0 ) const SIP_DEPRECATED;
609
611 void initStatistics(
612 QgsRasterBandStats &statistics, int bandNo, Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All, const QgsRectangle &boundingBox = QgsRectangle(), int binCount = 0
613 ) const;
614
615 private:
616#ifdef SIP_RUN
617 QgsRasterInterface( const QgsRasterInterface & );
618 QgsRasterInterface &operator=( const QgsRasterInterface & );
619#endif
620
621 Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
622};
623
624#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
QFlags< RasterInterfaceCapability > RasterInterfaceCapabilities
Raster interface capabilities.
Definition qgis.h:5440
@ UnknownDataType
Unknown or unspecified type.
Definition qgis.h:414
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.
Raster renderer which draws a vector field stored in raster bands.
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:203
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:220
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:80