QGIS API Documentation 3.41.0-Master (3440c17df1d)
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
270 virtual QString colorInterpretationName( int bandNumber ) const;
271
277 QString displayBandName( int bandNumber ) const;
278
289 virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) = 0 SIP_FACTORY;
290
295 virtual bool setInput( QgsRasterInterface *input ) { mInput = input; return true; }
296
298 virtual QgsRasterInterface *input() const { return mInput; }
299
301 virtual bool on() const { return mOn; }
302
304 virtual void setOn( bool on ) { mOn = on; }
305
313 {
314 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
315 return mInput ? mInput->sourceInput() : this;
316 }
317
324 {
325 QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
326 return mInput ? mInput->sourceInput() : this;
327 }
328
338 Q_DECL_DEPRECATED QgsRasterBandStats bandStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr ) SIP_DEPRECATED;
339
348 virtual QgsRasterBandStats bandStatistics( int bandNo,
349 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
350 const QgsRectangle &extent = QgsRectangle(),
351 int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr );
352
359 Q_DECL_DEPRECATED bool hasStatistics( int bandNo, int stats, const QgsRectangle &extent = QgsRectangle(), int sampleSize = 0 ) SIP_DEPRECATED;
360
366 virtual bool hasStatistics( int bandNo,
367 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
368 const QgsRectangle &extent = QgsRectangle(),
369 int sampleSize = 0 );
370
371
385#ifndef SIP_RUN
386 virtual QgsRasterHistogram histogram( int bandNo,
387 int binCount = 0,
388 double minimum = std::numeric_limits<double>::quiet_NaN(),
389 double maximum = std::numeric_limits<double>::quiet_NaN(),
390 const QgsRectangle &extent = QgsRectangle(),
391 int sampleSize = 0,
392 bool includeOutOfRange = false,
393 QgsRasterBlockFeedback *feedback = nullptr );
394#else
395 virtual QgsRasterHistogram histogram( int bandNo,
396 int binCount = 0,
397 SIP_PYOBJECT minimum = Py_None,
398 SIP_PYOBJECT maximum = Py_None,
399 const QgsRectangle &extent = QgsRectangle(),
400 int sampleSize = 0,
401 bool includeOutOfRange = false,
402 QgsRasterBlockFeedback *feedback = nullptr )
403 [QgsRasterHistogram( int bandNo,
404 int binCount = 0,
405 double minimum = 0.0,
406 double maximum = 0.0,
407 const QgsRectangle &extent = QgsRectangle(),
408 int sampleSize = 0,
409 bool includeOutOfRange = false,
410 QgsRasterBlockFeedback *feedback = nullptr )];
411 % MethodCode
412 double minimum;
413 double maximum;
414 if ( a2 == Py_None )
415 {
416 minimum = std::numeric_limits<double>::quiet_NaN();
417 }
418 else
419 {
420 minimum = PyFloat_AsDouble( a2 );
421 }
422
423 if ( a3 == Py_None )
424 {
425 maximum = std::numeric_limits<double>::quiet_NaN();
426 }
427 else
428 {
429 maximum = PyFloat_AsDouble( a3 );
430 }
431
432 QgsRasterHistogram *h = new QgsRasterHistogram( sipCpp->histogram( a0, a1, minimum, maximum, *a4, a5, a6, a7 ) );
433 return sipConvertFromType( h, sipType_QgsRasterHistogram, Py_None );
434 % End
435#endif
436
437
442#ifndef SIP_RUN
443 virtual bool hasHistogram( int bandNo,
444 int binCount,
445 double minimum = std::numeric_limits<double>::quiet_NaN(),
446 double maximum = std::numeric_limits<double>::quiet_NaN(),
447 const QgsRectangle &extent = QgsRectangle(),
448 int sampleSize = 0,
449 bool includeOutOfRange = false );
450#else
451 virtual bool hasHistogram( int bandNo,
452 int binCount,
453 SIP_PYOBJECT minimum = Py_None,
454 SIP_PYOBJECT maximum = Py_None,
455 const QgsRectangle &extent = QgsRectangle(),
456 int sampleSize = 0,
457 bool includeOutOfRange = false )
458 [bool( int bandNo,
459 int binCount,
460 double minimum = 0.0,
461 double maximum = 0.0,
462 const QgsRectangle &extent = QgsRectangle(),
463 int sampleSize = 0,
464 bool includeOutOfRange = false )];
465 % MethodCode
466 double minimum;
467 double maximum;
468 if ( a2 == Py_None )
469 {
470 minimum = std::numeric_limits<double>::quiet_NaN();
471 }
472 else
473 {
474 minimum = PyFloat_AsDouble( a2 );
475 }
476
477 if ( a3 == Py_None )
478 {
479 maximum = std::numeric_limits<double>::quiet_NaN();
480 }
481 else
482 {
483 maximum = PyFloat_AsDouble( a3 );
484 }
485
486 sipRes = sipCpp->hasHistogram( a0, a1, minimum, maximum, *a4, a5, a6 );
487 % End
488#endif
489
490
501 virtual void cumulativeCut( int bandNo,
502 double lowerCount,
503 double upperCount,
504 double &lowerValue,
505 double &upperValue,
506 const QgsRectangle &extent = QgsRectangle(),
507 int sampleSize = 0 );
508
510 virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const { Q_UNUSED( doc ) Q_UNUSED( parentElem ); }
512 virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ) }
513
514 protected:
515 // QgsRasterInterface used as input
516 QgsRasterInterface *mInput = nullptr;
517
519 QList<QgsRasterBandStats> mStatistics;
520
522 QList<QgsRasterHistogram> mHistograms;
523
524 // On/off state, if off, it does not do anything, replicates input
525 bool mOn = true;
526
531#ifndef SIP_RUN
532 void initHistogram( QgsRasterHistogram &histogram,
533 int bandNo,
534 int binCount,
535 double minimum = std::numeric_limits<double>::quiet_NaN(),
536 double maximum = std::numeric_limits<double>::quiet_NaN(),
537 const QgsRectangle &boundingBox = QgsRectangle(),
538 int sampleSize = 0,
539 bool includeOutOfRange = false );
540#else
541 void initHistogram( QgsRasterHistogram &histogram,
542 int bandNo,
543 int binCount,
544 SIP_PYOBJECT minimum = Py_None,
545 SIP_PYOBJECT maximum = Py_None,
546 const QgsRectangle &boundingBox = QgsRectangle(),
547 int sampleSize = 0,
548 bool includeOutOfRange = false )
549 [void ( QgsRasterHistogram & histogram,
550 int bandNo,
551 int binCount,
552 double minimum = 0.0,
553 double maximum = 0.0,
554 const QgsRectangle &boundingBox = QgsRectangle(),
555 int sampleSize = 0,
556 bool includeOutOfRange = false )];
557 % MethodCode
558 double minimum;
559 double maximum;
560 if ( a3 == Py_None )
561 {
562 minimum = std::numeric_limits<double>::quiet_NaN();
563 }
564 else
565 {
566 minimum = PyFloat_AsDouble( a3 );
567 }
568
569 if ( a4 == Py_None )
570 {
571 maximum = std::numeric_limits<double>::quiet_NaN();
572 }
573 else
574 {
575 maximum = PyFloat_AsDouble( a4 );
576 }
577
578#if defined(SIP_PROTECTED_IS_PUBLIC) || (SIP_VERSION >= 0x050000 && !defined(_MSC_VER))
579 sipCpp->initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
580#else
581 sipCpp->sipProtect_initHistogram( *a0, a1, a2, minimum, maximum, *a5, a6, a7 );
582#endif
583 % End
584#endif
585
590 Q_DECL_DEPRECATED void initStatistics( QgsRasterBandStats &statistics, int bandNo, int stats, const QgsRectangle &boundingBox = QgsRectangle(), int binCount = 0 ) const SIP_DEPRECATED;
591
593 void initStatistics( QgsRasterBandStats &statistics, int bandNo,
594 Qgis::RasterBandStatistics stats = Qgis::RasterBandStatistic::All,
595 const QgsRectangle &boundingBox = QgsRectangle(),
596 int binCount = 0 ) const;
597
598 private:
599#ifdef SIP_RUN
601 QgsRasterInterface &operator=( const QgsRasterInterface & );
602#endif
603
604 Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
605};
606
607#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:4537
@ 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.
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: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