QGIS API Documentation 3.38.0-Grenoble (exported)
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>
156#endif
157
158
159#ifdef SIP_RUN
161 if ( dynamic_cast<QgsBrightnessContrastFilter *>( sipCpp ) )
162 sipType = sipType_QgsBrightnessContrastFilter;
163 else if ( dynamic_cast<QgsHueSaturationFilter *>( sipCpp ) )
164 sipType = sipType_QgsHueSaturationFilter;
165 else if ( dynamic_cast<QgsRasterDataProvider *>( sipCpp ) )
166 {
167 sipType = sipType_QgsRasterDataProvider;
168 // use static cast because QgsRasterDataProvider has multiple inheritance
169 // and we would end up with bad pointer otherwise!
170 *sipCppRet = static_cast<QgsRasterDataProvider *>( sipCpp );
171 }
172 else if ( dynamic_cast<QgsRasterNuller *>( sipCpp ) )
173 sipType = sipType_QgsRasterNuller;
174 else if ( dynamic_cast<QgsRasterProjector *>( sipCpp ) )
175 sipType = sipType_QgsRasterProjector;
176 else if ( dynamic_cast<QgsRasterRenderer *>( sipCpp ) )
177 {
178 if ( dynamic_cast<QgsHillshadeRenderer *>( sipCpp ) )
179 sipType = sipType_QgsHillshadeRenderer;
180 else if ( dynamic_cast<QgsMultiBandColorRenderer *>( sipCpp ) )
181 sipType = sipType_QgsMultiBandColorRenderer;
182 else if ( dynamic_cast<QgsPalettedRasterRenderer *>( sipCpp ) )
183 sipType = sipType_QgsPalettedRasterRenderer;
184 else if ( dynamic_cast<QgsSingleBandColorDataRenderer *>( sipCpp ) )
185 sipType = sipType_QgsSingleBandColorDataRenderer;
186 else if ( dynamic_cast<QgsSingleBandGrayRenderer *>( sipCpp ) )
187 sipType = sipType_QgsSingleBandGrayRenderer;
188 else if ( dynamic_cast<QgsSingleBandPseudoColorRenderer *>( sipCpp ) )
189 sipType = sipType_QgsSingleBandPseudoColorRenderer;
190 else if ( dynamic_cast<QgsRasterSingleColorRenderer *>( sipCpp ) )
191 sipType = sipType_QgsRasterSingleColorRenderer;
192 else if ( dynamic_cast<QgsRasterContourRenderer *>( sipCpp ) )
193 sipType = sipType_QgsRasterContourRenderer;
194 else
195 sipType = sipType_QgsRasterRenderer;
196 }
197 else if ( dynamic_cast<QgsRasterResampleFilter *>( sipCpp ) )
198 sipType = sipType_QgsRasterResampleFilter;
199 else
200 sipType = 0;
201 SIP_END
202#endif
203
204 Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface )
205
206 public:
207
208 QgsRasterInterface( QgsRasterInterface *input = nullptr );
209
210 virtual ~QgsRasterInterface() = default;
211
214
215 // TODO QGIS 4.0 -- rename to interfaceCapabilities, to avoid confusion with QgsRasterDataProvider::providerCapabilities
216 // (which inherits this class)
217
221 virtual Qgis::RasterInterfaceCapabilities capabilities() const;
222
228 Q_DECL_DEPRECATED QString capabilitiesString() const SIP_DEPRECATED;
229
231 virtual Qgis::DataType dataType( int bandNo ) const = 0;
232
237 virtual Qgis::DataType sourceDataType( int bandNo ) const { return mInput ? mInput->sourceDataType( bandNo ) : Qgis::DataType::UnknownDataType; }
238
243 virtual QgsRectangle extent() const { return mInput ? mInput->extent() : QgsRectangle(); }
244
248 int dataTypeSize( int bandNo ) const { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
249
251 virtual int bandCount() const = 0;
252
254 virtual int xBlockSize() const { return mInput ? mInput->xBlockSize() : 0; }
255 virtual int yBlockSize() const { return mInput ? mInput->yBlockSize() : 0; }
256
258 virtual int xSize() const { return mInput ? mInput->xSize() : 0; }
259 virtual int ySize() const { return mInput ? mInput->ySize() : 0; }
260
262 virtual QString generateBandName( int bandNumber ) const;
263
269 virtual QString colorInterpretationName( int bandNumber ) const;
270
276 QString displayBandName( int bandNumber ) const;
277
288 virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) = 0 SIP_FACTORY;
289
294 virtual bool setInput( QgsRasterInterface *input ) { mInput = input; return true; }
295
297 virtual QgsRasterInterface *input() const { return mInput; }
298
300 virtual bool on() const { return mOn; }
301
303 virtual void setOn( bool on ) { mOn = on; }
304
312 {
313 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
314 return mInput ? mInput->sourceInput() : this;
315 }
316
323 {
324 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
325 return mInput ? mInput->sourceInput() : this;
326 }
327
337 Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) SIP_DEPRECATED;
338
347 virtual QgsRasterBandStats bandStatistics( int bandNo,
348 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
349 const QgsRectangle &extent = QgsRectangle(),
350 int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr );
351
358 Q_DECL_DEPRECATED bool hasStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 ) SIP_DEPRECATED;
359
365 virtual bool hasStatistics( int bandNo,
366 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
367 const QgsRectangle &extent = QgsRectangle(),
368 int sampleSize = 0 );
369
370
384#ifndef SIP_RUN
385 virtual QgsRasterHistogram histogram( int bandNo,
386 int binCount = 0,
387 double minimum = std::numeric_limits<double>::quiet_NaN(),
388 double maximum = std::numeric_limits<double>::quiet_NaN(),
389 const QgsRectangle &extent = QgsRectangle(),
390 int sampleSize = 0,
391 bool includeOutOfRange = false,
392 QgsRasterBlockFeedback *feedback = nullptr );
393#else
394 virtual QgsRasterHistogram histogram( int bandNo,
395 int binCount = 0,
396 SIP_PYOBJECT minimum = Py_None,
397 SIP_PYOBJECT maximum = Py_None,
398 const QgsRectangle &extent = QgsRectangle(),
399 int sampleSize = 0,
400 bool includeOutOfRange = false,
401 QgsRasterBlockFeedback *feedback = nullptr )
402 [QgsRasterHistogram( int bandNo,
403 int binCount = 0,
404 double minimum = 0.0,
405 double maximum = 0.0,
406 const QgsRectangle &extent = QgsRectangle(),
407 int sampleSize = 0,
408 bool includeOutOfRange = false,
409 QgsRasterBlockFeedback *feedback = nullptr )];
410 % MethodCode
411 double minimum;
412 double maximum;
413 if ( a2 == Py_None )
414 {
415 minimum = std::numeric_limits<double>::quiet_NaN();
416 }
417 else
418 {
419 minimum = PyFloat_AsDouble( a2 );
420 }
421
422 if ( a3 == Py_None )
423 {
424 maximum = std::numeric_limits<double>::quiet_NaN();
425 }
426 else
427 {
428 maximum = PyFloat_AsDouble( a3 );
429 }
430
431 QgsRasterHistogram *h = new QgsRasterHistogram( sipCpp->histogram( a0, a1, minimum, maximum, *a4, a5, a6, a7 ) );
432 return sipConvertFromType( h, sipType_QgsRasterHistogram, Py_None );
433 % End
434#endif
435
436
441#ifndef SIP_RUN
442 virtual bool hasHistogram( int bandNo,
443 int binCount,
444 double minimum = std::numeric_limits<double>::quiet_NaN(),
445 double maximum = std::numeric_limits<double>::quiet_NaN(),
446 const QgsRectangle &extent = QgsRectangle(),
447 int sampleSize = 0,
448 bool includeOutOfRange = false );
449#else
450 virtual bool hasHistogram( int bandNo,
451 int binCount,
452 SIP_PYOBJECT minimum = Py_None,
453 SIP_PYOBJECT maximum = Py_None,
454 const QgsRectangle &extent = QgsRectangle(),
455 int sampleSize = 0,
456 bool includeOutOfRange = false )
457 [bool( int bandNo,
458 int binCount,
459 double minimum = 0.0,
460 double maximum = 0.0,
461 const QgsRectangle &extent = QgsRectangle(),
462 int sampleSize = 0,
463 bool includeOutOfRange = false )];
464 % MethodCode
465 double minimum;
466 double maximum;
467 if ( a2 == Py_None )
468 {
469 minimum = std::numeric_limits<double>::quiet_NaN();
470 }
471 else
472 {
473 minimum = PyFloat_AsDouble( a2 );
474 }
475
476 if ( a3 == Py_None )
477 {
478 maximum = std::numeric_limits<double>::quiet_NaN();
479 }
480 else
481 {
482 maximum = PyFloat_AsDouble( a3 );
483 }
484
485 sipRes = sipCpp->hasHistogram( a0, a1, minimum, maximum, *a4, a5, a6 );
486 % End
487#endif
488
489
500 virtual void cumulativeCut( int bandNo,
501 double lowerCount,
502 double upperCount,
503 double &lowerValue,
504 double &upperValue,
505 const QgsRectangle &extent = QgsRectangle(),
506 int sampleSize = 0 );
507
509 virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const { Q_UNUSED( doc ) Q_UNUSED( parentElem ); }
511 virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ) }
512
513 protected:
514 // QgsRasterInterface used as input
515 QgsRasterInterface *mInput = nullptr;
516
518 QList<QgsRasterBandStats> mStatistics;
519
521 QList<QgsRasterHistogram> mHistograms;
522
523 // On/off state, if off, it does not do anything, replicates input
524 bool mOn = true;
525
530#ifndef SIP_RUN
531 void initHistogram( QgsRasterHistogram &histogram,
532 int bandNo,
533 int binCount,
534 double minimum = std::numeric_limits<double>::quiet_NaN(),
535 double maximum = std::numeric_limits<double>::quiet_NaN(),
536 const QgsRectangle &boundingBox = QgsRectangle(),
537 int sampleSize = 0,
538 bool includeOutOfRange = false );
539#else
540 void initHistogram( QgsRasterHistogram &histogram,
541 int bandNo,
542 int binCount,
543 SIP_PYOBJECT minimum = Py_None,
544 SIP_PYOBJECT maximum = Py_None,
545 const QgsRectangle &boundingBox = QgsRectangle(),
546 int sampleSize = 0,
547 bool includeOutOfRange = false )
548 [void ( QgsRasterHistogram & histogram,
549 int bandNo,
550 int binCount,
551 double minimum = 0.0,
552 double maximum = 0.0,
553 const QgsRectangle &boundingBox = QgsRectangle(),
554 int sampleSize = 0,
555 bool includeOutOfRange = false )];
556 % MethodCode
557 double minimum;
558 double maximum;
559 if ( a3 == Py_None )
560 {
561 minimum = std::numeric_limits<double>::quiet_NaN();
562 }
563 else
564 {
565 minimum = PyFloat_AsDouble( a3 );
566 }
567
568 if ( a4 == Py_None )
569 {
570 maximum = std::numeric_limits<double>::quiet_NaN();
571 }
572 else
573 {
574 maximum = PyFloat_AsDouble( a4 );
575 }
576
577#if defined(SIP_PROTECTED_IS_PUBLIC) || (SIP_VERSION >= 0x050000 && !defined(_MSC_VER))
578 sipCpp->initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
579#else
580 sipCpp->sipProtect_initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
581#endif
582 % End
583#endif
584
589 Q_DECL_DEPRECATED void initStatistics( QgsRasterBandStats &statistics, int bandNo, int stats, const QgsRectangle &boundingBox = QgsRectangle(), int binCount = 0 ) const SIP_DEPRECATED;
590
592 void initStatistics( QgsRasterBandStats &statistics, int bandNo,
593 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
594 const QgsRectangle &boundingBox = QgsRectangle(),
595 int binCount = 0 ) const;
596
597 private:
598#ifdef SIP_RUN
600 QgsRasterInterface &operator=( const QgsRasterInterface & );
601#endif
602
603 Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
604};
605
606#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QFlags< RasterInterfaceCapability > RasterInterfaceCapabilities
Raster interface capabilities.
Definition qgis.h:4218
@ 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.
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
virtual int xSize() const
Gets raster size.
virtual void setOn(bool on)
Sets whether the interface is on or off.
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 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.
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:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#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