QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsrasterdataprovider.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterdataprovider.cpp - DataProvider Interface for raster layers
3  --------------------------------------
4  Date : Mar 11, 2005
5  Copyright : (C) 2005 by Brendan Morley
6  email : morb at ozemail dot com dot au
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 #include "qgsproviderregistry.h"
19 #include "qgsrasterdataprovider.h"
21 #include "qgsprovidermetadata.h"
22 #include "qgsrasterprojector.h"
23 #include "qgslogger.h"
24 #include "qgsmessagelog.h"
25 #include "qgsapplication.h"
26 #include "qgspoint.h"
27 
28 #include <QTime>
29 #include <QMap>
30 #include <QByteArray>
31 #include <QVariant>
32 
33 #define ERR(message) QgsError(message, "Raster provider")
34 
36 {
37  if ( mUseSrcNoDataValue.size() < bandNo )
38  {
39  for ( int i = mUseSrcNoDataValue.size(); i < bandNo; i++ )
40  {
41  mUseSrcNoDataValue.append( false );
42  }
43  }
44  mUseSrcNoDataValue[bandNo - 1] = use;
45 }
46 
47 QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback )
48 {
49  QgsDebugMsgLevel( QStringLiteral( "bandNo = %1 width = %2 height = %3" ).arg( bandNo ).arg( width ).arg( height ), 4 );
50  QgsDebugMsgLevel( QStringLiteral( "boundingBox = %1" ).arg( boundingBox.toString() ), 4 );
51 
52  std::unique_ptr< QgsRasterBlock > block = std::make_unique< QgsRasterBlock >( dataType( bandNo ), width, height );
53  if ( sourceHasNoDataValue( bandNo ) && useSourceNoDataValue( bandNo ) )
54  {
56  }
57 
58  if ( block->isEmpty() )
59  {
60  QgsDebugMsg( QStringLiteral( "Couldn't create raster block" ) );
61  block->setError( { tr( "Couldn't create raster block." ), QStringLiteral( "Raster" ) } );
62  block->setValid( false );
63  return block.release();
64  }
65 
66  // Read necessary extent only
67  QgsRectangle tmpExtent = boundingBox;
68 
69  if ( tmpExtent.isEmpty() )
70  {
71  QgsDebugMsg( QStringLiteral( "Extent outside provider extent" ) );
72  block->setError( { tr( "Extent outside provider extent." ), QStringLiteral( "Raster" ) } );
73  block->setValid( false );
74  block->setIsNoData();
75  return block.release();
76  }
77 
78  double xRes = boundingBox.width() / width;
79  double yRes = boundingBox.height() / height;
80  double tmpXRes, tmpYRes;
81  double providerXRes = 0;
82  double providerYRes = 0;
83  if ( capabilities() & Size )
84  {
85  providerXRes = extent().width() / xSize();
86  providerYRes = extent().height() / ySize();
87  tmpXRes = std::max( providerXRes, xRes );
88  tmpYRes = std::max( providerYRes, yRes );
89  if ( qgsDoubleNear( tmpXRes, xRes ) ) tmpXRes = xRes;
90  if ( qgsDoubleNear( tmpYRes, yRes ) ) tmpYRes = yRes;
91  }
92  else
93  {
94  tmpXRes = xRes;
95  tmpYRes = yRes;
96  }
97 
98  if ( tmpExtent != boundingBox ||
99  tmpXRes > xRes || tmpYRes > yRes )
100  {
101  // Read smaller extent or lower resolution
102 
103  if ( !extent().contains( boundingBox ) )
104  {
105  QRect subRect = QgsRasterBlock::subRect( boundingBox, width, height, extent() );
106  block->setIsNoDataExcept( subRect );
107  }
108 
109  // Calculate row/col limits (before tmpExtent is aligned)
110  int fromRow = std::round( ( boundingBox.yMaximum() - tmpExtent.yMaximum() ) / yRes );
111  int toRow = std::round( ( boundingBox.yMaximum() - tmpExtent.yMinimum() ) / yRes ) - 1;
112  int fromCol = std::round( ( tmpExtent.xMinimum() - boundingBox.xMinimum() ) / xRes );
113  int toCol = std::round( ( tmpExtent.xMaximum() - boundingBox.xMinimum() ) / xRes ) - 1;
114 
115  QgsDebugMsgLevel( QStringLiteral( "fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ), 4 );
116 
117  if ( fromRow < 0 || fromRow >= height || toRow < 0 || toRow >= height ||
118  fromCol < 0 || fromCol >= width || toCol < 0 || toCol >= width )
119  {
120  // Should not happen
121  QgsDebugMsg( QStringLiteral( "Row or column limits out of range" ) );
122  block->setError( { tr( "Row or column limits out of range" ), QStringLiteral( "Raster" ) } );
123  block->setValid( false );
124  return block.release();
125  }
126 
127  // If lower source resolution is used, the extent must be aligned to original
128  // resolution to avoid possible shift due to resampling
129  if ( tmpXRes > xRes )
130  {
131  int col = std::floor( ( tmpExtent.xMinimum() - extent().xMinimum() ) / providerXRes );
132  tmpExtent.setXMinimum( extent().xMinimum() + col * providerXRes );
133  col = std::ceil( ( tmpExtent.xMaximum() - extent().xMinimum() ) / providerXRes );
134  tmpExtent.setXMaximum( extent().xMinimum() + col * providerXRes );
135  }
136  if ( tmpYRes > yRes )
137  {
138  int row = std::floor( ( extent().yMaximum() - tmpExtent.yMaximum() ) / providerYRes );
139  tmpExtent.setYMaximum( extent().yMaximum() - row * providerYRes );
140  row = std::ceil( ( extent().yMaximum() - tmpExtent.yMinimum() ) / providerYRes );
141  tmpExtent.setYMinimum( extent().yMaximum() - row * providerYRes );
142  }
143  int tmpWidth = std::round( tmpExtent.width() / tmpXRes );
144  int tmpHeight = std::round( tmpExtent.height() / tmpYRes );
145  tmpXRes = tmpExtent.width() / tmpWidth;
146  tmpYRes = tmpExtent.height() / tmpHeight;
147 
148  QgsDebugMsgLevel( QStringLiteral( "Reading smaller block tmpWidth = %1 height = %2" ).arg( tmpWidth ).arg( tmpHeight ), 4 );
149  QgsDebugMsgLevel( QStringLiteral( "tmpExtent = %1" ).arg( tmpExtent.toString() ), 4 );
150 
151  std::unique_ptr< QgsRasterBlock > tmpBlock = std::make_unique< QgsRasterBlock >( dataType( bandNo ), tmpWidth, tmpHeight );
152  if ( sourceHasNoDataValue( bandNo ) && useSourceNoDataValue( bandNo ) )
153  {
154  tmpBlock->setNoDataValue( sourceNoDataValue( bandNo ) );
155  }
156 
157  if ( !readBlock( bandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->bits(), feedback ) )
158  {
159  QgsDebugMsg( QStringLiteral( "Error occurred while reading block" ) );
160  block->setError( { tr( "Error occurred while reading block." ), QStringLiteral( "Raster" ) } );
161  block->setValid( false );
162  block->setIsNoData();
163  return block.release();
164  }
165 
166  int pixelSize = dataTypeSize( bandNo );
167 
168  double xMin = boundingBox.xMinimum();
169  double yMax = boundingBox.yMaximum();
170  double tmpXMin = tmpExtent.xMinimum();
171  double tmpYMax = tmpExtent.yMaximum();
172 
173  for ( int row = fromRow; row <= toRow; row++ )
174  {
175  double y = yMax - ( row + 0.5 ) * yRes;
176  int tmpRow = std::floor( ( tmpYMax - y ) / tmpYRes );
177 
178  for ( int col = fromCol; col <= toCol; col++ )
179  {
180  double x = xMin + ( col + 0.5 ) * xRes;
181  int tmpCol = std::floor( ( x - tmpXMin ) / tmpXRes );
182 
183  if ( tmpRow < 0 || tmpRow >= tmpHeight || tmpCol < 0 || tmpCol >= tmpWidth )
184  {
185  QgsDebugMsg( QStringLiteral( "Source row or column limits out of range" ) );
186  block->setIsNoData(); // so that the problem becomes obvious and fixed
187  block->setError( { tr( "Source row or column limits out of range." ), QStringLiteral( "Raster" ) } );
188  block->setValid( false );
189  return block.release();
190  }
191 
192  qgssize tmpIndex = static_cast< qgssize >( tmpRow ) * static_cast< qgssize >( tmpWidth ) + tmpCol;
193  qgssize index = row * static_cast< qgssize >( width ) + col;
194 
195  char *tmpBits = tmpBlock->bits( tmpIndex );
196  char *bits = block->bits( index );
197  if ( !tmpBits )
198  {
199  QgsDebugMsg( QStringLiteral( "Cannot get input block data tmpRow = %1 tmpCol = %2 tmpIndex = %3." ).arg( tmpRow ).arg( tmpCol ).arg( tmpIndex ) );
200  continue;
201  }
202  if ( !bits )
203  {
204  QgsDebugMsg( QStringLiteral( "Cannot set output block data." ) );
205  continue;
206  }
207  memcpy( bits, tmpBits, pixelSize );
208  }
209  }
210  }
211  else
212  {
213  if ( !readBlock( bandNo, boundingBox, width, height, block->bits(), feedback ) )
214  {
215  QgsDebugMsg( QStringLiteral( "Error occurred while reading block" ) );
216  block->setIsNoData();
217  block->setError( { tr( "Error occurred while reading block." ), QStringLiteral( "Raster" ) } );
218  block->setValid( false );
219  return block.release();
220  }
221  }
222 
223  // apply scale and offset
224  block->applyScaleOffset( bandScale( bandNo ), bandOffset( bandNo ) );
225  // apply user no data values
227  return block.release();
228 }
229 
231  : QgsDataProvider( QString(), QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() )
232  , QgsRasterInterface( nullptr )
233  , mTemporalCapabilities( std::make_unique< QgsRasterDataProviderTemporalCapabilities >() )
234 {
235 
236 }
237 
239  QgsDataProvider::ReadFlags flags )
240  : QgsDataProvider( uri, options, flags )
241  , QgsRasterInterface( nullptr )
242  , mTemporalCapabilities( std::make_unique< QgsRasterDataProviderTemporalCapabilities >() )
243 {
244 }
245 
246 QgsRasterDataProvider::ProviderCapabilities QgsRasterDataProvider::providerCapabilities() const
247 {
249 }
250 
252 {
253  Q_UNUSED( bandNo )
255 }
256 
257 //
258 //Random Static convenience function
259 //
261 
262 // TODO
263 // (WMS) IdentifyFormatFeature is not consistent with QgsRaster::IdentifyFormatValue.
264 // IdentifyFormatHtml: better error reporting
265 QgsRasterIdentifyResult QgsRasterDataProvider::identify( const QgsPointXY &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox, int width, int height, int /*dpi*/ )
266 {
267  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
268  QMap<int, QVariant> results;
269 
270  if ( format != QgsRaster::IdentifyFormatValue || !( capabilities() & IdentifyValue ) )
271  {
272  QgsDebugMsg( QStringLiteral( "Format not supported" ) );
273  return QgsRasterIdentifyResult( ERR( tr( "Format not supported" ) ) );
274  }
275 
276  if ( !extent().contains( point ) )
277  {
278  // Outside the raster
279  for ( int bandNo = 1; bandNo <= bandCount(); bandNo++ )
280  {
281  results.insert( bandNo, QVariant() );
282  }
284  }
285 
286  QgsRectangle finalExtent = boundingBox;
287  if ( finalExtent.isEmpty() )
288  finalExtent = extent();
289 
290  if ( width == 0 )
291  {
292  width = capabilities() & Size ? xSize() : 1000;
293  }
294  if ( height == 0 )
295  {
296  height = capabilities() & Size ? ySize() : 1000;
297  }
298 
299  // Calculate the row / column where the point falls
300  double xres = ( finalExtent.width() ) / width;
301  double yres = ( finalExtent.height() ) / height;
302 
303  int col = static_cast< int >( std::floor( ( point.x() - finalExtent.xMinimum() ) / xres ) );
304  int row = static_cast< int >( std::floor( ( finalExtent.yMaximum() - point.y() ) / yres ) );
305 
306  double xMin = finalExtent.xMinimum() + col * xres;
307  double xMax = xMin + xres;
308  double yMax = finalExtent.yMaximum() - row * yres;
309  double yMin = yMax - yres;
310  QgsRectangle pixelExtent( xMin, yMin, xMax, yMax );
311 
312  for ( int i = 1; i <= bandCount(); i++ )
313  {
314  std::unique_ptr< QgsRasterBlock > bandBlock( block( i, pixelExtent, 1, 1 ) );
315 
316  if ( bandBlock )
317  {
318  double value = bandBlock->value( 0 );
319 
320  results.insert( i, value );
321  }
322  else
323  {
324  results.insert( i, QVariant() );
325  }
326  }
328 }
329 
330 double QgsRasterDataProvider::sample( const QgsPointXY &point, int band,
331  bool *ok, const QgsRectangle &boundingBox, int width, int height, int dpi )
332 {
333  if ( ok )
334  *ok = false;
335 
336  const auto res = identify( point, QgsRaster::IdentifyFormatValue, boundingBox, width, height, dpi );
337  const QVariant value = res.results().value( band );
338 
339  if ( !value.isValid() )
340  return std::numeric_limits<double>::quiet_NaN();
341 
342  if ( ok )
343  *ok = true;
344 
345  return value.toDouble( ok );
346 }
347 
349 {
350  return QStringLiteral( "text/plain" );
351 }
352 
353 bool QgsRasterDataProvider::writeBlock( QgsRasterBlock *block, int band, int xOffset, int yOffset )
354 {
355  if ( !block )
356  return false;
357  if ( !isEditable() )
358  {
359  QgsDebugMsg( QStringLiteral( "writeBlock() called on read-only provider." ) );
360  return false;
361  }
362  return write( block->bits(), band, block->width(), block->height(), xOffset, yOffset );
363 }
364 
365 // typedef QList<QPair<QString, QString> > *pyramidResamplingMethods_t();
366 QList<QPair<QString, QString> > QgsRasterDataProvider::pyramidResamplingMethods( const QString &providerKey )
367 {
368  QList<QPair<QString, QString> > methods = QgsProviderRegistry::instance()->pyramidResamplingMethods( providerKey );
369  if ( methods.isEmpty() )
370  {
371  QgsDebugMsg( QStringLiteral( "provider pyramidResamplingMethods returned no methods" ) );
372  }
373  return methods;
374 }
375 
377 {
378  const QList<QgsRasterPyramid> pyramidList = buildPyramidList();
379  return std::any_of( pyramidList.constBegin(), pyramidList.constEnd(), []( QgsRasterPyramid pyramid ) { return pyramid.getExists(); } );
380 }
381 
383 {
384  if ( bandNo >= mUserNoDataValue.size() )
385  {
386  for ( int i = mUserNoDataValue.size(); i < bandNo; i++ )
387  {
389  }
390  }
391  QgsDebugMsgLevel( QStringLiteral( "set %1 band %1 no data ranges" ).arg( noData.size() ), 4 );
392 
393  if ( mUserNoDataValue[bandNo - 1] != noData )
394  {
395  // Clear statistics
396  int i = 0;
397  while ( i < mStatistics.size() )
398  {
399  if ( mStatistics.value( i ).bandNumber == bandNo )
400  {
401  mStatistics.removeAt( i );
402  mHistograms.removeAt( i );
403  }
404  else
405  {
406  i++;
407  }
408  }
409  mUserNoDataValue[bandNo - 1] = noData;
410  }
411 }
412 
414 {
415  return mTemporalCapabilities.get();
416 }
417 
419 {
420  return mTemporalCapabilities.get();
421 }
422 
424  const QString &uri,
425  const QString &format, int nBands,
426  Qgis::DataType type,
427  int width, int height, double *geoTransform,
429  const QStringList &createOptions )
430 {
432  providerKey,
433  uri, format,
434  nBands, type, width,
435  height, geoTransform, crs, createOptions );
436  if ( !ret )
437  {
438  QgsDebugMsg( "Cannot resolve 'createRasterDataProviderFunction' function in " + providerKey + " provider" );
439  }
440 
441  // TODO: it would be good to return invalid QgsRasterDataProvider
442  // with QgsError set, but QgsRasterDataProvider has pure virtual methods
443 
444  return ret;
445 }
446 
448 {
449  switch ( format )
450  {
452  return QStringLiteral( "Value" );
454  return QStringLiteral( "Text" );
456  return QStringLiteral( "Html" );
458  return QStringLiteral( "Feature" );
459  default:
460  return QStringLiteral( "Undefined" );
461  }
462 }
463 
465 {
466  switch ( format )
467  {
469  return tr( "Value" );
471  return tr( "Text" );
473  return tr( "Html" );
475  return tr( "Feature" );
476  default:
477  return QStringLiteral( "Undefined" );
478  }
479 }
480 
482 {
483  if ( formatName == QLatin1String( "Value" ) ) return QgsRaster::IdentifyFormatValue;
484  if ( formatName == QLatin1String( "Text" ) ) return QgsRaster::IdentifyFormatText;
485  if ( formatName == QLatin1String( "Html" ) ) return QgsRaster::IdentifyFormatHtml;
486  if ( formatName == QLatin1String( "Feature" ) ) return QgsRaster::IdentifyFormatFeature;
488 }
489 
491 {
492  switch ( format )
493  {
495  return IdentifyValue;
497  return IdentifyText;
499  return IdentifyHtml;
501  return IdentifyFeature;
502  default:
503  return NoCapabilities;
504  }
505 }
506 
508 {
509  return QList< double >();
510 }
511 
513 {
514  return false;
515 }
516 
518 {
519  Q_UNUSED( point )
520  Q_UNUSED( type )
521  return QgsPoint();
522 }
523 
524 bool QgsRasterDataProvider::userNoDataValuesContains( int bandNo, double value ) const
525 {
526  QgsRasterRangeList rangeList = mUserNoDataValue.value( bandNo - 1 );
527  return QgsRasterRange::contains( value, rangeList );
528 }
529 
531 {
532  mDpi = other.mDpi;
537  mExtent = other.mExtent;
542 
543  // copy temporal properties
544  if ( mTemporalCapabilities && other.mTemporalCapabilities )
545  {
546  *mTemporalCapabilities = *other.mTemporalCapabilities;
547  }
548 }
549 
550 static QgsRasterDataProvider::ResamplingMethod resamplingMethodFromString( const QString &str )
551 {
552  if ( str == QLatin1String( "bilinear" ) )
553  {
555  }
556  else if ( str == QLatin1String( "cubic" ) )
557  {
559  }
560  else if ( str == QLatin1String( "cubicSpline" ) )
561  {
563  }
564  else if ( str == QLatin1String( "lanczos" ) )
565  {
567  }
568  else if ( str == QLatin1String( "average" ) )
569  {
571  }
572  else if ( str == QLatin1String( "mode" ) )
573  {
575  }
576  else if ( str == QLatin1String( "gauss" ) )
577  {
579  }
581 }
582 
583 void QgsRasterDataProvider::readXml( const QDomElement &filterElem )
584 {
585  if ( filterElem.isNull() )
586  {
587  return;
588  }
589 
590  QDomElement resamplingElement = filterElem.firstChildElement( QStringLiteral( "resampling" ) );
591  if ( !resamplingElement.isNull() )
592  {
593  setMaxOversampling( resamplingElement.attribute( QStringLiteral( "maxOversampling" ), QStringLiteral( "2.0" ) ).toDouble() );
594  setZoomedInResamplingMethod( resamplingMethodFromString( resamplingElement.attribute( QStringLiteral( "zoomedInResamplingMethod" ) ) ) );
595  setZoomedOutResamplingMethod( resamplingMethodFromString( resamplingElement.attribute( QStringLiteral( "zoomedOutResamplingMethod" ) ) ) );
596  enableProviderResampling( resamplingElement.attribute( QStringLiteral( "enabled" ) ) == QLatin1String( "true" ) );
597  }
598 }
599 
600 static QString resamplingMethodToString( QgsRasterDataProvider::ResamplingMethod method )
601 {
602  switch ( method )
603  {
605  return QStringLiteral( "nearestNeighbour" );
607  return QStringLiteral( "bilinear" );
609  return QStringLiteral( "cubic" );
611  return QStringLiteral( "cubicSpline" );
613  return QStringLiteral( "lanczos" );
615  return QStringLiteral( "average" );
617  return QStringLiteral( "mode" );
619  return QStringLiteral( "gauss" );
620  }
621  // should not happen
622  return QStringLiteral( "nearestNeighbour" );
623 }
624 
625 void QgsRasterDataProvider::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
626 {
627  QDomElement providerElement = doc.createElement( QStringLiteral( "provider" ) );
628  parentElem.appendChild( providerElement );
629 
630  QDomElement resamplingElement = doc.createElement( QStringLiteral( "resampling" ) );
631  providerElement.appendChild( resamplingElement );
632 
633  resamplingElement.setAttribute( QStringLiteral( "enabled" ),
634  mProviderResamplingEnabled ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
635 
636  resamplingElement.setAttribute( QStringLiteral( "zoomedInResamplingMethod" ),
637  resamplingMethodToString( mZoomedInResamplingMethod ) );
638 
639  resamplingElement.setAttribute( QStringLiteral( "zoomedOutResamplingMethod" ),
640  resamplingMethodToString( mZoomedOutResamplingMethod ) );
641 
642  resamplingElement.setAttribute( QStringLiteral( "maxOversampling" ),
643  QString::number( mMaxOversampling ) );
644 }
645 
647 {
648  return colorName( colorInterpretation( bandNo ) );
649 }
DataType
Raster data types.
Definition: qgis.h:119
This class represents a coordinate reference system (CRS).
Abstract base class for spatial data provider implementations.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
QgsDataSourceUri uri() const
Gets the data source specification.
A class to represent a 2D point.
Definition: qgspointxy.h:59
double y
Definition: qgspointxy.h:63
Q_GADGET double x
Definition: qgspointxy.h:62
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsRasterDataProvider * createRasterDataProvider(const QString &providerKey, const QString &uri, const QString &format, int nBands, Qgis::DataType type, int width, int height, double *geoTransform, const QgsCoordinateReferenceSystem &crs, const QStringList &createOptions=QStringList())
Creates new instance of raster data provider.
QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns list of raster pyramid resampling methods.
Feedback object tailored for raster block reading.
Raster data container.
bool isEmpty() const
Returns true if block is empty, i.e.
void setNoDataValue(double noDataValue) SIP_HOLDGIL
Sets cell value that will be considered as "no data".
void setValid(bool valid) SIP_HOLDGIL
Mark block as valid or invalid.
int width() const SIP_HOLDGIL
Returns the width (number of columns) of the raster block.
char * bits(int row, int column)
Returns a pointer to block data.
bool setIsNoDataExcept(QRect exceptRect)
Set the whole block to no data except specified rectangle.
void applyNoDataValues(const QgsRasterRangeList &rangeList)
void applyScaleOffset(double scale, double offset)
Apply band scale and offset to raster block values.
static QRect subRect(const QgsRectangle &extent, int width, int height, const QgsRectangle &subExtent)
For extent and width, height find rectangle covered by subextent.
void setError(const QgsError &error)
Sets the last error.
int height() const SIP_HOLDGIL
Returns the height (number of rows) of the raster block.
bool setIsNoData(int row, int column) SIP_HOLDGIL
Set no data on pixel.
Implementation of data provider temporal properties for QgsRasterDataProviders.
Base class for raster data providers.
double mMaxOversampling
Maximum boundary for oversampling (to avoid too much data traffic). Default: 2.0.
QList< bool > mUseSrcNoDataValue
Use source nodata value.
TransformType
Types of transformation in transformCoordinates() function.
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
virtual bool sourceHasNoDataValue(int bandNo) const
Returns true if source band has no data value.
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
virtual QString lastErrorFormat()
Returns the format of the error text for the last error in this provider.
bool mProviderResamplingEnabled
Whether provider resampling is enabled.
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
virtual QList< QgsRasterPyramid > buildPyramidList(const QList< int > &overviewList=QList< int >())
Returns the raster layers pyramid list.
virtual void setUseSourceNoDataValue(int bandNo, bool use)
Sets the source nodata value usage.
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
QString colorName(int colorInterpretation) const
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
QList< QgsRasterRangeList > mUserNoDataValue
List of lists of user defined additional no data values for each band, indexed from 0.
virtual QgsRasterIdentifyResult identify(const QgsPointXY &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Identify raster value(s) found on the point position.
virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
virtual bool isEditable() const
Checks whether the provider is in editing mode, i.e.
void copyBaseSettings(const QgsRasterDataProvider &other)
Copy member variables from other raster data provider. Useful for implementation of clone() method in...
bool userNoDataValuesContains(int bandNo, double value) const
Returns true if user no data contains value.
bool writeBlock(QgsRasterBlock *block, int band, int xOffset=0, int yOffset=0)
Writes pixel data from a raster block into the provider data source.
virtual bool enableProviderResampling(bool enable)
Enable or disable provider-level resampling.
QgsRectangle extent() const override=0
Returns the extent of the layer.
virtual bool ignoreExtents() const
Returns true if the extents reported by the data provider are not reliable and it's possible that the...
virtual bool setMaxOversampling(double factor)
Sets maximum oversampling factor for zoomed-out operations.
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
ResamplingMethod mZoomedOutResamplingMethod
Resampling method for zoomed out pixel extraction.
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
bool hasPyramids()
Returns true if raster has at least one existing pyramid.
virtual double bandScale(int bandNo) const
Read band scale for raster value.
static QString identifyFormatName(QgsRaster::IdentifyFormat format)
@ NoProviderCapabilities
Provider has no capabilities.
int dpi() const
Returns the dpi of the output device.
virtual double sample(const QgsPointXY &point, int band, bool *ok=nullptr, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Samples a raster value from the specified band found at the point position.
static QString identifyFormatLabel(QgsRaster::IdentifyFormat format)
QgsRasterBlock * block(int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
virtual int colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
virtual bool readBlock(int bandNo, int xBlock, int yBlock, void *data)
Reads a block of raster data into data.
ResamplingMethod mZoomedInResamplingMethod
Resampling method for zoomed in pixel extraction.
QgsRasterDataProvider()
Provider capabilities.
QList< bool > mSrcHasNoDataValue
Source no data value exists.
static QgsRasterDataProvider * create(const QString &providerKey, const QString &uri, const QString &format, int nBands, Qgis::DataType type, int width, int height, double *geoTransform, const QgsCoordinateReferenceSystem &crs, const QStringList &createOptions=QStringList())
Creates a new dataset with mDataSourceURI.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
virtual bool setZoomedInResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-in operations.
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
virtual QList< double > nativeResolutions() const
Returns a list of native resolutions if available, i.e.
virtual QgsPoint transformCoordinates(const QgsPoint &point, TransformType type)
Transforms coordinates between source image coordinate space [0..width]x[0..height] and layer coordin...
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
QString colorInterpretationName(int bandNo) const override
Returns the name of the color interpretation for the specified bandNumber.
ResamplingMethod
Resampling method for provider-level resampling.
@ Lanczos
Lanczos windowed sinc interpolation (6x6 kernel)
@ Nearest
Nearest-neighbour resampling.
@ Mode
Mode (selects the value which appears most often of all the sampled points)
@ Bilinear
Bilinear (2x2 kernel) resampling.
@ CubicSpline
Cubic B-Spline Approximation (4x4 kernel)
@ Cubic
Cubic Convolution Approximation (4x4 kernel) resampling.
virtual bool write(void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
virtual bool setZoomedOutResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-out operations.
Raster identify results container.
Base class for processing filters like renderers, reprojector, resampler etc.
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
Capability
If you add to this, please also add to capabilitiesString()
@ IdentifyValue
Numerical values.
@ IdentifyFeature
WMS GML -> feature.
@ Size
Original data source size (and thus resolution) is known, it is not always available,...
virtual int xSize() const
Gets raster size.
virtual int bandCount() const =0
Gets number of bands.
int dataTypeSize(int bandNo) const
Returns the size (in bytes) for the data type for the specified band.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
virtual int ySize() const
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
This struct is used to store pyramid info for the raster layer.
bool contains(double value) const
Returns true if this range contains the specified value.
IdentifyFormat
Definition: qgsraster.h:58
@ IdentifyFormatFeature
Definition: qgsraster.h:63
@ IdentifyFormatValue
Definition: qgsraster.h:60
@ IdentifyFormatText
Definition: qgsraster.h:61
@ IdentifyFormatUndefined
Definition: qgsraster.h:59
@ IdentifyFormatHtml
Definition: qgsraster.h:62
@ UndefinedColorInterpretation
Definition: qgsraster.h:37
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
Definition: qgsrectangle.h:161
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
Definition: qgsrectangle.h:156
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
Definition: qgsrectangle.h:151
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:230
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
Definition: qgsrectangle.h:166
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:223
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:469
#define str(x)
Definition: qgis.cpp:37
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
Definition: qgis.h:1051
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:598
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
#define ERR(message)
QList< QgsRasterRange > QgsRasterRangeList
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.