QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
27 #include <QTime>
28 #include <QMap>
29 #include <QByteArray>
30 #include <QVariant>
31 
32 #define ERR(message) QgsError(message, "Raster provider")
33 
35 {
36  if ( mUseSrcNoDataValue.size() < bandNo )
37  {
38  for ( int i = mUseSrcNoDataValue.size(); i < bandNo; i++ )
39  {
40  mUseSrcNoDataValue.append( false );
41  }
42  }
43  mUseSrcNoDataValue[bandNo - 1] = use;
44 }
45 
46 QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback )
47 {
48  QgsDebugMsgLevel( QStringLiteral( "bandNo = %1 width = %2 height = %3" ).arg( bandNo ).arg( width ).arg( height ), 4 );
49  QgsDebugMsgLevel( QStringLiteral( "boundingBox = %1" ).arg( boundingBox.toString() ), 4 );
50 
51  std::unique_ptr< QgsRasterBlock > block = qgis::make_unique< QgsRasterBlock >( dataType( bandNo ), width, height );
52  if ( sourceHasNoDataValue( bandNo ) && useSourceNoDataValue( bandNo ) )
53  {
55  }
56 
57  if ( block->isEmpty() )
58  {
59  QgsDebugMsg( QStringLiteral( "Couldn't create raster block" ) );
60  block->setError( { tr( "Couldn't create raster block." ), QStringLiteral( "Raster" ) } );
61  block->setValid( false );
62  return block.release();
63  }
64 
65  // Read necessary extent only
66  QgsRectangle tmpExtent = boundingBox;
67 
68  if ( tmpExtent.isEmpty() )
69  {
70  QgsDebugMsg( QStringLiteral( "Extent outside provider extent" ) );
71  block->setError( { tr( "Extent outside provider extent." ), QStringLiteral( "Raster" ) } );
72  block->setValid( false );
73  block->setIsNoData();
74  return block.release();
75  }
76 
77  double xRes = boundingBox.width() / width;
78  double yRes = boundingBox.height() / height;
79  double tmpXRes, tmpYRes;
80  double providerXRes = 0;
81  double providerYRes = 0;
82  if ( capabilities() & Size )
83  {
84  providerXRes = extent().width() / xSize();
85  providerYRes = extent().height() / ySize();
86  tmpXRes = std::max( providerXRes, xRes );
87  tmpYRes = std::max( providerYRes, yRes );
88  if ( qgsDoubleNear( tmpXRes, xRes ) ) tmpXRes = xRes;
89  if ( qgsDoubleNear( tmpYRes, yRes ) ) tmpYRes = yRes;
90  }
91  else
92  {
93  tmpXRes = xRes;
94  tmpYRes = yRes;
95  }
96 
97  if ( tmpExtent != boundingBox ||
98  tmpXRes > xRes || tmpYRes > yRes )
99  {
100  // Read smaller extent or lower resolution
101 
102  if ( !extent().contains( boundingBox ) )
103  {
104  QRect subRect = QgsRasterBlock::subRect( boundingBox, width, height, extent() );
105  block->setIsNoDataExcept( subRect );
106  }
107 
108  // Calculate row/col limits (before tmpExtent is aligned)
109  int fromRow = std::round( ( boundingBox.yMaximum() - tmpExtent.yMaximum() ) / yRes );
110  int toRow = std::round( ( boundingBox.yMaximum() - tmpExtent.yMinimum() ) / yRes ) - 1;
111  int fromCol = std::round( ( tmpExtent.xMinimum() - boundingBox.xMinimum() ) / xRes );
112  int toCol = std::round( ( tmpExtent.xMaximum() - boundingBox.xMinimum() ) / xRes ) - 1;
113 
114  QgsDebugMsgLevel( QStringLiteral( "fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ), 4 );
115 
116  if ( fromRow < 0 || fromRow >= height || toRow < 0 || toRow >= height ||
117  fromCol < 0 || fromCol >= width || toCol < 0 || toCol >= width )
118  {
119  // Should not happen
120  QgsDebugMsg( QStringLiteral( "Row or column limits out of range" ) );
121  block->setError( { tr( "Row or column limits out of range" ), QStringLiteral( "Raster" ) } );
122  block->setValid( false );
123  return block.release();
124  }
125 
126  // If lower source resolution is used, the extent must be aligned to original
127  // resolution to avoid possible shift due to resampling
128  if ( tmpXRes > xRes )
129  {
130  int col = std::floor( ( tmpExtent.xMinimum() - extent().xMinimum() ) / providerXRes );
131  tmpExtent.setXMinimum( extent().xMinimum() + col * providerXRes );
132  col = std::ceil( ( tmpExtent.xMaximum() - extent().xMinimum() ) / providerXRes );
133  tmpExtent.setXMaximum( extent().xMinimum() + col * providerXRes );
134  }
135  if ( tmpYRes > yRes )
136  {
137  int row = std::floor( ( extent().yMaximum() - tmpExtent.yMaximum() ) / providerYRes );
138  tmpExtent.setYMaximum( extent().yMaximum() - row * providerYRes );
139  row = std::ceil( ( extent().yMaximum() - tmpExtent.yMinimum() ) / providerYRes );
140  tmpExtent.setYMinimum( extent().yMaximum() - row * providerYRes );
141  }
142  int tmpWidth = std::round( tmpExtent.width() / tmpXRes );
143  int tmpHeight = std::round( tmpExtent.height() / tmpYRes );
144  tmpXRes = tmpExtent.width() / tmpWidth;
145  tmpYRes = tmpExtent.height() / tmpHeight;
146 
147  QgsDebugMsgLevel( QStringLiteral( "Reading smaller block tmpWidth = %1 height = %2" ).arg( tmpWidth ).arg( tmpHeight ), 4 );
148  QgsDebugMsgLevel( QStringLiteral( "tmpExtent = %1" ).arg( tmpExtent.toString() ), 4 );
149 
150  std::unique_ptr< QgsRasterBlock > tmpBlock = qgis::make_unique< QgsRasterBlock >( dataType( bandNo ), tmpWidth, tmpHeight );
151  if ( sourceHasNoDataValue( bandNo ) && useSourceNoDataValue( bandNo ) )
152  {
153  tmpBlock->setNoDataValue( sourceNoDataValue( bandNo ) );
154  }
155 
156  if ( !readBlock( bandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->bits(), feedback ) )
157  {
158  QgsDebugMsg( QStringLiteral( "Error occurred while reading block" ) );
159  block->setError( { tr( "Error occurred while reading block." ), QStringLiteral( "Raster" ) } );
160  block->setValid( false );
161  block->setIsNoData();
162  return block.release();
163  }
164 
165  int pixelSize = dataTypeSize( bandNo );
166 
167  double xMin = boundingBox.xMinimum();
168  double yMax = boundingBox.yMaximum();
169  double tmpXMin = tmpExtent.xMinimum();
170  double tmpYMax = tmpExtent.yMaximum();
171 
172  for ( int row = fromRow; row <= toRow; row++ )
173  {
174  double y = yMax - ( row + 0.5 ) * yRes;
175  int tmpRow = std::floor( ( tmpYMax - y ) / tmpYRes );
176 
177  for ( int col = fromCol; col <= toCol; col++ )
178  {
179  double x = xMin + ( col + 0.5 ) * xRes;
180  int tmpCol = std::floor( ( x - tmpXMin ) / tmpXRes );
181 
182  if ( tmpRow < 0 || tmpRow >= tmpHeight || tmpCol < 0 || tmpCol >= tmpWidth )
183  {
184  QgsDebugMsg( QStringLiteral( "Source row or column limits out of range" ) );
185  block->setIsNoData(); // so that the problem becomes obvious and fixed
186  block->setError( { tr( "Source row or column limits out of range." ), QStringLiteral( "Raster" ) } );
187  block->setValid( false );
188  return block.release();
189  }
190 
191  qgssize tmpIndex = static_cast< qgssize >( tmpRow ) * static_cast< qgssize >( tmpWidth ) + tmpCol;
192  qgssize index = row * static_cast< qgssize >( width ) + col;
193 
194  char *tmpBits = tmpBlock->bits( tmpIndex );
195  char *bits = block->bits( index );
196  if ( !tmpBits )
197  {
198  QgsDebugMsg( QStringLiteral( "Cannot get input block data tmpRow = %1 tmpCol = %2 tmpIndex = %3." ).arg( tmpRow ).arg( tmpCol ).arg( tmpIndex ) );
199  continue;
200  }
201  if ( !bits )
202  {
203  QgsDebugMsg( QStringLiteral( "Cannot set output block data." ) );
204  continue;
205  }
206  memcpy( bits, tmpBits, pixelSize );
207  }
208  }
209  }
210  else
211  {
212  if ( !readBlock( bandNo, boundingBox, width, height, block->bits(), feedback ) )
213  {
214  QgsDebugMsg( QStringLiteral( "Error occurred while reading block" ) );
215  block->setIsNoData();
216  block->setError( { tr( "Error occurred while reading block." ), QStringLiteral( "Raster" ) } );
217  block->setValid( false );
218  return block.release();
219  }
220  }
221 
222  // apply scale and offset
223  block->applyScaleOffset( bandScale( bandNo ), bandOffset( bandNo ) );
224  // apply user no data values
226  return block.release();
227 }
228 
230  : QgsDataProvider( QString(), QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags() )
231  , QgsRasterInterface( nullptr )
232  , mTemporalCapabilities( qgis::make_unique< QgsRasterDataProviderTemporalCapabilities >() )
233 {
234 
235 }
236 
238  QgsDataProvider::ReadFlags flags )
239  : QgsDataProvider( uri, options, flags )
240  , QgsRasterInterface( nullptr )
241  , mTemporalCapabilities( qgis::make_unique< QgsRasterDataProviderTemporalCapabilities >() )
242 {
243 }
244 
245 QgsRasterDataProvider::ProviderCapabilities QgsRasterDataProvider::providerCapabilities() const
246 {
248 }
249 
250 //
251 //Random Static convenience function
252 //
254 // convenience function for building metadata() HTML table cells
255 
257 {
258  QString s;
259  return s;
260 }
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  QList<QgsRasterPyramid> myPyramidList = buildPyramidList();
379 
380  if ( myPyramidList.isEmpty() )
381  return false;
382 
383  QList<QgsRasterPyramid>::iterator myRasterPyramidIterator;
384  for ( myRasterPyramidIterator = myPyramidList.begin();
385  myRasterPyramidIterator != myPyramidList.end();
386  ++myRasterPyramidIterator )
387  {
388  if ( myRasterPyramidIterator->exists )
389  {
390  return true;
391  }
392  }
393  return false;
394 }
395 
397 {
398  if ( bandNo >= mUserNoDataValue.size() )
399  {
400  for ( int i = mUserNoDataValue.size(); i < bandNo; i++ )
401  {
403  }
404  }
405  QgsDebugMsgLevel( QStringLiteral( "set %1 band %1 no data ranges" ).arg( noData.size() ), 4 );
406 
407  if ( mUserNoDataValue[bandNo - 1] != noData )
408  {
409  // Clear statistics
410  int i = 0;
411  while ( i < mStatistics.size() )
412  {
413  if ( mStatistics.value( i ).bandNumber == bandNo )
414  {
415  mStatistics.removeAt( i );
416  mHistograms.removeAt( i );
417  }
418  else
419  {
420  i++;
421  }
422  }
423  mUserNoDataValue[bandNo - 1] = noData;
424  }
425 }
426 
428 {
429  return mTemporalCapabilities.get();
430 }
431 
433 {
434  return mTemporalCapabilities.get();
435 }
436 
438  const QString &uri,
439  const QString &format, int nBands,
440  Qgis::DataType type,
441  int width, int height, double *geoTransform,
443  const QStringList &createOptions )
444 {
446  providerKey,
447  uri, format,
448  nBands, type, width,
449  height, geoTransform, crs, createOptions );
450  if ( !ret )
451  {
452  QgsDebugMsg( "Cannot resolve 'createRasterDataProviderFunction' function in " + providerKey + " provider" );
453  }
454 
455  // TODO: it would be good to return invalid QgsRasterDataProvider
456  // with QgsError set, but QgsRasterDataProvider has pure virtual methods
457 
458  return ret;
459 }
460 
462 {
463  switch ( format )
464  {
466  return QStringLiteral( "Value" );
468  return QStringLiteral( "Text" );
470  return QStringLiteral( "Html" );
472  return QStringLiteral( "Feature" );
473  default:
474  return QStringLiteral( "Undefined" );
475  }
476 }
477 
479 {
480  switch ( format )
481  {
483  return tr( "Value" );
485  return tr( "Text" );
487  return tr( "Html" );
489  return tr( "Feature" );
490  default:
491  return QStringLiteral( "Undefined" );
492  }
493 }
494 
496 {
497  if ( formatName == QLatin1String( "Value" ) ) return QgsRaster::IdentifyFormatValue;
498  if ( formatName == QLatin1String( "Text" ) ) return QgsRaster::IdentifyFormatText;
499  if ( formatName == QLatin1String( "Html" ) ) return QgsRaster::IdentifyFormatHtml;
500  if ( formatName == QLatin1String( "Feature" ) ) return QgsRaster::IdentifyFormatFeature;
502 }
503 
505 {
506  switch ( format )
507  {
509  return IdentifyValue;
511  return IdentifyText;
513  return IdentifyHtml;
515  return IdentifyFeature;
516  default:
517  return NoCapabilities;
518  }
519 }
520 
522 {
523  return QList< double >();
524 }
525 
527 {
528  return false;
529 }
530 
532 {
533  Q_UNUSED( point )
534  Q_UNUSED( type )
535  return QgsPoint();
536 }
537 
538 bool QgsRasterDataProvider::userNoDataValuesContains( int bandNo, double value ) const
539 {
540  QgsRasterRangeList rangeList = mUserNoDataValue.value( bandNo - 1 );
541  return QgsRasterRange::contains( value, rangeList );
542 }
543 
545 {
546  mDpi = other.mDpi;
551  mExtent = other.mExtent;
556 
557  // copy temporal properties
558  if ( mTemporalCapabilities && other.mTemporalCapabilities )
559  {
560  *mTemporalCapabilities = *other.mTemporalCapabilities;
561  }
562 }
563 
564 static QgsRasterDataProvider::ResamplingMethod resamplingMethodFromString( const QString &str )
565 {
566  if ( str == QLatin1String( "bilinear" ) )
567  {
569  }
570  else if ( str == QLatin1String( "cubic" ) )
571  {
573  }
575 }
576 
577 void QgsRasterDataProvider::readXml( const QDomElement &filterElem )
578 {
579  if ( filterElem.isNull() )
580  {
581  return;
582  }
583 
584  QDomElement resamplingElement = filterElem.firstChildElement( QStringLiteral( "resampling" ) );
585  if ( !resamplingElement.isNull() )
586  {
587  setMaxOversampling( resamplingElement.attribute( QStringLiteral( "maxOversampling" ), QStringLiteral( "2.0" ) ).toDouble() );
588  setZoomedInResamplingMethod( resamplingMethodFromString( resamplingElement.attribute( QStringLiteral( "zoomedInResamplingMethod" ) ) ) );
589  setZoomedOutResamplingMethod( resamplingMethodFromString( resamplingElement.attribute( QStringLiteral( "zoomedOutResamplingMethod" ) ) ) );
590  enableProviderResampling( resamplingElement.attribute( QStringLiteral( "enabled" ) ) == QLatin1String( "true" ) );
591  }
592 }
593 
594 static QString resamplingMethodToString( QgsRasterDataProvider::ResamplingMethod method )
595 {
596  switch ( method )
597  {
598  case QgsRasterDataProvider::ResamplingMethod::Nearest : return QStringLiteral( "nearestNeighbour" );
599  case QgsRasterDataProvider::ResamplingMethod::Bilinear : return QStringLiteral( "bilinear" );
600  case QgsRasterDataProvider::ResamplingMethod::Cubic : return QStringLiteral( "cubic" );
601  }
602  // should not happen
603  return QStringLiteral( "nearestNeighbour" );
604 }
605 
606 void QgsRasterDataProvider::writeXml( QDomDocument &doc, QDomElement &parentElem ) const
607 {
608  QDomElement providerElement = doc.createElement( QStringLiteral( "provider" ) );
609  parentElem.appendChild( providerElement );
610 
611  QDomElement resamplingElement = doc.createElement( QStringLiteral( "resampling" ) );
612  providerElement.appendChild( resamplingElement );
613 
614  resamplingElement.setAttribute( QStringLiteral( "enabled" ),
615  mProviderResamplingEnabled ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
616 
617  resamplingElement.setAttribute( QStringLiteral( "zoomedInResamplingMethod" ),
618  resamplingMethodToString( mZoomedInResamplingMethod ) );
619 
620  resamplingElement.setAttribute( QStringLiteral( "zoomedOutResamplingMethod" ),
621  resamplingMethodToString( mZoomedOutResamplingMethod ) );
622 
623  resamplingElement.setAttribute( QStringLiteral( "maxOversampling" ),
624  QString::number( mMaxOversampling ) );
625 }
626 
627 
628 // ENDS
QgsRasterDataProvider::setUserNoDataValue
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
Definition: qgsrasterdataprovider.cpp:396
qgsrasterprojector.h
QgsRectangle::height
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
ERR
#define ERR(message)
Definition: qgsrasterdataprovider.cpp:32
QgsPointXY::y
double y
Definition: qgspointxy.h:48
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:102
QgsRasterDataProvider::readXml
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
Definition: qgsrasterdataprovider.cpp:577
QgsRasterDataProvider::mSrcNoDataValue
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
Definition: qgsrasterdataprovider.h:712
QgsRasterDataProvider::dataType
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
QgsRasterInterface::IdentifyHtml
@ IdentifyHtml
Definition: qgsrasterinterface.h:193
QgsRasterInterface::mStatistics
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
Definition: qgsrasterinterface.h:470
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:105
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:42
QgsRasterInterface::Size
@ Size
Definition: qgsrasterinterface.h:186
QgsRasterBlock::applyNoDataValues
void applyNoDataValues(const QgsRasterRangeList &rangeList)
Definition: qgsrasterblock.cpp:583
QgsRasterDataProvider::ResamplingMethod::Nearest
@ Nearest
Nearest-neighbour resamplikng.
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
QgsRasterDataProvider::dpi
int dpi() const
Returns the dpi of the output device.
Definition: qgsrasterdataprovider.h:422
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsRasterDataProvider::useSourceNoDataValue
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
Definition: qgsrasterdataprovider.h:249
qgsrasteridentifyresult.h
QgsRasterDataProvider::writeXml
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
Definition: qgsrasterdataprovider.cpp:606
QgsRasterDataProvider::ResamplingMethod::Cubic
@ Cubic
Bicubic resamplikng.
QgsRasterDataProvider::transformCoordinates
virtual QgsPoint transformCoordinates(const QgsPoint &point, TransformType type)
Transforms coordinates between source image coordinate space [0..width]x[0..height] and layer coordin...
Definition: qgsrasterdataprovider.cpp:531
QgsPointXY::x
Q_GADGET double x
Definition: qgspointxy.h:47
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsRaster::IdentifyFormatText
@ IdentifyFormatText
Definition: qgsraster.h:61
QgsRasterDataProvider::write
virtual bool write(void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
Definition: qgsrasterdataprovider.h:456
QgsRasterDataProvider::copyBaseSettings
void copyBaseSettings(const QgsRasterDataProvider &other)
Copy member variables from other raster data provider. Useful for implementation of clone() method in...
Definition: qgsrasterdataprovider.cpp:544
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsRasterDataProvider::mSrcHasNoDataValue
QList< bool > mSrcHasNoDataValue
Source no data value exists.
Definition: qgsrasterdataprovider.h:715
QgsRasterDataProvider::extent
QgsRectangle extent() const override=0
Returns the extent of the layer.
QgsRaster::IdentifyFormatHtml
@ IdentifyFormatHtml
Definition: qgsraster.h:62
QgsRasterBlock::width
int width() const SIP_HOLDGIL
Returns the width (number of columns) of the raster block.
Definition: qgsrasterblock.h:643
QgsRasterDataProvider::lastErrorFormat
virtual QString lastErrorFormat()
Returns the format of the error text for the last error in this provider.
Definition: qgsrasterdataprovider.cpp:348
QgsRasterInterface::IdentifyFeature
@ IdentifyFeature
Definition: qgsrasterinterface.h:194
QgsRasterDataProvider::mZoomedInResamplingMethod
ResamplingMethod mZoomedInResamplingMethod
Resampling method for zoomed in pixel extraction.
Definition: qgsrasterdataprovider.h:736
QgsRasterDataProvider::mProviderResamplingEnabled
bool mProviderResamplingEnabled
Whether provider resampling is enabled.
Definition: qgsrasterdataprovider.h:733
QgsRasterBlock::bits
char * bits(int row, int column)
Returns a pointer to block data.
Definition: qgsrasterblock.cpp:516
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsRasterDataProvider::mZoomedOutResamplingMethod
ResamplingMethod mZoomedOutResamplingMethod
Resampling method for zoomed out pixel extraction.
Definition: qgsrasterdataprovider.h:739
QgsRasterDataProvider::bandOffset
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
Definition: qgsrasterdataprovider.h:238
QgsRasterDataProvider::enableProviderResampling
virtual bool enableProviderResampling(bool enable)
Enable or disable provider-level resampling.
Definition: qgsrasterdataprovider.h:594
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsRasterDataProvider::mUserNoDataValue
QList< QgsRasterRangeList > mUserNoDataValue
List of lists of user defined additional no data values for each band, indexed from 0.
Definition: qgsrasterdataprovider.h:728
QgsRasterDataProvider::ResamplingMethod::Bilinear
@ Bilinear
Bilinear resamplikng.
QgsRasterDataProvider::identifyFormatFromName
static QgsRaster::IdentifyFormat identifyFormatFromName(const QString &formatName)
Definition: qgsrasterdataprovider.cpp:495
QgsRasterDataProvider::setZoomedInResamplingMethod
virtual bool setZoomedInResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-in operations.
Definition: qgsrasterdataprovider.h:627
QgsRasterDataProvider::nativeResolutions
virtual QList< double > nativeResolutions() const
Returns a list of native resolutions if available, i.e.
Definition: qgsrasterdataprovider.cpp:521
QgsRasterDataProvider::sourceHasNoDataValue
virtual bool sourceHasNoDataValue(int bandNo) const
Returns true if source band has no data value.
Definition: qgsrasterdataprovider.h:246
qgsapplication.h
QgsProviderRegistry::pyramidResamplingMethods
QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns list of raster pyramid resampling methods.
Definition: qgsproviderregistry.cpp:486
QgsRasterBlock::subRect
static QRect subRect(const QgsRectangle &extent, int width, int height, const QgsRectangle &subExtent)
For extent and width, height find rectangle covered by subextent.
Definition: qgsrasterblock.cpp:770
QgsRasterInterface::NoCapabilities
@ NoCapabilities
Definition: qgsrasterinterface.h:185
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
QgsRasterDataProvider::block
QgsRasterBlock * block(int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
Definition: qgsrasterdataprovider.cpp:46
QgsRasterDataProvider::ResamplingMethod
ResamplingMethod
Resampling method for provider-level resampling.
Definition: qgsrasterdataprovider.h:615
qgsprovidermetadata.h
QgsRaster::IdentifyFormatValue
@ IdentifyFormatValue
Definition: qgsraster.h:60
QgsRasterInterface::IdentifyValue
@ IdentifyValue
Definition: qgsrasterinterface.h:191
qgsproviderregistry.h
QgsRasterInterface::xSize
virtual int xSize() const
Gets raster size.
Definition: qgsrasterinterface.h:241
QgsRasterIdentifyResult
Raster identify results container.
Definition: qgsrasteridentifyresult.h:31
QgsProviderRegistry::createRasterDataProvider
virtual 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.
Definition: qgsproviderregistry.cpp:474
QgsRasterDataProvider::writeBlock
bool writeBlock(QgsRasterBlock *block, int band, int xOffset=0, int yOffset=0)
Writes pixel data from a raster block into the provider data source.
Definition: qgsrasterdataprovider.cpp:353
QgsRasterDataProvider::providerCapabilities
virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
Definition: qgsrasterdataprovider.cpp:245
QgsRasterDataProvider::mMaxOversampling
double mMaxOversampling
Maximum boundary for oversampling (to avoid too much data traffic). Default: 2.0.
Definition: qgsrasterdataprovider.h:742
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:315
QgsRasterDataProvider::sample
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.
Definition: qgsrasterdataprovider.cpp:330
QgsRasterDataProvider::temporalCapabilities
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
Definition: qgsrasterdataprovider.cpp:427
QgsRasterBlock::setIsNoDataExcept
bool setIsNoDataExcept(QRect exceptRect)
Set the whole block to no data except specified rectangle.
Definition: qgsrasterblock.cpp:296
QgsRasterDataProvider::NoProviderCapabilities
@ NoProviderCapabilities
Provider has no capabilities.
Definition: qgsrasterdataprovider.h:100
QgsRasterDataProvider::pyramidResamplingMethods
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
Definition: qgsrasterdataprovider.cpp:366
QgsRasterDataProvider::identify
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.
Definition: qgsrasterdataprovider.cpp:265
QgsRectangle::setXMinimum
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
Definition: qgsrectangle.h:130
QgsRasterBlock::setError
void setError(const QgsError &error)
Sets the last error.
Definition: qgsrasterblock.h:622
QgsRasterDataProvider::bandScale
virtual double bandScale(int bandNo) const
Read band scale for raster value.
Definition: qgsrasterdataprovider.h:232
QgsRasterRangeList
QList< QgsRasterRange > QgsRasterRangeList
Definition: qgsrasterrange.h:26
QgsRasterDataProvider::sourceNoDataValue
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
Definition: qgsrasterdataprovider.h:255
QgsRasterBlock::height
int height() const SIP_HOLDGIL
Returns the height (number of rows) of the raster block.
Definition: qgsrasterblock.h:650
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsRasterRange::contains
bool contains(double value) const
Returns true if this range contains the specified value.
Definition: qgsrasterrange.h:114
QgsRasterBlock::isEmpty
bool isEmpty() const
Returns true if block is empty, i.e.
Definition: qgsrasterblock.cpp:130
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsRectangle::setXMaximum
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
Definition: qgsrectangle.h:135
QgsRasterDataProvider::ignoreExtents
virtual bool ignoreExtents() const
Returns true if the extents reported by the data provider are not reliable and it's possible that the...
Definition: qgsrasterdataprovider.cpp:526
QgsRaster::IdentifyFormatFeature
@ IdentifyFormatFeature
Definition: qgsraster.h:63
QgsRasterInterface::ySize
virtual int ySize() const
Definition: qgsrasterinterface.h:242
QgsRasterDataProvider::TransformType
TransformType
Types of transformation in transformCoordinates() function.
Definition: qgsrasterdataprovider.h:568
QgsRectangle::toString
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
Definition: qgsrectangle.cpp:127
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsRasterDataProvider::setMaxOversampling
virtual bool setMaxOversampling(double factor)
Sets maximum oversampling factor for zoomed-out operations.
Definition: qgsrasterdataprovider.h:655
QgsRectangle::setYMaximum
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
Definition: qgsrectangle.h:145
QgsRasterDataProvider::identifyFormatLabel
static QString identifyFormatLabel(QgsRaster::IdentifyFormat format)
Definition: qgsrasterdataprovider.cpp:478
QgsRasterDataProvider::identifyFormatToCapability
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
Definition: qgsrasterdataprovider.cpp:504
QgsRasterInterface::mHistograms
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
Definition: qgsrasterinterface.h:473
QgsRasterDataProvider::buildPyramidList
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Returns the raster layers pyramid list.
Definition: qgsrasterdataprovider.h:341
QgsRasterInterface
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:117
QgsRasterDataProvider::userNoDataValues
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
Definition: qgsrasterdataprovider.h:260
QgsRasterBlock::setValid
void setValid(bool valid) SIP_HOLDGIL
Mark block as valid or invalid.
Definition: qgsrasterblock.h:71
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
QgsRectangle::setYMinimum
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
Definition: qgsrectangle.h:140
QgsRasterBlock::setNoDataValue
void setNoDataValue(double noDataValue) SIP_HOLDGIL
Sets cell value that will be considered as "no data".
Definition: qgsrasterblock.cpp:222
QgsRasterInterface::Capability
Capability
If you add to this, please also add to capabilitiesString()
Definition: qgsrasterinterface.h:184
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsRasterDataProvider::mUseSrcNoDataValue
QList< bool > mUseSrcNoDataValue
Use source nodata value.
Definition: qgsrasterdataprovider.h:722
QgsRasterInterface::IdentifyText
@ IdentifyText
Definition: qgsrasterinterface.h:192
QgsRasterDataProvider::readBlock
virtual bool readBlock(int bandNo, int xBlock, int yBlock, void *data)
Reads a block of raster data into data.
Definition: qgsrasterdataprovider.h:682
QgsRasterDataProvider::setUseSourceNoDataValue
virtual void setUseSourceNoDataValue(int bandNo, bool use)
Sets the source nodata value usage.
Definition: qgsrasterdataprovider.cpp:34
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition: qgsrasterinterface.h:41
QgsRasterBlock::applyScaleOffset
void applyScaleOffset(double scale, double offset)
Apply band scale and offset to raster block values.
Definition: qgsrasterblock.cpp:570
QgsRasterDataProvider::QgsRasterDataProvider
QgsRasterDataProvider()
Provider capabilities.
Definition: qgsrasterdataprovider.cpp:229
QgsDataProvider::uri
QgsDataSourceUri uri() const
Gets the data source specification.
Definition: qgsdataprovider.h:197
QgsRasterDataProvider::isEditable
virtual bool isEditable() const
Checks whether the provider is in editing mode, i.e.
Definition: qgsrasterdataprovider.h:439
QgsRasterDataProvider::setZoomedOutResamplingMethod
virtual bool setZoomedOutResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-out operations.
Definition: qgsrasterdataprovider.h:641
QgsRasterDataProvider::userNoDataValuesContains
bool userNoDataValuesContains(int bandNo, double value) const
Returns true if user no data contains value.
Definition: qgsrasterdataprovider.cpp:538
QgsRasterInterface::bandCount
virtual int bandCount() const =0
Gets number of bands.
QgsRasterDataProvider::create
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.
Definition: qgsrasterdataprovider.cpp:437
qgslogger.h
QgsRasterDataProvider::identifyFormatName
static QString identifyFormatName(QgsRaster::IdentifyFormat format)
Definition: qgsrasterdataprovider.cpp:461
QgsRasterDataProvider::mExtent
QgsRectangle mExtent
Definition: qgsrasterdataprovider.h:730
QgsRasterDataProvider::hasPyramids
bool hasPyramids()
Returns true if raster has at least one populated histogram.
Definition: qgsrasterdataprovider.cpp:376
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:48
QgsRectangle::isEmpty
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:437
QgsRaster::IdentifyFormat
IdentifyFormat
Definition: qgsraster.h:58
QgsRasterDataProvider::htmlMetadata
virtual QString htmlMetadata()=0
Returns metadata in a format suitable for feeding directly into a subset of the GUI raster properties...
Definition: qgsrasterdataprovider.cpp:256
QgsRasterInterface::capabilities
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
Definition: qgsrasterinterface.h:206
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:89
QgsRasterInterface::dataTypeSize
int dataTypeSize(int bandNo)
Definition: qgsrasterinterface.h:231
QgsRasterBlock
Raster data container.
Definition: qgsrasterblock.h:37
QgsRasterDataProviderTemporalCapabilities
Implementation of data provider temporal properties for QgsRasterDataProviders.
Definition: qgsrasterdataprovidertemporalcapabilities.h:38
qgsrasterdataprovider.h
qgsmessagelog.h
QgsDataProvider::crs
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
QgsRasterBlock::setIsNoData
bool setIsNoData(int row, int column) SIP_HOLDGIL
Set no data on pixel.
Definition: qgsrasterblock.h:432
QgsRaster::IdentifyFormatUndefined
@ IdentifyFormatUndefined
Definition: qgsraster.h:59
qgssize
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:768
QgsRasterDataProvider::mDpi
int mDpi
Dots per inch.
Definition: qgsrasterdataprovider.h:703