QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsrasterlayer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterlayer.cpp - description
3  -------------------
4 begin : Sat Jun 22 2002
5 copyright : (C) 2003 by Tim Sutton, Steve Halasz and Gary E.Sherman
6 email : tim at linfiniti.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 #include "qgsapplication.h"
19 #include "qgscolorrampshader.h"
21 #include "qgscoordinatetransform.h"
22 #include "qgsdatasourceuri.h"
23 #include "qgshuesaturationfilter.h"
25 #include "qgslogger.h"
26 #include "qgsmaplayerlegend.h"
27 #include "qgsmaptopixel.h"
28 #include "qgsmessagelog.h"
30 #include "qgspainting.h"
32 #include "qgspathresolver.h"
34 #include "qgsproviderregistry.h"
35 #include "qgsrasterdataprovider.h"
36 #include "qgsrasterdrawer.h"
37 #include "qgsrasteriterator.h"
38 #include "qgsrasterlayer.h"
39 #include "qgsrasterlayerrenderer.h"
40 #include "qgsrasterprojector.h"
41 #include "qgsrasterrange.h"
44 #include "qgsrastershader.h"
45 #include "qgsreadwritecontext.h"
46 #include "qgsrectangle.h"
47 #include "qgsrendercontext.h"
51 #include "qgssettings.h"
52 #include "qgssymbollayerutils.h"
53 #include "qgsgdalprovider.h"
57 #include "qgsruntimeprofiler.h"
58 
59 #include <cmath>
60 #include <cstdio>
61 #include <limits>
62 #include <typeinfo>
63 
64 #include <QApplication>
65 #include <QCursor>
66 #include <QDir>
67 #include <QDomElement>
68 #include <QDomNode>
69 #include <QFile>
70 #include <QFileInfo>
71 #include <QFont>
72 #include <QFontMetrics>
73 #include <QFrame>
74 #include <QImage>
75 #include <QLabel>
76 #include <QList>
77 #include <QMatrix>
78 #include <QMessageBox>
79 #include <QPainter>
80 #include <QPixmap>
81 #include <QRegExp>
82 #include <QSlider>
83 
84 #define ERR(message) QGS_ERROR_MESSAGE(message,"Raster layer")
85 
86 const double QgsRasterLayer::SAMPLE_SIZE = 250000;
87 
94 
101 
103  : QgsMapLayer( QgsMapLayerType::RasterLayer )
104  , QSTRING_NOT_SET( QStringLiteral( "Not Set" ) )
105  , TRSTRING_NOT_SET( tr( "Not Set" ) )
106  , mTemporalProperties( new QgsRasterLayerTemporalProperties( this ) )
107 
108 {
109  init();
110  setValid( false );
111 }
112 
113 QgsRasterLayer::QgsRasterLayer( const QString &uri,
114  const QString &baseName,
115  const QString &providerKey,
116  const LayerOptions &options )
117  : QgsMapLayer( QgsMapLayerType::RasterLayer, baseName, uri )
118  // Constant that signals property not used.
119  , QSTRING_NOT_SET( QStringLiteral( "Not Set" ) )
120  , TRSTRING_NOT_SET( tr( "Not Set" ) )
121  , mTemporalProperties( new QgsRasterLayerTemporalProperties( this ) )
122 {
124 
125  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
126  setProviderType( providerKey );
127 
128  QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
129 
130  setDataSource( uri, baseName, providerKey, providerOptions, options.loadDefaultStyle );
131 
132  if ( isValid() )
133  {
134  mTemporalProperties->setDefaultsFromDataProviderTemporalCapabilities( mDataProvider->temporalCapabilities() );
135  }
136 
137 } // QgsRasterLayer ctor
138 
140 {
141  emit willBeDeleted();
142 
143  setValid( false );
144  // Note: provider and other interfaces are owned and deleted by pipe
145 }
146 
148 {
150  if ( mDataProvider )
151  {
152  options.transformContext = mDataProvider->transformContext();
153  }
154  QgsRasterLayer *layer = new QgsRasterLayer( source(), name(), mProviderKey, options );
155  QgsMapLayer::clone( layer );
156 
157  // do not clone data provider which is the first element in pipe
158  for ( int i = 1; i < mPipe.size(); i++ )
159  {
160  if ( mPipe.at( i ) )
161  layer->pipe()->set( mPipe.at( i )->clone() );
162  }
163 
164  return layer;
165 }
166 
168 //
169 // Static Methods and members
170 //
172 
173 bool QgsRasterLayer::isValidRasterFileName( const QString &fileNameQString, QString &retErrMsg )
174 {
175  bool myIsValid = QgsGdalProvider::isValidRasterFileName( fileNameQString, retErrMsg );
176  return myIsValid;
177 }
178 
179 bool QgsRasterLayer::isValidRasterFileName( QString const &fileNameQString )
180 {
181  QString retErrMsg;
182  return isValidRasterFileName( fileNameQString, retErrMsg );
183 }
184 
185 QDateTime QgsRasterLayer::lastModified( QString const &name )
186 {
187  QgsDebugMsgLevel( "name=" + name, 4 );
188  QDateTime t;
189 
190  QFileInfo fi( name );
191 
192  // Is it file?
193  if ( !fi.exists() )
194  return t;
195 
196  t = fi.lastModified();
197 
198  QgsDebugMsgLevel( "last modified = " + t.toString(), 4 );
199 
200  return t;
201 }
202 
203 void QgsRasterLayer::setDataProvider( const QString &provider )
204 {
206 }
207 
208 // typedef for the QgsDataProvider class factory
209 typedef QgsDataProvider *classFactoryFunction_t( const QString *, const QgsDataProvider::ProviderOptions &options );
210 
212 //
213 // Non Static Public methods
214 //
216 
218 {
219  if ( !mDataProvider ) return 0;
220  return mDataProvider->bandCount();
221 }
222 
223 QString QgsRasterLayer::bandName( int bandNo ) const
224 {
225  if ( !mDataProvider ) return QString();
226  return mDataProvider->generateBandName( bandNo );
227 }
228 
229 void QgsRasterLayer::setRendererForDrawingStyle( QgsRaster::DrawingStyle drawingStyle )
230 {
231  setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( drawingStyle, mDataProvider ) );
232 }
233 
235 {
236  return mDataProvider;
237 }
238 
240 {
241  return mDataProvider;
242 }
243 
245 {
246  if ( mDataProvider )
247  {
248  mDataProvider->reloadData();
249  }
250 }
251 
253 {
254  return new QgsRasterLayerRenderer( this, rendererContext );
255 }
256 
257 
258 void QgsRasterLayer::draw( QPainter *theQPainter,
259  QgsRasterViewPort *rasterViewPort,
260  const QgsMapToPixel *qgsMapToPixel )
261 {
262  QgsDebugMsgLevel( QStringLiteral( " 3 arguments" ), 4 );
263  QElapsedTimer time;
264  time.start();
265  //
266  //
267  // The goal here is to make as many decisions as possible early on (outside of the rendering loop)
268  // so that we can maximise performance of the rendering process. So now we check which drawing
269  // procedure to use :
270  //
271 
272  QgsRasterProjector *projector = mPipe.projector();
273  bool restoreOldResamplingStage = false;
274  QgsRasterPipe::ResamplingStage oldResamplingState = resamplingStage();
275  // TODO add a method to interface to get provider and get provider
276  // params in QgsRasterProjector
277 
278  if ( projector )
279  {
280  // Force provider resampling if reprojection is needed
281  if ( mDataProvider != nullptr &&
283  rasterViewPort->mSrcCRS != rasterViewPort->mDestCRS &&
284  oldResamplingState != QgsRasterPipe::ResamplingStage::Provider )
285  {
286  restoreOldResamplingStage = true;
288  }
289  projector->setCrs( rasterViewPort->mSrcCRS, rasterViewPort->mDestCRS, rasterViewPort->mTransformContext );
290  }
291 
292  // Drawer to pipe?
293  QgsRasterIterator iterator( mPipe.last() );
294  QgsRasterDrawer drawer( &iterator );
295  drawer.draw( theQPainter, rasterViewPort, qgsMapToPixel );
296 
297  if ( restoreOldResamplingStage )
298  {
299  setResamplingStage( oldResamplingState );
300  }
301 
302  QgsDebugMsgLevel( QStringLiteral( "total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
303 } //end of draw method
304 
306 {
307  QList< QPair< QString, QColor > > symbolList;
309  if ( renderer )
310  {
311  renderer->legendSymbologyItems( symbolList );
312  }
313  return symbolList;
314 }
315 
317 {
318  QgsLayerMetadataFormatter htmlFormatter( metadata() );
319  QString myMetadata = QStringLiteral( "<html><head></head>\n<body>\n" );
320 
321  // Begin Provider section
322  myMetadata += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" ) %
323  QStringLiteral( "<table class=\"list-view\">\n" ) %
324 
325  // name
326  QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Name" ) % QStringLiteral( "</td><td>" ) % name() % QStringLiteral( "</td></tr>\n" );
327 
328  // local path
329  QVariantMap uriComponents = QgsProviderRegistry::instance()->decodeUri( mProviderKey, publicSource() );
330  QString path;
331  if ( uriComponents.contains( QStringLiteral( "path" ) ) )
332  {
333  path = uriComponents[QStringLiteral( "path" )].toString();
334  if ( QFile::exists( path ) )
335  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Path" ) % QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), QDir::toNativeSeparators( path ) ) ) + QStringLiteral( "</td></tr>\n" );
336  }
337  if ( uriComponents.contains( QStringLiteral( "url" ) ) )
338  {
339  const QString url = uriComponents[QStringLiteral( "url" )].toString();
340  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "URL" ) % QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl( url ).toString(), url ) ) + QStringLiteral( "</td></tr>\n" );
341  }
342 
343  // data source
344  if ( publicSource() != path )
345  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Source" ) + QStringLiteral( "</td><td>%1" ).arg( publicSource() ) + QStringLiteral( "</td></tr>\n" );
346 
347  // EPSG
348  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "CRS" ) + QStringLiteral( "</td><td>" );
349  if ( crs().isValid() )
350  {
351  myMetadata += crs().userFriendlyIdentifier( QgsCoordinateReferenceSystem::FullString ) % QStringLiteral( " - " );
352  if ( crs().isGeographic() )
353  myMetadata += tr( "Geographic" );
354  else
355  myMetadata += tr( "Projected" );
356  }
357  myMetadata += QStringLiteral( "</td></tr>\n" ) %
358 
359  // Extent
360  QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Extent" ) % QStringLiteral( "</td><td>" ) % extent().toString() % QStringLiteral( "</td></tr>\n" ) %
361 
362  // unit
363  QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Unit" ) % QStringLiteral( "</td><td>" ) % QgsUnitTypes::toString( crs().mapUnits() ) % QStringLiteral( "</td></tr>\n" ) %
364 
365  // Raster Width
366  QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Width" ) % QStringLiteral( "</td><td>" );
367  if ( dataProvider()->capabilities() & QgsRasterDataProvider::Size )
368  myMetadata += QString::number( width() );
369  else
370  myMetadata += tr( "n/a" );
371  myMetadata += QStringLiteral( "</td></tr>\n" ) %
372 
373  // Raster height
374  QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Height" ) + QStringLiteral( "</td><td>" );
375  if ( dataProvider()->capabilities() & QgsRasterDataProvider::Size )
376  myMetadata += QString::number( height() );
377  else
378  myMetadata += tr( "n/a" );
379  myMetadata += QStringLiteral( "</td></tr>\n" ) %
380 
381  // Data type
382  QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Data type" ) % QStringLiteral( "</td><td>" );
383  // Just use the first band
384  switch ( mDataProvider->sourceDataType( 1 ) )
385  {
386  case Qgis::Byte:
387  myMetadata += tr( "Byte - Eight bit unsigned integer" );
388  break;
389  case Qgis::UInt16:
390  myMetadata += tr( "UInt16 - Sixteen bit unsigned integer " );
391  break;
392  case Qgis::Int16:
393  myMetadata += tr( "Int16 - Sixteen bit signed integer " );
394  break;
395  case Qgis::UInt32:
396  myMetadata += tr( "UInt32 - Thirty two bit unsigned integer " );
397  break;
398  case Qgis::Int32:
399  myMetadata += tr( "Int32 - Thirty two bit signed integer " );
400  break;
401  case Qgis::Float32:
402  myMetadata += tr( "Float32 - Thirty two bit floating point " );
403  break;
404  case Qgis::Float64:
405  myMetadata += tr( "Float64 - Sixty four bit floating point " );
406  break;
407  case Qgis::CInt16:
408  myMetadata += tr( "CInt16 - Complex Int16 " );
409  break;
410  case Qgis::CInt32:
411  myMetadata += tr( "CInt32 - Complex Int32 " );
412  break;
413  case Qgis::CFloat32:
414  myMetadata += tr( "CFloat32 - Complex Float32 " );
415  break;
416  case Qgis::CFloat64:
417  myMetadata += tr( "CFloat64 - Complex Float64 " );
418  break;
419  default:
420  myMetadata += tr( "Could not determine raster data type." );
421  }
422  myMetadata += QStringLiteral( "</td></tr>\n" ) %
423 
424  // Insert provider-specific (e.g. WMS-specific) metadata
425  mDataProvider->htmlMetadata() %
426 
427  // End Provider section
428  QStringLiteral( "</table>\n<br><br>" ) %
429 
430  // Identification section
431  QStringLiteral( "<h1>" ) % tr( "Identification" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
432  htmlFormatter.identificationSectionHtml() %
433  QStringLiteral( "<br><br>\n" ) %
434 
435  // extent section
436  QStringLiteral( "<h1>" ) % tr( "Extent" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
437  htmlFormatter.extentSectionHtml( ) %
438  QStringLiteral( "<br><br>\n" ) %
439 
440  // Start the Access section
441  QStringLiteral( "<h1>" ) % tr( "Access" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
442  htmlFormatter.accessSectionHtml( ) %
443  QStringLiteral( "<br><br>\n" ) %
444 
445  // Bands section
446  QStringLiteral( "</table>\n<br><br><h1>" ) % tr( "Bands" ) % QStringLiteral( "</h1>\n<hr>\n<table class=\"list-view\">\n" ) %
447 
448  // Band count
449  QStringLiteral( "<tr><td class=\"highlight\">" ) % tr( "Band count" ) % QStringLiteral( "</td><td>" ) % QString::number( bandCount() ) % QStringLiteral( "</td></tr>\n" );
450 
451  // Band table
452  myMetadata += QStringLiteral( "</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" ) %
453  QStringLiteral( "<tr><th>" ) % tr( "Number" ) % QStringLiteral( "</th><th>" ) % tr( "Band" ) % QStringLiteral( "</th><th>" ) % tr( "No-Data" ) % QStringLiteral( "</th><th>" ) %
454  tr( "Min" ) % QStringLiteral( "</th><th>" ) % tr( "Max" ) % QStringLiteral( "</th></tr>\n" );
455 
456  QgsRasterDataProvider *provider = const_cast< QgsRasterDataProvider * >( mDataProvider );
457  for ( int i = 1; i <= bandCount(); i++ )
458  {
459  QString rowClass;
460  if ( i % 2 )
461  rowClass = QStringLiteral( "class=\"odd-row\"" );
462 
463  myMetadata += QStringLiteral( "<tr " ) % rowClass % QStringLiteral( "><td>" ) % QString::number( i ) % QStringLiteral( "</td><td>" ) % bandName( i ) % QStringLiteral( "</td><td>" );
464 
465  if ( dataProvider()->sourceHasNoDataValue( i ) )
466  myMetadata += QString::number( dataProvider()->sourceNoDataValue( i ) );
467  else
468  myMetadata += tr( "n/a" );
469  myMetadata += QLatin1String( "</td>" );
470 
471  if ( provider->hasStatistics( i ) )
472  {
473  QgsRasterBandStats myRasterBandStats = provider->bandStatistics( i );
474  myMetadata += QStringLiteral( "<td>" ) % QString::number( myRasterBandStats.minimumValue, 'f', 10 ) % QStringLiteral( "</td>" ) %
475  QStringLiteral( "<td>" ) % QString::number( myRasterBandStats.maximumValue, 'f', 10 ) % QStringLiteral( "</td>" );
476  }
477  else
478  {
479  myMetadata += QStringLiteral( "<td>" ) % tr( "n/a" ) % QStringLiteral( "</td><td>" ) % tr( "n/a" ) % QStringLiteral( "</td>" );
480  }
481 
482  myMetadata += QLatin1String( "</tr>\n" );
483  }
484 
485  //close previous bands table
486  myMetadata += QStringLiteral( "</table>\n<br><br>" ) %
487 
488  // Start the contacts section
489  QStringLiteral( "<h1>" ) % tr( "Contacts" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
490  htmlFormatter.contactsSectionHtml( ) %
491  QStringLiteral( "<br><br>\n" ) %
492 
493  // Start the links section
494  QStringLiteral( "<h1>" ) % tr( "References" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
495  htmlFormatter.linksSectionHtml( ) %
496  QStringLiteral( "<br><br>\n" ) %
497 
498  // Start the history section
499  QStringLiteral( "<h1>" ) % tr( "History" ) % QStringLiteral( "</h1>\n<hr>\n" ) %
500  htmlFormatter.historySectionHtml( ) %
501  QStringLiteral( "<br><br>\n" ) %
502 
503  QStringLiteral( "\n</body>\n</html>\n" );
504  return myMetadata;
505 }
506 
507 QPixmap QgsRasterLayer::paletteAsPixmap( int bandNumber )
508 {
509  //TODO: This function should take dimensions
510  QgsDebugMsgLevel( QStringLiteral( "entered." ), 4 );
511 
512  // Only do this for the GDAL provider?
513  // Maybe WMS can do this differently using QImage::numColors and QImage::color()
514  if ( mDataProvider &&
515  mDataProvider->colorInterpretation( bandNumber ) == QgsRaster::PaletteIndex )
516  {
517  QgsDebugMsgLevel( QStringLiteral( "....found paletted image" ), 4 );
518  QgsColorRampShader myShader;
519  QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->colorTable( bandNumber );
520  if ( !myColorRampItemList.isEmpty() )
521  {
522  QgsDebugMsgLevel( QStringLiteral( "....got color ramp item list" ), 4 );
523  myShader.setColorRampItemList( myColorRampItemList );
525  // Draw image
526  int mySize = 100;
527  QPixmap myPalettePixmap( mySize, mySize );
528  QPainter myQPainter( &myPalettePixmap );
529 
530  QImage myQImage = QImage( mySize, mySize, QImage::Format_RGB32 );
531  myQImage.fill( 0 );
532  myPalettePixmap.fill();
533 
534  double myStep = ( static_cast< double >( myColorRampItemList.size() ) - 1 ) / static_cast< double >( mySize * mySize );
535  double myValue = 0.0;
536  for ( int myRow = 0; myRow < mySize; myRow++ )
537  {
538  QRgb *myLineBuffer = reinterpret_cast< QRgb * >( myQImage.scanLine( myRow ) );
539  for ( int myCol = 0; myCol < mySize; myCol++ )
540  {
541  myValue = myStep * static_cast< double >( myCol + myRow * mySize );
542  int c1, c2, c3, c4;
543  myShader.shade( myValue, &c1, &c2, &c3, &c4 );
544  myLineBuffer[ myCol ] = qRgba( c1, c2, c3, c4 );
545  }
546  }
547 
548  myQPainter.drawImage( 0, 0, myQImage );
549  return myPalettePixmap;
550  }
551  QPixmap myNullPixmap;
552  return myNullPixmap;
553  }
554  else
555  {
556  //invalid layer was requested
557  QPixmap myNullPixmap;
558  return myNullPixmap;
559  }
560 }
561 
563 {
564  return mProviderKey;
565 }
566 
568 {
569 // We return one raster pixel per map unit pixel
570 // One raster pixel can have several raster units...
571 
572 // We can only use one of the mGeoTransform[], so go with the
573 // horisontal one.
574 
575  if ( mDataProvider &&
576  mDataProvider->capabilities() & QgsRasterDataProvider::Size && !qgsDoubleNear( mDataProvider->xSize(), 0.0 ) )
577  {
578  return mDataProvider->extent().width() / mDataProvider->xSize();
579  }
580  return 1;
581 }
582 
584 {
585  if ( mDataProvider &&
586  mDataProvider->capabilities() & QgsRasterDataProvider::Size && !qgsDoubleNear( mDataProvider->ySize(), 0.0 ) )
587  {
588  return mDataProvider->extent().height() / mDataProvider->ySize();
589  }
590  return 1;
591 }
592 
593 void QgsRasterLayer::init()
594 {
595  mRasterType = QgsRasterLayer::GrayOrUndefined;
596 
598 
599  setRendererForDrawingStyle( QgsRaster::UndefinedDrawingStyle );
600 
601  //Initialize the last view port structure, should really be a class
602  mLastViewPort.mWidth = 0;
603  mLastViewPort.mHeight = 0;
604 }
605 
606 void QgsRasterLayer::setDataProvider( QString const &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
607 {
608  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
609  setValid( false ); // assume the layer is invalid until we determine otherwise
610 
611  mPipe.remove( mDataProvider ); // deletes if exists
612  mDataProvider = nullptr;
613 
614  // XXX should I check for and possibly delete any pre-existing providers?
615  // XXX How often will that scenario occur?
616 
617  mProviderKey = provider;
618  // set the layer name (uppercase first character)
619  if ( ! mLayerName.isEmpty() ) // XXX shouldn't this happen in parent?
620  {
621  setName( mLayerName );
622  }
623 
624  //mBandCount = 0;
625 
626  std::unique_ptr< QgsScopedRuntimeProfile > profile;
627  if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
628  profile = qgis::make_unique< QgsScopedRuntimeProfile >( tr( "Create %1 provider" ).arg( provider ), QStringLiteral( "projectload" ) );
629 
630  mDataProvider = qobject_cast< QgsRasterDataProvider * >( QgsProviderRegistry::instance()->createProvider( mProviderKey, mDataSource, options, flags ) );
631  if ( !mDataProvider )
632  {
633  //QgsMessageLog::logMessage( tr( "Cannot instantiate the data provider" ), tr( "Raster" ) );
634  appendError( ERR( tr( "Cannot instantiate the '%1' data provider" ).arg( mProviderKey ) ) );
635  return;
636  }
637  QgsDebugMsgLevel( QStringLiteral( "Data provider created" ), 4 );
638  mDataProvider->setParent( this );
639 
640  // Set data provider into pipe even if not valid so that it is deleted with pipe (with layer)
641  mPipe.set( mDataProvider );
642  if ( !mDataProvider->isValid() )
643  {
644  setError( mDataProvider->error() );
645  appendError( ERR( tr( "Provider is not valid (provider: %1, URI: %2" ).arg( mProviderKey, mDataSource ) ) );
646  return;
647  }
648 
650  {
651  setMetadata( mDataProvider->layerMetadata() );
652  QgsDebugMsgLevel( QStringLiteral( "Set Data provider QgsLayerMetadata identifier[%1]" ).arg( metadata().identifier() ), 4 );
653  }
654 
655  if ( provider == QLatin1String( "gdal" ) )
656  {
657  // make sure that the /vsigzip or /vsizip is added to uri, if applicable
658  mDataSource = mDataProvider->dataSourceUri();
659  }
660 
661  // get the extent
662  QgsRectangle mbr = mDataProvider->extent();
663 
664  // show the extent
665  QgsDebugMsgLevel( "Extent of layer: " + mbr.toString(), 4 );
666  // store the extent
667  setExtent( mbr );
668 
669  // upper case the first letter of the layer name
670  QgsDebugMsgLevel( "mLayerName: " + name(), 4 );
671 
672  // set up the raster drawing style
673  // Do not set any 'sensible' style here, the style is set later
674 
675  // Setup source CRS
676  setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) );
677 
678  QgsDebugMsgLevel( "using wkt:\n" + crs().toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ), 4 );
679 
680  //defaults - Needs to be set after the Contrast list has been build
681  //Try to read the default contrast enhancement from the config file
682 
683  //decide what type of layer this is...
684  //TODO Change this to look at the color interp and palette interp to decide which type of layer it is
685  QgsDebugMsgLevel( "bandCount = " + QString::number( mDataProvider->bandCount() ), 4 );
686  QgsDebugMsgLevel( "dataType = " + QString::number( mDataProvider->dataType( 1 ) ), 4 );
687  if ( ( mDataProvider->bandCount() > 1 ) )
688  {
689  // handle singleband gray with alpha
690  if ( mDataProvider->bandCount() == 2
691  && ( ( mDataProvider->colorInterpretation( 1 ) == QgsRaster::GrayIndex
692  && mDataProvider->colorInterpretation( 2 ) == QgsRaster::AlphaBand )
693  || ( mDataProvider->colorInterpretation( 1 ) == QgsRaster::AlphaBand
694  && mDataProvider->colorInterpretation( 2 ) == QgsRaster::GrayIndex ) ) )
695  {
696  mRasterType = GrayOrUndefined;
697  }
698  else
699  {
700  mRasterType = Multiband;
701  }
702  }
703  else if ( mDataProvider->dataType( 1 ) == Qgis::ARGB32
704  || mDataProvider->dataType( 1 ) == Qgis::ARGB32_Premultiplied )
705  {
706  mRasterType = ColorLayer;
707  }
708  else if ( mDataProvider->colorInterpretation( 1 ) == QgsRaster::PaletteIndex )
709  {
710  mRasterType = Palette;
711  }
712  else if ( mDataProvider->colorInterpretation( 1 ) == QgsRaster::ContinuousPalette )
713  {
714  mRasterType = Palette;
715  }
716  else
717  {
718  mRasterType = GrayOrUndefined;
719  }
720 
721  QgsDebugMsgLevel( "mRasterType = " + QString::number( mRasterType ), 4 );
722  if ( mRasterType == ColorLayer )
723  {
724  QgsDebugMsgLevel( "Setting drawing style to SingleBandColorDataStyle " + QString::number( QgsRaster::SingleBandColorDataStyle ), 4 );
725  setRendererForDrawingStyle( QgsRaster::SingleBandColorDataStyle );
726  }
727  else if ( mRasterType == Palette && mDataProvider->colorInterpretation( 1 ) == QgsRaster::PaletteIndex )
728  {
729  setRendererForDrawingStyle( QgsRaster::PalettedColor ); //sensible default
730  }
731  else if ( mRasterType == Palette && mDataProvider->colorInterpretation( 1 ) == QgsRaster::ContinuousPalette )
732  {
733  setRendererForDrawingStyle( QgsRaster::SingleBandPseudoColor );
734  // Load color table
735  QList<QgsColorRampShader::ColorRampItem> colorTable = mDataProvider->colorTable( 1 );
737  if ( r )
738  {
739  // TODO: this should go somewhere else
740  QgsRasterShader *shader = new QgsRasterShader();
741  QgsColorRampShader *colorRampShader = new QgsColorRampShader();
743  colorRampShader->setColorRampItemList( colorTable );
744  shader->setRasterShaderFunction( colorRampShader );
745  r->setShader( shader );
746  }
747  }
748  else if ( mRasterType == Multiband )
749  {
750  setRendererForDrawingStyle( QgsRaster::MultiBandColor ); //sensible default
751  }
752  else //GrayOrUndefined
753  {
754  setRendererForDrawingStyle( QgsRaster::SingleBandGray ); //sensible default
755  }
756 
757  // Auto set alpha band
758  for ( int bandNo = 1; bandNo <= mDataProvider->bandCount(); bandNo++ )
759  {
760  if ( mDataProvider->colorInterpretation( bandNo ) == QgsRaster::AlphaBand )
761  {
762  if ( auto *lRenderer = mPipe.renderer() )
763  {
764  lRenderer->setAlphaBand( bandNo );
765  }
766  break;
767  }
768  }
769 
770  // brightness filter
772  mPipe.set( brightnessFilter );
773 
774  // hue/saturation filter
776  mPipe.set( hueSaturationFilter );
777 
778  // resampler (must be after renderer)
780  mPipe.set( resampleFilter );
781 
783  {
784  QgsSettings settings;
785  QString resampling = settings.value( QStringLiteral( "/Raster/defaultZoomedInResampling" ), QStringLiteral( "nearest neighbour" ) ).toString();
786  if ( resampling == QLatin1String( "bilinear" ) )
787  {
790  }
791  else if ( resampling == QLatin1String( "cubic" ) )
792  {
795  }
796  resampling = settings.value( QStringLiteral( "/Raster/defaultZoomedOutResampling" ), QStringLiteral( "nearest neighbour" ) ).toString();
797  if ( resampling == QLatin1String( "bilinear" ) )
798  {
801  }
802 
803  const double maxOversampling = settings.value( QStringLiteral( "/Raster/defaultOversampling" ), 2.0 ).toDouble();
804  resampleFilter->setMaxOversampling( maxOversampling );
805  mDataProvider->setMaxOversampling( maxOversampling );
806 
808  settings.value( QStringLiteral( "/Raster/defaultEarlyResampling" ), false ).toBool() )
809  {
811  }
812  else
813  {
815  }
816  }
817 
818  // projector (may be anywhere in pipe)
819  QgsRasterProjector *projector = new QgsRasterProjector;
820  mPipe.set( projector );
821 
822  // Set default identify format - use the richest format available
823  int capabilities = mDataProvider->capabilities();
825  if ( capabilities & QgsRasterInterface::IdentifyHtml )
826  {
827  // HTML is usually richest
828  identifyFormat = QgsRaster::IdentifyFormatHtml;
829  }
830  else if ( capabilities & QgsRasterInterface::IdentifyFeature )
831  {
832  identifyFormat = QgsRaster::IdentifyFormatFeature;
833  }
834  else if ( capabilities & QgsRasterInterface::IdentifyText )
835  {
836  identifyFormat = QgsRaster::IdentifyFormatText;
837  }
838  else if ( capabilities & QgsRasterInterface::IdentifyValue )
839  {
840  identifyFormat = QgsRaster::IdentifyFormatValue;
841  }
842  setCustomProperty( QStringLiteral( "identify/format" ), QgsRasterDataProvider::identifyFormatName( identifyFormat ) );
843 
844  // Store timestamp
845  // TODO move to provider
846  mLastModified = lastModified( mDataSource );
847 
848  // Do a passthrough for the status bar text
849  connect( mDataProvider, &QgsRasterDataProvider::statusChanged, this, &QgsRasterLayer::statusChanged );
850 
851  //mark the layer as valid
852  setValid( true );
853 
854  if ( mDataProvider->supportsSubsetString() )
855  connect( this, &QgsRasterLayer::subsetStringChanged, this, &QgsMapLayer::configChanged, Qt::UniqueConnection );
856  else
858 
859 
860  QgsDebugMsgLevel( QStringLiteral( "exiting." ), 4 );
861 
862 }
863 
864 void QgsRasterLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag )
865 {
866  bool hadRenderer( renderer() );
867 
868  QDomImplementation domImplementation;
869  QDomDocumentType documentType;
870  QString errorMsg;
871 
872  // Store the original style
873  if ( hadRenderer && ! loadDefaultStyleFlag )
874  {
875  documentType = domImplementation.createDocumentType(
876  QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
877 
878  QDomDocument doc = QDomDocument( documentType );
879  QDomElement styleElem = doc.createElement( QStringLiteral( "qgis" ) );
880  styleElem.setAttribute( QStringLiteral( "version" ), Qgis::version() );
881  QgsReadWriteContext writeContext;
882  if ( ! writeSymbology( styleElem, doc, errorMsg, writeContext ) )
883  {
884  QgsDebugMsg( QStringLiteral( "Could not store symbology for layer %1: %2" )
885  .arg( name(),
886  errorMsg ) );
887  }
888  else
889  {
890  doc.appendChild( styleElem );
891 
892  mOriginalStyleDocument = doc;
893  mOriginalStyleElement = styleElem;
894  }
895  }
896 
897  if ( mDataProvider )
898  closeDataProvider();
899 
900  init();
901 
902  for ( int i = mPipe.size() - 1; i >= 0; --i )
903  {
904  mPipe.remove( i );
905  }
906 
907  mDataSource = dataSource;
908  mLayerName = baseName;
909 
910  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
912  {
914  }
915 
916  setDataProvider( provider, options, flags );
917 
918  if ( mDataProvider )
919  mDataProvider->setDataSourceUri( mDataSource );
920 
921  if ( isValid() )
922  {
923  // load default style
924  bool defaultLoadedFlag = false;
925  bool restoredStyle = false;
926  if ( loadDefaultStyleFlag )
927  {
928  loadDefaultStyle( defaultLoadedFlag );
929  }
930  else if ( !mOriginalStyleElement.isNull() ) // Restore the style
931  {
932  QgsReadWriteContext readContext;
933  if ( ! readSymbology( mOriginalStyleElement, errorMsg, readContext ) )
934  {
935  QgsDebugMsg( QStringLiteral( "Could not restore symbology for layer %1: %2" )
936  .arg( name() )
937  .arg( errorMsg ) );
938 
939  }
940  else
941  {
942  restoredStyle = true;
943  emit repaintRequested();
944  emit styleChanged();
945  emit rendererChanged();
946  }
947  }
948 
949  if ( !defaultLoadedFlag && !restoredStyle )
950  {
952  }
953  }
954  emit dataSourceChanged();
955  emit dataChanged();
956 }
957 
958 void QgsRasterLayer::closeDataProvider()
959 {
960  setValid( false );
961  mPipe.remove( mDataProvider );
962  mDataProvider = nullptr;
963 }
964 
965 void QgsRasterLayer::computeMinMax( int band,
966  const QgsRasterMinMaxOrigin &mmo,
968  const QgsRectangle &extent,
969  int sampleSize,
970  double &min, double &max )
971 {
972 
973  min = std::numeric_limits<double>::quiet_NaN();
974  max = std::numeric_limits<double>::quiet_NaN();
975  if ( !mDataProvider )
976  return;
977 
978  if ( limits == QgsRasterMinMaxOrigin::MinMax )
979  {
980  QgsRasterBandStats myRasterBandStats = mDataProvider->bandStatistics( band, QgsRasterBandStats::Min | QgsRasterBandStats::Max, extent, sampleSize );
981  min = myRasterBandStats.minimumValue;
982  max = myRasterBandStats.maximumValue;
983  }
984  else if ( limits == QgsRasterMinMaxOrigin::StdDev )
985  {
986  QgsRasterBandStats myRasterBandStats = mDataProvider->bandStatistics( band, QgsRasterBandStats::Mean | QgsRasterBandStats::StdDev, extent, sampleSize );
987  min = myRasterBandStats.mean - ( mmo.stdDevFactor() * myRasterBandStats.stdDev );
988  max = myRasterBandStats.mean + ( mmo.stdDevFactor() * myRasterBandStats.stdDev );
989  }
990  else if ( limits == QgsRasterMinMaxOrigin::CumulativeCut )
991  {
992  const double myLower = mmo.cumulativeCutLower();
993  const double myUpper = mmo.cumulativeCutUpper();
994  QgsDebugMsgLevel( QStringLiteral( "myLower = %1 myUpper = %2" ).arg( myLower ).arg( myUpper ), 4 );
995  mDataProvider->cumulativeCut( band, myLower, myUpper, min, max, extent, sampleSize );
996  }
997  QgsDebugMsgLevel( QStringLiteral( "band = %1 min = %2 max = %3" ).arg( band ).arg( min ).arg( max ), 4 );
998 
999 }
1000 
1002 {
1003  return mDataProvider ? mDataProvider->ignoreExtents() : false;
1004 }
1005 
1007 {
1008  return mTemporalProperties;
1009 }
1010 
1012 {
1014  limits,
1015  extent,
1016  sampleSize,
1017  generateLookupTableFlag,
1018  mPipe.renderer() );
1019 }
1020 
1023  const QgsRectangle &extent,
1024  int sampleSize,
1025  bool generateLookupTableFlag,
1026  QgsRasterRenderer *rasterRenderer )
1027 {
1028  QgsDebugMsgLevel( QStringLiteral( "theAlgorithm = %1 limits = %2 extent.isEmpty() = %3" ).arg( algorithm ).arg( limits ).arg( extent.isEmpty() ), 4 );
1029  if ( !rasterRenderer || !mDataProvider )
1030  {
1031  return;
1032  }
1033 
1034  QList<int> myBands;
1035  QList<QgsContrastEnhancement *> myEnhancements;
1036  QgsRasterMinMaxOrigin myMinMaxOrigin;
1037  QgsRasterRenderer *myRasterRenderer = nullptr;
1038  QgsSingleBandGrayRenderer *myGrayRenderer = nullptr;
1039  QgsSingleBandPseudoColorRenderer *myPseudoColorRenderer = nullptr;
1040  QgsMultiBandColorRenderer *myMultiBandRenderer = nullptr;
1041  QString rendererType = rasterRenderer->type();
1042  if ( rendererType == QLatin1String( "singlebandgray" ) )
1043  {
1044  myGrayRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>( rasterRenderer );
1045  if ( !myGrayRenderer )
1046  {
1047  return;
1048  }
1049  myBands << myGrayRenderer->grayBand();
1050  myRasterRenderer = myGrayRenderer;
1051  myMinMaxOrigin = myGrayRenderer->minMaxOrigin();
1052  }
1053  else if ( rendererType == QLatin1String( "multibandcolor" ) )
1054  {
1055  myMultiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>( rasterRenderer );
1056  if ( !myMultiBandRenderer )
1057  {
1058  return;
1059  }
1060  myBands << myMultiBandRenderer->redBand() << myMultiBandRenderer->greenBand() << myMultiBandRenderer->blueBand();
1061  myRasterRenderer = myMultiBandRenderer;
1062  myMinMaxOrigin = myMultiBandRenderer->minMaxOrigin();
1063  }
1064  else if ( rendererType == QLatin1String( "singlebandpseudocolor" ) )
1065  {
1066  myPseudoColorRenderer = dynamic_cast<QgsSingleBandPseudoColorRenderer *>( rasterRenderer );
1067  if ( !myPseudoColorRenderer )
1068  {
1069  return;
1070  }
1071  myBands << myPseudoColorRenderer->band();
1072  myRasterRenderer = myPseudoColorRenderer;
1073  myMinMaxOrigin = myPseudoColorRenderer->minMaxOrigin();
1074  }
1075  else
1076  {
1077  return;
1078  }
1079 
1080  const auto constMyBands = myBands;
1081  for ( int myBand : constMyBands )
1082  {
1083  if ( myBand != -1 )
1084  {
1085  Qgis::DataType myType = static_cast< Qgis::DataType >( mDataProvider->dataType( myBand ) );
1086  std::unique_ptr<QgsContrastEnhancement> myEnhancement( new QgsContrastEnhancement( static_cast< Qgis::DataType >( myType ) ) );
1087  myEnhancement->setContrastEnhancementAlgorithm( algorithm, generateLookupTableFlag );
1088 
1089  double min;
1090  double max;
1091  computeMinMax( myBand, myMinMaxOrigin, limits, extent, sampleSize, min, max );
1092 
1093  if ( rendererType == QLatin1String( "singlebandpseudocolor" ) )
1094  {
1095  myPseudoColorRenderer->setClassificationMin( min );
1096  myPseudoColorRenderer->setClassificationMax( max );
1097  if ( myPseudoColorRenderer->shader() )
1098  {
1099  QgsColorRampShader *colorRampShader = dynamic_cast<QgsColorRampShader *>( myPseudoColorRenderer->shader()->rasterShaderFunction() );
1100  if ( colorRampShader )
1101  {
1102  colorRampShader->classifyColorRamp( myPseudoColorRenderer->band(), extent, myPseudoColorRenderer->input() );
1103  }
1104  }
1105  }
1106  else
1107  {
1108  myEnhancement->setMinimumValue( min );
1109  myEnhancement->setMaximumValue( max );
1110  myEnhancements.append( myEnhancement.release() );
1111  }
1112  }
1113  else
1114  {
1115  myEnhancements.append( nullptr );
1116  }
1117  }
1118 
1119  if ( rendererType == QLatin1String( "singlebandgray" ) )
1120  {
1121  if ( myEnhancements.first() ) myGrayRenderer->setContrastEnhancement( myEnhancements.takeFirst() );
1122  }
1123  else if ( rendererType == QLatin1String( "multibandcolor" ) )
1124  {
1125  if ( myEnhancements.first() ) myMultiBandRenderer->setRedContrastEnhancement( myEnhancements.takeFirst() );
1126  if ( myEnhancements.first() ) myMultiBandRenderer->setGreenContrastEnhancement( myEnhancements.takeFirst() );
1127  if ( myEnhancements.first() ) myMultiBandRenderer->setBlueContrastEnhancement( myEnhancements.takeFirst() );
1128  }
1129 
1130  //delete all remaining unused enhancements
1131  qDeleteAll( myEnhancements );
1132 
1133  myMinMaxOrigin.setLimits( limits );
1134  if ( extent != QgsRectangle() &&
1135  myMinMaxOrigin.extent() == QgsRasterMinMaxOrigin::WholeRaster )
1136  {
1138  }
1139  if ( myRasterRenderer )
1140  {
1141  myRasterRenderer->setMinMaxOrigin( myMinMaxOrigin );
1142  }
1143 
1144  if ( rasterRenderer == renderer() )
1145  {
1146  emit repaintRequested();
1147  emit styleChanged();
1148  emit rendererChanged();
1149  }
1150 }
1151 
1153 {
1154  QgsSingleBandGrayRenderer *singleBandRenderer = nullptr;
1155  QgsMultiBandColorRenderer *multiBandRenderer = nullptr;
1156  const QgsContrastEnhancement *ce = nullptr;
1157  if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>( renderer() ) ) )
1158  {
1159  ce = singleBandRenderer->contrastEnhancement();
1160  }
1161  else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>( renderer() ) ) )
1162  {
1163  ce = multiBandRenderer->redContrastEnhancement();
1164  }
1165 
1166  if ( ce )
1167  {
1170  renderer()->minMaxOrigin().limits() == QgsRasterMinMaxOrigin::None ?
1171  QgsRasterMinMaxOrigin::MinMax : renderer()->minMaxOrigin().limits(),
1172  extent,
1173  SAMPLE_SIZE,
1174  true,
1175  renderer() );
1176  }
1177  else
1178  {
1181  if ( defaultContrastEnhancementSettings( myAlgorithm, myLimits ) )
1182  {
1184  myLimits,
1185  extent,
1186  SAMPLE_SIZE,
1187  true,
1188  renderer() );
1189  }
1190  }
1191 }
1192 
1194  const QgsRectangle &extent )
1195 {
1196  if ( mDataProvider &&
1197  mLastRectangleUsedByRefreshContrastEnhancementIfNeeded != extent &&
1198  rasterRenderer->minMaxOrigin().limits() != QgsRasterMinMaxOrigin::None &&
1200  {
1201  refreshRenderer( rasterRenderer, extent );
1202  }
1203 }
1204 
1205 void QgsRasterLayer::refreshRenderer( QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent )
1206 {
1207  if ( mDataProvider )
1208  {
1209  QgsSingleBandGrayRenderer *singleBandRenderer = nullptr;
1210  QgsMultiBandColorRenderer *multiBandRenderer = nullptr;
1211  QgsSingleBandPseudoColorRenderer *sbpcr = nullptr;
1212  const QgsContrastEnhancement *ce = nullptr;
1213  if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>( rasterRenderer ) ) )
1214  {
1215  ce = singleBandRenderer->contrastEnhancement();
1216  }
1217  else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>( rasterRenderer ) ) )
1218  {
1219  ce = multiBandRenderer->redContrastEnhancement();
1220  }
1221  else if ( ( sbpcr = dynamic_cast<QgsSingleBandPseudoColorRenderer *>( rasterRenderer ) ) )
1222  {
1223  mLastRectangleUsedByRefreshContrastEnhancementIfNeeded = extent;
1224  double min;
1225  double max;
1226  computeMinMax( sbpcr->band(),
1227  rasterRenderer->minMaxOrigin(),
1228  rasterRenderer->minMaxOrigin().limits(), extent,
1229  SAMPLE_SIZE, min, max );
1230  sbpcr->setClassificationMin( min );
1231  sbpcr->setClassificationMax( max );
1232 
1233  if ( sbpcr->shader() )
1234  {
1235  QgsColorRampShader *colorRampShader = dynamic_cast<QgsColorRampShader *>( sbpcr->shader()->rasterShaderFunction() );
1236  if ( colorRampShader )
1237  {
1238  colorRampShader->classifyColorRamp( sbpcr->band(), extent, rasterRenderer->input() );
1239  }
1240  }
1241 
1243  r->setClassificationMin( min );
1244  r->setClassificationMax( max );
1245 
1246  if ( r->shader() )
1247  {
1248  QgsColorRampShader *colorRampShader = dynamic_cast<QgsColorRampShader *>( r->shader()->rasterShaderFunction() );
1249  if ( colorRampShader )
1250  {
1251  colorRampShader->classifyColorRamp( sbpcr->band(), extent, rasterRenderer->input() );
1252  }
1253  }
1254 
1255  emit repaintRequested();
1256  emit styleChanged();
1257  emit rendererChanged();
1258  return;
1259  }
1260 
1261  if ( ce &&
1263  {
1264  mLastRectangleUsedByRefreshContrastEnhancementIfNeeded = extent;
1265 
1267  rasterRenderer->minMaxOrigin().limits(),
1268  extent,
1269  SAMPLE_SIZE,
1270  true,
1271  rasterRenderer );
1272 
1273  // Update main renderer so that the legends get updated
1274  if ( singleBandRenderer )
1275  static_cast<QgsSingleBandGrayRenderer *>( renderer() )->setContrastEnhancement( new QgsContrastEnhancement( * singleBandRenderer->contrastEnhancement() ) );
1276  else if ( multiBandRenderer )
1277  {
1278  if ( multiBandRenderer->redContrastEnhancement() )
1279  {
1280  static_cast<QgsMultiBandColorRenderer *>( renderer() )->setRedContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->redContrastEnhancement() ) );
1281  }
1282  if ( multiBandRenderer->greenContrastEnhancement() )
1283  {
1284  static_cast<QgsMultiBandColorRenderer *>( renderer() )->setGreenContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->greenContrastEnhancement() ) );
1285  }
1286  if ( multiBandRenderer->blueContrastEnhancement() )
1287  {
1288  static_cast<QgsMultiBandColorRenderer *>( renderer() )->setBlueContrastEnhancement( new QgsContrastEnhancement( *multiBandRenderer->blueContrastEnhancement() ) );
1289  }
1290  }
1291 
1292  emit styleChanged();
1293  emit rendererChanged();
1294  }
1295  }
1296 }
1297 
1299 {
1300  if ( !isValid() || !mDataProvider )
1301  {
1302  QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
1303  return customProperty( QStringLiteral( "storedSubsetString" ) ).toString();
1304  }
1305  if ( !mDataProvider->supportsSubsetString() )
1306  {
1307  return QString();
1308  }
1309  return mDataProvider->subsetString();
1310 }
1311 
1312 bool QgsRasterLayer::setSubsetString( const QString &subset )
1313 {
1314  if ( !isValid() || !mDataProvider )
1315  {
1316  QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider or while editing" ), 3 );
1317  setCustomProperty( QStringLiteral( "storedSubsetString" ), subset );
1318  return false;
1319  }
1320 
1321  if ( !mDataProvider->supportsSubsetString() )
1322  {
1323  return false;
1324  }
1325 
1326  if ( subset == mDataProvider->subsetString() )
1327  return true;
1328 
1329  bool res = mDataProvider->setSubsetString( subset );
1330 
1331  // get the updated data source string from the provider
1332  mDataSource = mDataProvider->dataSourceUri();
1333 
1334  if ( res )
1335  {
1336  setExtent( mDataProvider->extent() );
1337  refreshRenderer( renderer(), extent() );
1338  emit subsetStringChanged();
1339  }
1340 
1341  return res;
1342 }
1343 
1346  QgsRasterMinMaxOrigin::Limits &myLimits ) const
1347 {
1348  QgsSettings mySettings;
1349 
1350  QString key;
1351  QString defaultAlg;
1352  QString defaultLimits;
1353 
1354  // TODO: we should not test renderer class here, move it somehow to renderers
1355  if ( dynamic_cast<QgsSingleBandGrayRenderer *>( renderer() ) )
1356  {
1357  key = QStringLiteral( "singleBand" );
1360  defaultLimits = QgsRasterMinMaxOrigin::limitsString(
1362  }
1363  else if ( dynamic_cast<QgsMultiBandColorRenderer *>( renderer() ) )
1364  {
1365  if ( QgsRasterBlock::typeSize( dataProvider()->sourceDataType( 1 ) ) == 1 )
1366  {
1367  key = QStringLiteral( "multiBandSingleByte" );
1370  defaultLimits = QgsRasterMinMaxOrigin::limitsString(
1372  }
1373  else
1374  {
1375  key = QStringLiteral( "multiBandMultiByte" );
1378  defaultLimits = QgsRasterMinMaxOrigin::limitsString(
1380  }
1381  }
1382 
1383  if ( key.isEmpty() )
1384  {
1385  QgsDebugMsgLevel( QStringLiteral( "No default contrast enhancement for this drawing style" ), 2 );
1387  myLimits = QgsRasterMinMaxOrigin::limitsFromString( QString() );
1388  return false;
1389  }
1390  QgsDebugMsgLevel( "key = " + key, 4 );
1391 
1392  QString myAlgorithmString = mySettings.value( "/Raster/defaultContrastEnhancementAlgorithm/" + key, defaultAlg ).toString();
1393  QgsDebugMsgLevel( "myAlgorithmString = " + myAlgorithmString, 4 );
1394 
1395  myAlgorithm = QgsContrastEnhancement::contrastEnhancementAlgorithmFromString( myAlgorithmString );
1396 
1397  QString myLimitsString = mySettings.value( "/Raster/defaultContrastEnhancementLimits/" + key, defaultLimits ).toString();
1398  QgsDebugMsgLevel( "myLimitsString = " + myLimitsString, 4 );
1399  myLimits = QgsRasterMinMaxOrigin::limitsFromString( myLimitsString );
1400 
1401  return true;
1402 }
1403 
1405 {
1406  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
1407 
1410  defaultContrastEnhancementSettings( myAlgorithm, myLimits );
1411 
1412  setContrastEnhancement( myAlgorithm, myLimits );
1413 }
1414 
1415 void QgsRasterLayer::setLayerOrder( QStringList const &layers )
1416 {
1417  QgsDebugMsgLevel( QStringLiteral( "entered." ), 4 );
1418 
1419  if ( mDataProvider )
1420  {
1421  QgsDebugMsgLevel( QStringLiteral( "About to mDataProvider->setLayerOrder(layers)." ), 4 );
1422  mDataProvider->setLayerOrder( layers );
1423  }
1424 
1425 }
1426 
1427 void QgsRasterLayer::setSubLayerVisibility( const QString &name, bool vis )
1428 {
1429 
1430  if ( mDataProvider )
1431  {
1432  QgsDebugMsgLevel( QStringLiteral( "About to mDataProvider->setSubLayerVisibility(name, vis)." ), 4 );
1433  mDataProvider->setSubLayerVisibility( name, vis );
1434  }
1435 
1436 }
1437 
1438 QDateTime QgsRasterLayer::timestamp() const
1439 {
1440  if ( !mDataProvider )
1441  return QDateTime();
1442  return mDataProvider->timestamp();
1443 }
1444 
1446 {
1447  if ( auto *lRenderer = mPipe.renderer() )
1448  {
1449  if ( !lRenderer->accept( visitor ) )
1450  return false;
1451  }
1452  return true;
1453 }
1454 
1455 
1456 bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props ) const
1457 {
1458  Q_UNUSED( errorMessage )
1459 
1460  QgsStringMap localProps = QgsStringMap( props );
1461  if ( hasScaleBasedVisibility() )
1462  {
1463  // TODO: QgsSymbolLayerUtils::mergeScaleDependencies generate SE only and not SLD1.0
1465  }
1466 
1467  if ( isSpatial() ) // TODO: does it make sense this control?
1468  {
1469  // store constraints
1470  QDomElement constraintElem = doc.createElement( QStringLiteral( "sld:LayerFeatureConstraints" ) );
1471  node.appendChild( constraintElem );
1472 
1473  QDomElement featureTypeConstraintElem = doc.createElement( QStringLiteral( "sld:FeatureTypeConstraint" ) );
1474  constraintElem.appendChild( featureTypeConstraintElem );
1475 
1476  QDomElement userStyleElem = doc.createElement( QStringLiteral( "sld:UserStyle" ) );
1477  node.appendChild( userStyleElem );
1478 
1479  if ( !name().isEmpty() )
1480  {
1481  QDomElement nameElem = doc.createElement( QStringLiteral( "sld:Name" ) );
1482  nameElem.appendChild( doc.createTextNode( name() ) );
1483  userStyleElem.appendChild( nameElem );
1484  }
1485 
1486  if ( !abstract().isEmpty() )
1487  {
1488  QDomElement abstractElem = doc.createElement( QStringLiteral( "sld:Abstract" ) );
1489  abstractElem.appendChild( doc.createTextNode( abstract() ) );
1490  userStyleElem.appendChild( abstractElem );
1491  }
1492 
1493  if ( !title().isEmpty() )
1494  {
1495  QDomElement titleElem = doc.createElement( QStringLiteral( "sld:Title" ) );
1496  titleElem.appendChild( doc.createTextNode( title() ) );
1497  userStyleElem.appendChild( titleElem );
1498  }
1499 
1500  QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral( "sld:FeatureTypeStyle" ) );
1501  userStyleElem.appendChild( featureTypeStyleElem );
1502 
1503 #if 0
1504  // TODO: Is there a way to fill it's value with the named style?
1505  // by default <sld:Name> under <sld:FeatureTypeStyle> can have 0 occurrences
1506  // the same happen for tags:
1507  // sld:Title
1508  // sld:Abstract
1509  // sld:FeatureTypeName
1510  // sld:SemanticTypeIdentifier
1511  QDomElement typeStyleNameElem = doc.createElement( QStringLiteral( "sld:Name" ) );
1512  featureTypeStyleElem.appendChild( typeStyleNameElem );
1513 #endif
1514 
1515  QDomElement typeStyleRuleElem = doc.createElement( QStringLiteral( "sld:Rule" ) );
1516  featureTypeStyleElem.appendChild( typeStyleRuleElem );
1517 
1518  // add ScaleDenominator tags
1519  if ( hasScaleBasedVisibility() )
1520  {
1521  // note that denominator is the inverted value of scale
1522  if ( maximumScale() != 0.0 )
1523  {
1524  QDomElement minScaleElem = doc.createElement( QStringLiteral( "sld:MinScaleDenominator" ) );
1525  minScaleElem.appendChild( doc.createTextNode( QString::number( maximumScale() ) ) );
1526  typeStyleRuleElem.appendChild( minScaleElem );
1527  }
1528 
1529  QDomElement maxScaleElem = doc.createElement( QStringLiteral( "sld:MaxScaleDenominator" ) );
1530  maxScaleElem.appendChild( doc.createTextNode( QString::number( minimumScale() ) ) );
1531  typeStyleRuleElem.appendChild( maxScaleElem );
1532  }
1533 
1534  // export renderer dependent tags
1535  mPipe.renderer()->toSld( doc, typeStyleRuleElem, localProps );
1536 
1537  // inject raster layer parameters in RasterSymbolizer tag because
1538  // they belongs to rasterlayer and not to the renderer => avoid to
1539  // pass many parameters value via localProps
1540  QDomNodeList elements = typeStyleRuleElem.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
1541  if ( elements.size() != 0 )
1542  {
1543  // there SHOULD be only one
1544  QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();
1545 
1546  // lamda helper used below to reduce code redundancy
1547  auto vendorOptionWriter = [&]( QString name, QString value )
1548  {
1549  QDomElement vendorOptionElem = doc.createElement( QStringLiteral( "sld:VendorOption" ) );
1550  vendorOptionElem.setAttribute( QStringLiteral( "name" ), name );
1551  vendorOptionElem.appendChild( doc.createTextNode( value ) );
1552  rasterSymbolizerElem.appendChild( vendorOptionElem );
1553  };
1554 
1555  // add greyScale rendering mode if set
1557  {
1558  QString property;
1559  switch ( hueSaturationFilter()->grayscaleMode() )
1560  {
1562  property = QStringLiteral( "lightness" );
1563  break;
1565  property = QStringLiteral( "luminosity" );
1566  break;
1568  property = QStringLiteral( "average" );
1569  break;
1571  // added just to avoid travis fail
1572  break;
1573  }
1574  if ( !property.isEmpty() )
1575  vendorOptionWriter( QStringLiteral( "grayScale" ), property );
1576  }
1577 
1578  // add Hue, Saturation and Lighting values in props is Hue filter is set
1579  if ( hueSaturationFilter() && hueSaturationFilter()->colorizeOn() )
1580  {
1581  vendorOptionWriter( QStringLiteral( "colorizeOn" ), QString::number( hueSaturationFilter()->colorizeOn() ) );
1582  vendorOptionWriter( QStringLiteral( "colorizeRed" ), QString::number( hueSaturationFilter()->colorizeColor().red() ) );
1583  vendorOptionWriter( QStringLiteral( "colorizeGreen" ), QString::number( hueSaturationFilter()->colorizeColor().green() ) );
1584  vendorOptionWriter( QStringLiteral( "colorizeBlue" ), QString::number( hueSaturationFilter()->colorizeColor().blue() ) );
1585  if ( hueSaturationFilter()->colorizeStrength() != 100.0 )
1586  vendorOptionWriter( QStringLiteral( "colorizeStrength" ), QString::number( hueSaturationFilter()->colorizeStrength() / 100.0 ) );
1587  vendorOptionWriter( QStringLiteral( "saturation" ), QString::number( hueSaturationFilter()->colorizeColor().saturationF() ) );
1588  }
1589  else
1590  {
1591  // saturation != 0 (default value)
1592  if ( hueSaturationFilter()->saturation() != 0 )
1593  {
1594  // normlize value [-100:100] -> [0:1]
1595  int s = hueSaturationFilter()->saturation();
1596  double sF = ( s - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1597  vendorOptionWriter( QStringLiteral( "saturation" ), QString::number( sF ) );
1598  }
1599  }
1600 
1601  // brightness != 0 (default value)
1602  if ( brightnessFilter()->brightness() != 0 )
1603  {
1604  // normalize value [-255:255] -> [0:1]
1605  int b = brightnessFilter()->brightness();
1606  double bF = ( b - ( -255.0 ) ) / ( 255.0 - ( -255.0 ) );
1607  vendorOptionWriter( QStringLiteral( "brightness" ), QString::number( bF ) );
1608  }
1609 
1610  // contrast != 0 (default value)
1611  if ( brightnessFilter()->contrast() != 0 )
1612  {
1613  // normlize value [-100:100] -> [0:1]
1614  int c = brightnessFilter()->contrast();
1615  double cF = ( c - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1616  vendorOptionWriter( QStringLiteral( "contrast" ), QString::number( cF ) );
1617  }
1618 
1619 #if 0
1620  // TODO: check if the below mapping formula make sense to map QGIS contrast with SLD gamma value
1621  //
1622  // add SLD1.0 ContrastEnhancement GammaValue = QGIS Contrast
1623  // SLD1.0 does only define 1 as neutral/center double value but does not define range.
1624  // because https://en.wikipedia.org/wiki/Gamma_correction assumed gamma is >0.
1625  // whilst QGIS has a -100/100 values centered in 0 => QGIS contrast value will be scaled in the
1626  // following way:
1627  // [-100,0] => [0,1] and [0,100] => [1,100]
1628  // an alternative could be scale [-100,100] => (0,2]
1629  //
1630  if ( newProps.contains( QStringLiteral( "contrast" ) ) )
1631  {
1632  double gamma;
1633  double contrast = newProps[ QStringLiteral( "contrast" ) ].toDouble();
1634  double percentage = ( contrast - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1635  if ( percentage <= 0.5 )
1636  {
1637  // stretch % to [0-1]
1638  gamma = percentage / 0.5;
1639  }
1640  else
1641  {
1642  gamma = contrast;
1643  }
1644 
1645  QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral( "sld:ContrastEnhancement" ) );
1646  rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1647 
1648  QDomElement gammaValueElem = doc.createElement( QStringLiteral( "sld:GammaValue" ) );
1649  gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1650  globalContrastEnhancementElem.appendChild( gammaValueElem );
1651  }
1652 #endif
1653  }
1654  }
1655  return true;
1656 }
1657 
1658 
1660 {
1661  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
1662  if ( !renderer )
1663  {
1664  return;
1665  }
1666 
1667  mPipe.set( renderer );
1668  emit rendererChanged();
1669  emit styleChanged();
1670 }
1671 
1672 void QgsRasterLayer::showStatusMessage( QString const &message )
1673 {
1674  // QgsDebugMsg(QString("entered with '%1'.").arg(theMessage));
1675 
1676  // Pass-through
1677  // TODO: See if we can connect signal-to-signal. This is a kludge according to the Qt doc.
1678  emit statusChanged( message );
1679 }
1680 
1682 {
1683  if ( mDataProvider )
1684  mDataProvider->setTransformContext( transformContext );
1685 }
1686 
1687 QStringList QgsRasterLayer::subLayers() const
1688 {
1689  if ( ! mDataProvider )
1690  return QStringList();
1691  return mDataProvider->subLayers();
1692 }
1693 
1694 // this function should be used when rendering with the MTR engine introduced in 2.3, as QPixmap is not thread safe (see bug #9626)
1695 // note: previewAsImage and previewAsPixmap should use a common low-level fct QgsRasterLayer::previewOnPaintDevice( QSize size, QColor bgColor, QPaintDevice &device )
1696 QImage QgsRasterLayer::previewAsImage( QSize size, const QColor &bgColor, QImage::Format format )
1697 {
1698  QImage image( size, format );
1699 
1700  if ( ! isValid( ) )
1701  return QImage();
1702 
1703  if ( image.format() == QImage::Format_Indexed8 )
1704  {
1705  image.setColor( 0, bgColor.rgba() );
1706  image.fill( 0 ); //defaults to white, set to transparent for rendering on a map
1707  }
1708  else
1709  {
1710  image.fill( bgColor );
1711  }
1712 
1713  QgsRasterViewPort *rasterViewPort = new QgsRasterViewPort();
1714 
1715  double mapUnitsPerPixel;
1716  double x = 0.0;
1717  double y = 0.0;
1718  QgsRectangle extent = mDataProvider->extent();
1719  if ( extent.width() / extent.height() >= static_cast< double >( image.width() ) / image.height() )
1720  {
1721  mapUnitsPerPixel = extent.width() / image.width();
1722  y = ( image.height() - extent.height() / mapUnitsPerPixel ) / 2;
1723  }
1724  else
1725  {
1726  mapUnitsPerPixel = extent.height() / image.height();
1727  x = ( image.width() - extent.width() / mapUnitsPerPixel ) / 2;
1728  }
1729 
1730  const double pixelWidth = extent.width() / mapUnitsPerPixel;
1731  const double pixelHeight = extent.height() / mapUnitsPerPixel;
1732 
1733  rasterViewPort->mTopLeftPoint = QgsPointXY( x, y );
1734  rasterViewPort->mBottomRightPoint = QgsPointXY( pixelWidth, pixelHeight );
1735  rasterViewPort->mWidth = image.width();
1736  rasterViewPort->mHeight = image.height();
1737 
1738  rasterViewPort->mDrawnExtent = extent;
1739  rasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
1740  rasterViewPort->mDestCRS = QgsCoordinateReferenceSystem(); // will be invalid
1741 
1742  QgsMapToPixel *mapToPixel = new QgsMapToPixel( mapUnitsPerPixel );
1743 
1744  QPainter *painter = new QPainter( &image );
1745  draw( painter, rasterViewPort, mapToPixel );
1746  delete rasterViewPort;
1747  delete mapToPixel;
1748 
1749  painter->end();
1750  delete painter;
1751 
1752  return image;
1753 }
1754 
1756 //
1757 // Protected methods
1758 //
1760 /*
1761  * \param QDomNode node that will contain the symbology definition for this layer.
1762  * \param errorMessage reference to string that will be updated with any error messages
1763  * \return TRUE in case of success.
1764  */
1765 bool QgsRasterLayer::readSymbology( const QDomNode &layer_node, QString &errorMessage,
1766  QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
1767 {
1768  Q_UNUSED( errorMessage )
1769  // TODO: implement categories for raster layer
1770 
1771  QDomElement rasterRendererElem;
1772 
1773  QDomElement layerElement = layer_node.toElement();
1774  readCommonStyle( layerElement, context, categories );
1775 
1776  // pipe element was introduced in the end of 1.9 development when there were
1777  // already many project files in use so we support 1.9 backward compatibility
1778  // even it was never officially released -> use pipe element if present, otherwise
1779  // use layer node
1780  QDomNode pipeNode = layer_node.firstChildElement( QStringLiteral( "pipe" ) );
1781  if ( pipeNode.isNull() ) // old project
1782  {
1783  pipeNode = layer_node;
1784  }
1785 
1786  //rasterlayerproperties element there -> old format (1.8 and early 1.9)
1787  if ( !layer_node.firstChildElement( QStringLiteral( "rasterproperties" ) ).isNull() )
1788  {
1789  //copy node because layer_node is const
1790  QDomNode layerNodeCopy = layer_node.cloneNode();
1791  QDomDocument doc = layerNodeCopy.ownerDocument();
1792  QDomElement rasterPropertiesElem = layerNodeCopy.firstChildElement( QStringLiteral( "rasterproperties" ) );
1793  QgsProjectFileTransform::convertRasterProperties( doc, layerNodeCopy, rasterPropertiesElem,
1794  this );
1795  rasterRendererElem = layerNodeCopy.firstChildElement( QStringLiteral( "rasterrenderer" ) );
1796  QgsDebugMsgLevel( doc.toString(), 4 );
1797  }
1798  else
1799  {
1800  rasterRendererElem = pipeNode.firstChildElement( QStringLiteral( "rasterrenderer" ) );
1801  }
1802 
1803  if ( !rasterRendererElem.isNull() )
1804  {
1805  QString rendererType = rasterRendererElem.attribute( QStringLiteral( "type" ) );
1806  QgsRasterRendererRegistryEntry rendererEntry;
1807  if ( QgsApplication::rasterRendererRegistry()->rendererData( rendererType, rendererEntry ) )
1808  {
1809  QgsRasterRenderer *renderer = rendererEntry.rendererCreateFunction( rasterRendererElem, dataProvider() );
1810  mPipe.set( renderer );
1811  }
1812  }
1813 
1814  //brightness
1816  mPipe.set( brightnessFilter );
1817 
1818  //brightness coefficient
1819  QDomElement brightnessElem = pipeNode.firstChildElement( QStringLiteral( "brightnesscontrast" ) );
1820  if ( !brightnessElem.isNull() )
1821  {
1822  brightnessFilter->readXml( brightnessElem );
1823  }
1824 
1825  //hue/saturation
1827  mPipe.set( hueSaturationFilter );
1828 
1829  //saturation coefficient
1830  QDomElement hueSaturationElem = pipeNode.firstChildElement( QStringLiteral( "huesaturation" ) );
1831  if ( !hueSaturationElem.isNull() )
1832  {
1833  hueSaturationFilter->readXml( hueSaturationElem );
1834  }
1835 
1836  //resampler
1838  mPipe.set( resampleFilter );
1839 
1840  //max oversampling
1841  QDomElement resampleElem = pipeNode.firstChildElement( QStringLiteral( "rasterresampler" ) );
1842  if ( !resampleElem.isNull() )
1843  {
1844  resampleFilter->readXml( resampleElem );
1845  }
1846 
1847  //provider
1848  if ( mDataProvider )
1849  {
1850  QDomElement providerElem = pipeNode.firstChildElement( QStringLiteral( "provider" ) );
1851  if ( !providerElem.isNull() )
1852  {
1853  mDataProvider->readXml( providerElem );
1854  }
1855  }
1856 
1857  // Resampling stage
1858  QDomNode resamplingStageElement = pipeNode.namedItem( QStringLiteral( "resamplingStage" ) );
1859  if ( !resamplingStageElement.isNull() )
1860  {
1861  QDomElement e = resamplingStageElement.toElement();
1862  if ( e.text() == QLatin1String( "provider" ) )
1864  else if ( e.text() == QLatin1String( "resamplingFilter" ) )
1866  }
1867 
1868  // get and set the blend mode if it exists
1869  QDomNode blendModeNode = layer_node.namedItem( QStringLiteral( "blendMode" ) );
1870  if ( !blendModeNode.isNull() )
1871  {
1872  QDomElement e = blendModeNode.toElement();
1873  setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
1874  }
1875 
1876  readCustomProperties( layer_node );
1877 
1878  return true;
1879 }
1880 
1881 bool QgsRasterLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
1882 {
1883  return readSymbology( node, errorMessage, context, categories );
1884 }
1885 
1886 bool QgsRasterLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
1887 {
1888  QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
1889  // Make sure to read the file first so stats etc are initialized properly!
1890 
1891  //process provider key
1892  QDomNode pkeyNode = layer_node.namedItem( QStringLiteral( "provider" ) );
1893 
1894  if ( pkeyNode.isNull() )
1895  {
1896  mProviderKey = QStringLiteral( "gdal" );
1897  }
1898  else
1899  {
1900  QDomElement pkeyElt = pkeyNode.toElement();
1901  mProviderKey = pkeyElt.text();
1902  if ( mProviderKey.isEmpty() )
1903  {
1904  mProviderKey = QStringLiteral( "gdal" );
1905  }
1906  }
1907 
1908  // Open the raster source based on provider and datasource
1909 
1910  // Go down the raster-data-provider paradigm
1911 
1912  // Collect provider-specific information
1913 
1914  QDomNode rpNode = layer_node.namedItem( QStringLiteral( "rasterproperties" ) );
1915 
1916  if ( mProviderKey == QLatin1String( "wms" ) )
1917  {
1918  // >>> BACKWARD COMPATIBILITY < 1.9
1919  // The old WMS URI format does not contain all the information, we add them here.
1920  if ( !mDataSource.contains( QLatin1String( "crs=" ) ) && !mDataSource.contains( QLatin1String( "format=" ) ) )
1921  {
1922  QgsDebugMsgLevel( QStringLiteral( "Old WMS URI format detected -> adding params" ), 4 );
1923  QgsDataSourceUri uri;
1924  uri.setEncodedUri( mDataSource );
1925  QDomElement layerElement = rpNode.firstChildElement( QStringLiteral( "wmsSublayer" ) );
1926  while ( !layerElement.isNull() )
1927  {
1928  // TODO: sublayer visibility - post-0.8 release timeframe
1929 
1930  // collect name for the sublayer
1931  uri.setParam( QStringLiteral( "layers" ), layerElement.namedItem( QStringLiteral( "name" ) ).toElement().text() );
1932 
1933  // collect style for the sublayer
1934  uri.setParam( QStringLiteral( "styles" ), layerElement.namedItem( QStringLiteral( "style" ) ).toElement().text() );
1935 
1936  layerElement = layerElement.nextSiblingElement( QStringLiteral( "wmsSublayer" ) );
1937  }
1938 
1939  // Collect format
1940  uri.setParam( QStringLiteral( "format" ), rpNode.namedItem( QStringLiteral( "wmsFormat" ) ).toElement().text() );
1941 
1942  // WMS CRS URL param should not be mixed with that assigned to the layer.
1943  // In the old WMS URI version there was no CRS and layer crs().authid() was used.
1944  uri.setParam( QStringLiteral( "crs" ), crs().authid() );
1945  mDataSource = uri.encodedUri();
1946  }
1947  // <<< BACKWARD COMPATIBILITY < 1.9
1948  }
1949 
1951  {
1952  QgsDataProvider::ProviderOptions providerOptions { context.transformContext() };
1953  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
1955  {
1957  }
1958  setDataProvider( mProviderKey, providerOptions, flags );
1959  }
1960 
1961  mOriginalStyleElement = layer_node.namedItem( QStringLiteral( "originalStyle" ) ).firstChildElement();
1962  if ( mOriginalStyleElement.isNull() )
1963  mOriginalStyleElement = layer_node.toElement();
1964  mOriginalStyleDocument = layer_node.ownerDocument();
1965 
1966  if ( ! mDataProvider )
1967  {
1969  {
1970  QgsDebugMsg( QStringLiteral( "Raster data provider could not be created for %1" ).arg( mDataSource ) );
1971  }
1972  return false;
1973  }
1974 
1975  QString error;
1976  bool res = readSymbology( layer_node, error, context );
1977 
1978  // old wms settings we need to correct
1979  if ( res && mProviderKey == QLatin1String( "wms" ) && ( !renderer() || renderer()->type() != QLatin1String( "singlebandcolordata" ) ) )
1980  {
1981  setRendererForDrawingStyle( QgsRaster::SingleBandColorDataStyle );
1982  }
1983 
1984  // Check timestamp
1985  // This was probably introduced to reload completely raster if data changed and
1986  // reset completely symbology to reflect new data type etc. It creates however
1987  // problems, because user defined symbology is complete lost if data file time
1988  // changed (the content may be the same). See also 6900.
1989 #if 0
1990  QDomNode stampNode = layer_node.namedItem( "timestamp" );
1991  if ( !stampNode.isNull() )
1992  {
1993  QDateTime stamp = QDateTime::fromString( stampNode.toElement().text(), Qt::ISODate );
1994  // TODO: very bad, we have to load twice!!! Make QgsDataProvider::timestamp() static?
1995  if ( stamp < mDataProvider->dataTimestamp() )
1996  {
1997  QgsDebugMsgLevel( QStringLiteral( "data changed, reload provider" ), 3 );
1998  closeDataProvider();
1999  init();
2001  if ( !isValid() ) return false;
2002  }
2003  }
2004 #endif
2005 
2006  // Load user no data value
2007  QDomElement noDataElement = layer_node.firstChildElement( QStringLiteral( "noData" ) );
2008 
2009  QDomNodeList noDataBandList = noDataElement.elementsByTagName( QStringLiteral( "noDataList" ) );
2010 
2011  for ( int i = 0; i < noDataBandList.size(); ++i )
2012  {
2013  QDomElement bandElement = noDataBandList.at( i ).toElement();
2014  bool ok;
2015  int bandNo = bandElement.attribute( QStringLiteral( "bandNo" ) ).toInt( &ok );
2016  QgsDebugMsgLevel( QStringLiteral( "bandNo = %1" ).arg( bandNo ), 4 );
2017  if ( ok && ( bandNo > 0 ) && ( bandNo <= mDataProvider->bandCount() ) )
2018  {
2019  mDataProvider->setUseSourceNoDataValue( bandNo, bandElement.attribute( QStringLiteral( "useSrcNoData" ) ).toInt() );
2020  QgsRasterRangeList myNoDataRangeList;
2021 
2022  QDomNodeList rangeList = bandElement.elementsByTagName( QStringLiteral( "noDataRange" ) );
2023 
2024  myNoDataRangeList.reserve( rangeList.size() );
2025  for ( int j = 0; j < rangeList.size(); ++j )
2026  {
2027  QDomElement rangeElement = rangeList.at( j ).toElement();
2028  QgsRasterRange myNoDataRange( rangeElement.attribute( QStringLiteral( "min" ) ).toDouble(),
2029  rangeElement.attribute( QStringLiteral( "max" ) ).toDouble() );
2030  QgsDebugMsgLevel( QStringLiteral( "min = %1 %2" ).arg( rangeElement.attribute( "min" ) ).arg( myNoDataRange.min() ), 4 );
2031  myNoDataRangeList << myNoDataRange;
2032  }
2033  mDataProvider->setUserNoDataValue( bandNo, myNoDataRangeList );
2034  }
2035  }
2036 
2037  readStyleManager( layer_node );
2038 
2039  return res;
2040 }
2041 
2042 bool QgsRasterLayer::writeSymbology( QDomNode &layer_node, QDomDocument &document, QString &errorMessage,
2043  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
2044 {
2045  Q_UNUSED( errorMessage )
2046  // TODO: implement categories for raster layer
2047 
2048  QDomElement layerElement = layer_node.toElement();
2049  writeCommonStyle( layerElement, document, context, categories );
2050 
2051  // Store pipe members into pipe element, in future, it will be
2052  // possible to add custom filters into the pipe
2053  QDomElement pipeElement = document.createElement( QStringLiteral( "pipe" ) );
2054 
2055  for ( int i = 0; i < mPipe.size(); i++ )
2056  {
2057  QgsRasterInterface *interface = mPipe.at( i );
2058  if ( !interface ) continue;
2059  interface->writeXml( document, pipeElement );
2060  }
2061 
2062  QDomElement resamplingStageElement = document.createElement( QStringLiteral( "resamplingStage" ) );
2063  QDomText resamplingStageText = document.createTextNode( resamplingStage() == QgsRasterPipe::ResamplingStage::Provider ? QStringLiteral( "provider" ) : QStringLiteral( "resamplingFilter" ) );
2064  resamplingStageElement.appendChild( resamplingStageText );
2065  pipeElement.appendChild( resamplingStageElement );
2066 
2067  layer_node.appendChild( pipeElement );
2068 
2069  if ( !isValid() && !mOriginalStyleElement.isNull() )
2070  {
2071  QDomElement originalStyleElement = document.createElement( QStringLiteral( "originalStyle" ) );
2072  originalStyleElement.appendChild( mOriginalStyleElement );
2073  layer_node.appendChild( originalStyleElement );
2074  }
2075 
2076  // add blend mode node
2077  QDomElement blendModeElement = document.createElement( QStringLiteral( "blendMode" ) );
2078  QDomText blendModeText = document.createTextNode( QString::number( QgsPainting::getBlendModeEnum( blendMode() ) ) );
2079  blendModeElement.appendChild( blendModeText );
2080  layer_node.appendChild( blendModeElement );
2081 
2082  return true;
2083 }
2084 
2085 bool QgsRasterLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
2086  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
2087 {
2088  return writeSymbology( node, doc, errorMessage, context, categories );
2089 } // bool QgsRasterLayer::writeSymbology
2090 
2091 /*
2092  * virtual
2093  * \note Called by QgsMapLayer::writeXml().
2094  */
2095 bool QgsRasterLayer::writeXml( QDomNode &layer_node,
2096  QDomDocument &document,
2097  const QgsReadWriteContext &context ) const
2098 {
2099  // first get the layer element so that we can append the type attribute
2100 
2101  QDomElement mapLayerNode = layer_node.toElement();
2102 
2103  if ( mapLayerNode.isNull() || "maplayer" != mapLayerNode.nodeName() )
2104  {
2105  QgsMessageLog::logMessage( tr( "<maplayer> not found." ), tr( "Raster" ) );
2106  return false;
2107  }
2108 
2109  mapLayerNode.setAttribute( QStringLiteral( "type" ), QStringLiteral( "raster" ) );
2110 
2111  // add provider node
2112 
2113  QDomElement provider = document.createElement( QStringLiteral( "provider" ) );
2114  QDomText providerText = document.createTextNode( mProviderKey );
2115  provider.appendChild( providerText );
2116  layer_node.appendChild( provider );
2117 
2118  // User no data
2119  QDomElement noData = document.createElement( QStringLiteral( "noData" ) );
2120 
2121  for ( int bandNo = 1; bandNo <= mDataProvider->bandCount(); bandNo++ )
2122  {
2123  QDomElement noDataRangeList = document.createElement( QStringLiteral( "noDataList" ) );
2124  noDataRangeList.setAttribute( QStringLiteral( "bandNo" ), bandNo );
2125  noDataRangeList.setAttribute( QStringLiteral( "useSrcNoData" ), mDataProvider->useSourceNoDataValue( bandNo ) );
2126 
2127  const auto constUserNoDataValues = mDataProvider->userNoDataValues( bandNo );
2128  for ( QgsRasterRange range : constUserNoDataValues )
2129  {
2130  QDomElement noDataRange = document.createElement( QStringLiteral( "noDataRange" ) );
2131 
2132  noDataRange.setAttribute( QStringLiteral( "min" ), QgsRasterBlock::printValue( range.min() ) );
2133  noDataRange.setAttribute( QStringLiteral( "max" ), QgsRasterBlock::printValue( range.max() ) );
2134  noDataRangeList.appendChild( noDataRange );
2135  }
2136 
2137  noData.appendChild( noDataRangeList );
2138 
2139  }
2140  if ( noData.hasChildNodes() )
2141  {
2142  layer_node.appendChild( noData );
2143  }
2144 
2145  writeStyleManager( layer_node, document );
2146 
2147  //write out the symbology
2148  QString errorMsg;
2149  return writeSymbology( layer_node, document, errorMsg, context );
2150 }
2151 
2152 // TODO: this should ideally go to gdal provider (together with most of encodedSource() + decodedSource())
2153 static bool _parseGpkgColons( const QString &src, QString &filename, QString &tablename )
2154 {
2155  // GDAL accepts the following input format: GPKG:filename:table
2156  // (GDAL won't accept quoted filename)
2157 
2158  QStringList lst = src.split( ':' );
2159  if ( lst.count() != 3 && lst.count() != 4 )
2160  return false;
2161 
2162  tablename = lst.last();
2163  if ( lst.count() == 3 )
2164  {
2165  filename = lst[1];
2166  return true;
2167  }
2168  else if ( lst.count() == 4 && lst[1].count() == 1 && ( lst[2][0] == '/' || lst[2][0] == '\\' ) )
2169  {
2170  // a bit of handling to make sure that filename C:\hello.gpkg is parsed correctly
2171  filename = lst[1] + ":" + lst[2];
2172  return true;
2173  }
2174  return false;
2175 }
2176 
2177 
2178 QString QgsRasterLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
2179 {
2180  QString src( source );
2181  bool handled = false;
2182 
2183  // Update path for subdataset
2184  if ( providerType() == QLatin1String( "gdal" ) )
2185  {
2186  if ( src.startsWith( QLatin1String( "NETCDF:" ) ) )
2187  {
2188  // NETCDF:filename:variable
2189  // filename can be quoted with " as it can contain colons
2190  QRegExp r( "NETCDF:(.+):([^:]+)" );
2191  if ( r.exactMatch( src ) )
2192  {
2193  QString filename = r.cap( 1 );
2194  if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
2195  filename = filename.mid( 1, filename.length() - 2 );
2196  src = "NETCDF:\"" + context.pathResolver().writePath( filename ) + "\":" + r.cap( 2 );
2197  handled = true;
2198  }
2199  }
2200  else if ( src.startsWith( QLatin1String( "GPKG:" ) ) )
2201  {
2202  // GPKG:filename:table
2203  QString filename, tablename;
2204  if ( _parseGpkgColons( src, filename, tablename ) )
2205  {
2206  filename = context.pathResolver().writePath( filename );
2207  src = QStringLiteral( "GPKG:%1:%2" ).arg( filename, tablename );
2208  handled = true;
2209  }
2210  }
2211  else if ( src.startsWith( QLatin1String( "HDF4_SDS:" ) ) )
2212  {
2213  // HDF4_SDS:subdataset_type:file_name:subdataset_index
2214  // filename can be quoted with " as it can contain colons
2215  QRegExp r( "HDF4_SDS:([^:]+):(.+):([^:]+)" );
2216  if ( r.exactMatch( src ) )
2217  {
2218  QString filename = r.cap( 2 );
2219  if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
2220  filename = filename.mid( 1, filename.length() - 2 );
2221  src = "HDF4_SDS:" + r.cap( 1 ) + ":\"" + context.pathResolver().writePath( filename ) + "\":" + r.cap( 3 );
2222  handled = true;
2223  }
2224  }
2225  else if ( src.startsWith( QLatin1String( "HDF5:" ) ) )
2226  {
2227  // HDF5:file_name:subdataset
2228  // filename can be quoted with " as it can contain colons
2229  QRegExp r( "HDF5:(.+):([^:]+)" );
2230  if ( r.exactMatch( src ) )
2231  {
2232  QString filename = r.cap( 1 );
2233  if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
2234  filename = filename.mid( 1, filename.length() - 2 );
2235  src = "HDF5:\"" + context.pathResolver().writePath( filename ) + "\":" + r.cap( 2 );
2236  handled = true;
2237  }
2238  }
2239  else if ( src.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2240  {
2241  // NITF_IM:0:filename
2242  // RADARSAT_2_CALIB:?:filename
2243  QRegExp r( "([^:]+):([^:]+):(.+)" );
2244  if ( r.exactMatch( src ) )
2245  {
2246  src = r.cap( 1 ) + ':' + r.cap( 2 ) + ':' + context.pathResolver().writePath( r.cap( 3 ) );
2247  handled = true;
2248  }
2249  }
2250  }
2251  else if ( providerType() == "wms" )
2252  {
2253  // handle relative paths to XYZ tiles
2254  QgsDataSourceUri uri;
2255  uri.setEncodedUri( src );
2256  QUrl srcUrl( uri.param( QStringLiteral( "url" ) ) );
2257  if ( srcUrl.isLocalFile() )
2258  {
2259  // relative path will become "file:./x.txt"
2260  QString relSrcUrl = context.pathResolver().writePath( srcUrl.toLocalFile() );
2261  uri.removeParam( QStringLiteral( "url" ) ); // needed because setParam() would insert second "url" key
2262  uri.setParam( QStringLiteral( "url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
2263  src = uri.encodedUri();
2264  handled = true;
2265  }
2266  }
2267 
2268  if ( !handled )
2269  src = context.pathResolver().writePath( src );
2270 
2271  return src;
2272 }
2273 
2274 QString QgsRasterLayer::decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const
2275 {
2276  QString src( source );
2277 
2278  if ( provider == QLatin1String( "wms" ) )
2279  {
2280  // >>> BACKWARD COMPATIBILITY < 1.9
2281  // For project file backward compatibility we must support old format:
2282  // 1. mode: <url>
2283  // example: http://example.org/wms?
2284  // 2. mode: tiled=<width>;<height>;<resolution>;<resolution>...,ignoreUrl=GetMap;GetFeatureInfo,featureCount=<count>,username=<name>,password=<password>,url=<url>
2285  // example: tiled=256;256;0.703;0.351,url=http://example.org/tilecache?
2286  // example: featureCount=10,http://example.org/wms?
2287  // example: ignoreUrl=GetMap;GetFeatureInfo,username=cimrman,password=jara,url=http://example.org/wms?
2288  // This is modified version of old QgsWmsProvider::parseUri
2289  // The new format has always params crs,format,layers,styles and that params
2290  // should not appear in old format url -> use them to identify version
2291  // XYZ tile layers do not need to contain crs,format params, but they have type=xyz
2292  if ( !src.contains( QLatin1String( "type=" ) ) &&
2293  !src.contains( QLatin1String( "crs=" ) ) && !src.contains( QLatin1String( "format=" ) ) )
2294  {
2295  QgsDebugMsgLevel( QStringLiteral( "Old WMS URI format detected -> converting to new format" ), 2 );
2296  QgsDataSourceUri uri;
2297  if ( !src.startsWith( QLatin1String( "http:" ) ) )
2298  {
2299  QStringList parts = src.split( ',' );
2300  QStringListIterator iter( parts );
2301  while ( iter.hasNext() )
2302  {
2303  QString item = iter.next();
2304  if ( item.startsWith( QLatin1String( "username=" ) ) )
2305  {
2306  uri.setUsername( item.mid( 9 ) );
2307  }
2308  else if ( item.startsWith( QLatin1String( "password=" ) ) )
2309  {
2310  uri.setPassword( item.mid( 9 ) );
2311  }
2312  else if ( item.startsWith( QLatin1String( "tiled=" ) ) )
2313  {
2314  // in < 1.9 tiled= may apper in to variants:
2315  // tiled=width;height - non tiled mode, specifies max width and max height
2316  // tiled=width;height;resolutions-1;resolution2;... - tile mode
2317 
2318  QStringList params = item.mid( 6 ).split( ';' );
2319 
2320  if ( params.size() == 2 ) // non tiled mode
2321  {
2322  uri.setParam( QStringLiteral( "maxWidth" ), params.takeFirst() );
2323  uri.setParam( QStringLiteral( "maxHeight" ), params.takeFirst() );
2324  }
2325  else if ( params.size() > 2 ) // tiled mode
2326  {
2327  // resolutions are no more needed and size limit is not used for tiles
2328  // we have to tell to the provider however that it is tiled
2329  uri.setParam( QStringLiteral( "tileMatrixSet" ), QString() );
2330  }
2331  }
2332  else if ( item.startsWith( QLatin1String( "featureCount=" ) ) )
2333  {
2334  uri.setParam( QStringLiteral( "featureCount" ), item.mid( 13 ) );
2335  }
2336  else if ( item.startsWith( QLatin1String( "url=" ) ) )
2337  {
2338  uri.setParam( QStringLiteral( "url" ), item.mid( 4 ) );
2339  }
2340  else if ( item.startsWith( QLatin1String( "ignoreUrl=" ) ) )
2341  {
2342  uri.setParam( QStringLiteral( "ignoreUrl" ), item.mid( 10 ).split( ';' ) );
2343  }
2344  }
2345  }
2346  else
2347  {
2348  uri.setParam( QStringLiteral( "url" ), src );
2349  }
2350  src = uri.encodedUri();
2351  // At this point, the URI is obviously incomplete, we add additional params
2352  // in QgsRasterLayer::readXml
2353  }
2354  // <<< BACKWARD COMPATIBILITY < 1.9
2355 
2356  // handle relative paths to XYZ tiles
2357  QgsDataSourceUri uri;
2358  uri.setEncodedUri( src );
2359  QUrl srcUrl( uri.param( QStringLiteral( "url" ) ) );
2360  if ( srcUrl.isLocalFile() ) // file-based URL? convert to relative path
2361  {
2362  QString absSrcUrl = context.pathResolver().readPath( srcUrl.toLocalFile() );
2363  uri.removeParam( QStringLiteral( "url" ) ); // needed because setParam() would insert second "url" key
2364  uri.setParam( QStringLiteral( "url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
2365  src = uri.encodedUri();
2366  }
2367 
2368  }
2369  else
2370  {
2371  bool handled = false;
2372 
2373  if ( provider == QLatin1String( "gdal" ) )
2374  {
2375  if ( src.startsWith( QLatin1String( "NETCDF:" ) ) )
2376  {
2377  // NETCDF:filename:variable
2378  // filename can be quoted with " as it can contain colons
2379  QRegExp r( "NETCDF:(.+):([^:]+)" );
2380  if ( r.exactMatch( src ) )
2381  {
2382  QString filename = r.cap( 1 );
2383  if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
2384  filename = filename.mid( 1, filename.length() - 2 );
2385  src = "NETCDF:\"" + context.pathResolver().readPath( filename ) + "\":" + r.cap( 2 );
2386  handled = true;
2387  }
2388  }
2389  else if ( src.startsWith( QLatin1String( "GPKG:" ) ) )
2390  {
2391  // GPKG:filename:table
2392  QString filename, tablename;
2393  if ( _parseGpkgColons( src, filename, tablename ) )
2394  {
2395  filename = context.pathResolver().readPath( filename );
2396  src = QStringLiteral( "GPKG:%1:%2" ).arg( filename, tablename );
2397  handled = true;
2398  }
2399  }
2400  else if ( src.startsWith( QLatin1String( "HDF4_SDS:" ) ) )
2401  {
2402  // HDF4_SDS:subdataset_type:file_name:subdataset_index
2403  // filename can be quoted with " as it can contain colons
2404  QRegExp r( "HDF4_SDS:([^:]+):(.+):([^:]+)" );
2405  if ( r.exactMatch( src ) )
2406  {
2407  QString filename = r.cap( 2 );
2408  if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
2409  filename = filename.mid( 1, filename.length() - 2 );
2410  src = "HDF4_SDS:" + r.cap( 1 ) + ":\"" + context.pathResolver().readPath( filename ) + "\":" + r.cap( 3 );
2411  handled = true;
2412  }
2413  }
2414  else if ( src.startsWith( QLatin1String( "HDF5:" ) ) )
2415  {
2416  // HDF5:file_name:subdataset
2417  // filename can be quoted with " as it can contain colons
2418  QRegExp r( "HDF5:(.+):([^:]+)" );
2419  if ( r.exactMatch( src ) )
2420  {
2421  QString filename = r.cap( 1 );
2422  if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
2423  filename = filename.mid( 1, filename.length() - 2 );
2424  src = "HDF5:\"" + context.pathResolver().readPath( filename ) + "\":" + r.cap( 2 );
2425  handled = true;
2426  }
2427  }
2428  else if ( src.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2429  {
2430  // NITF_IM:0:filename
2431  // RADARSAT_2_CALIB:?:filename
2432  QRegExp r( "([^:]+):([^:]+):(.+)" );
2433  if ( r.exactMatch( src ) )
2434  {
2435  src = r.cap( 1 ) + ':' + r.cap( 2 ) + ':' + context.pathResolver().readPath( r.cap( 3 ) );
2436  handled = true;
2437  }
2438  }
2439  }
2440 
2441  if ( !handled )
2442  src = context.pathResolver().readPath( src );
2443  }
2444 
2445  return src;
2446 }
2447 
2449 {
2450  if ( !mDataProvider ) return 0;
2451  return mDataProvider->xSize();
2452 }
2453 
2455 {
2456  if ( !mDataProvider ) return 0;
2457  return mDataProvider->ySize();
2458 }
2459 
2461 {
2462  mPipe.setResamplingStage( stage );
2463 }
2464 
2466 //
2467 // Private methods
2468 //
2470 bool QgsRasterLayer::update()
2471 {
2472  QgsDebugMsgLevel( QStringLiteral( "entered." ), 4 );
2473  // Check if data changed
2474  if ( mDataProvider && mDataProvider->dataTimestamp() > mDataProvider->timestamp() )
2475  {
2476  QgsDebugMsgLevel( QStringLiteral( "reload data" ), 4 );
2477  closeDataProvider();
2478  init();
2479  QgsDataProvider::ProviderOptions providerOptions;
2480  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
2482  {
2484  }
2485  setDataProvider( mProviderKey, providerOptions, flags );
2486  emit dataChanged();
2487  }
2488  return isValid();
2489 }
QgsSingleBandGrayRenderer::setContrastEnhancement
void setContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
Definition: qgssinglebandgrayrenderer.cpp:75
QgsMapLayer::setError
void setError(const QgsError &error)
Sets error message.
Definition: qgsmaplayer.h:1529
QgsMapLayer::willBeDeleted
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
QgsApplication::rasterRendererRegistry
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers.
Definition: qgsapplication.cpp:2153
QgsRasterViewPort::mBottomRightPoint
QgsPointXY mBottomRightPoint
Coordinate (in output device coordinate system) of bottom right corner of the part of the raster that...
Definition: qgsrasterviewport.h:52
QgsRasterInterface::hasStatistics
virtual bool hasStatistics(int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0)
Returns true if histogram is available (cached, already calculated).
Definition: qgsrasterinterface.cpp:93
QgsMultiBandColorRenderer::setGreenContrastEnhancement
void setGreenContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
Definition: qgsmultibandcolorrenderer.cpp:76
QgsRasterDataProvider::setUserNoDataValue
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
Definition: qgsrasterdataprovider.cpp:396
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:89
QgsMapLayer::readCommonStyle
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
Definition: qgsmaplayer.cpp:1622
qgsrasterprojector.h
QgsRasterBlock::printValue
static QString printValue(double value)
Print double value with all necessary significant digits.
Definition: qgsrasterblock.cpp:626
QgsHueSaturationFilter::GrayscaleAverage
@ GrayscaleAverage
Definition: qgshuesaturationfilter.h:41
Qgis::Float32
@ Float32
Thirty two bit floating point (float)
Definition: qgis.h:109
QgsRectangle::height
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
QgsRasterLayer::paletteAsPixmap
QPixmap paletteAsPixmap(int bandNumber=1)
Returns a 100x100 pixmap of the color palette.
Definition: qgsrasterlayer.cpp:507
QgsRasterLayer::bandCount
int bandCount() const
Returns the number of bands in this layer.
Definition: qgsrasterlayer.cpp:217
QgsRasterInterface::generateBandName
virtual QString generateBandName(int bandNumber) const
helper function to create zero padded band names
Definition: qgsrasterinterface.h:245
QgsRasterLayer::writeSymbology
bool writeSymbology(QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
Definition: qgsrasterlayer.cpp:2042
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:102
QgsDataSourceUri
Class for storing the component parts of a RDBMS data source URI (e.g.
Definition: qgsdatasourceuri.h:36
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
Qgis::version
static QString version()
Version string.
Definition: qgis.cpp:276
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
qgsrasterlayer.h
qgsruntimeprofiler.h
QgsMapLayer::FlagTrustLayerMetadata
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
Definition: qgsmaplayer.h:557
qgsbilinearrasterresampler.h
QgsMapLayer::configChanged
void configChanged()
Emitted whenever the configuration is changed.
Qgis::UInt32
@ UInt32
Thirty two bit unsigned integer (quint32)
Definition: qgis.h:107
QgsDataProvider::supportsSubsetString
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
Definition: qgsdataprovider.h:261
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
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:105
QgsHueSaturationFilter::GrayscaleLuminosity
@ GrayscaleLuminosity
Definition: qgshuesaturationfilter.h:40
QgsPainting::BlendMode
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
Definition: qgspainting.h:37
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:174
QgsRasterInterface::writeXml
virtual void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
Definition: qgsrasterinterface.h:461
QgsRasterLayer::ignoreExtents
bool ignoreExtents() const
If the ignoreExtent flag is set, the layer will also render outside the bounding box reported by the ...
Definition: qgsrasterlayer.cpp:1001
QgsRasterInterface::bandStatistics
virtual QgsRasterBandStats bandStatistics(int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
Returns the band statistics.
Definition: qgsrasterinterface.cpp:116
QgsRaster::PalettedColor
@ PalettedColor
Definition: qgsraster.h:94
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsRasterPipe::ResamplingStage::ResampleFilter
@ ResampleFilter
Resampling occurs in ResamplingFilter.
QgsRasterLayer::setLayerOrder
void setLayerOrder(const QStringList &layers) override
Reorders the previously selected sublayers of this layer from bottom to top.
Definition: qgsrasterlayer.cpp:1415
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:42
qgsrectangle.h
QgsRaster::SingleBandColorDataStyle
@ SingleBandColorDataStyle
Definition: qgsraster.h:101
QgsRasterRenderer::minMaxOrigin
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
Definition: qgsrasterrenderer.h:136
QgsRasterInterface::Size
@ Size
Definition: qgsrasterinterface.h:186
QgsRasterLayer::setResamplingStage
void setResamplingStage(QgsRasterPipe::ResamplingStage stage)
Select which stage of the pipe should apply resampling.
Definition: qgsrasterlayer.cpp:2460
ERR
#define ERR(message)
Definition: qgsrasterlayer.cpp:84
QgsRasterLayer::writeSld
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props=QgsStringMap()) const
Writes the symbology of the layer into the document provided in SLD 1.0.0 format.
Definition: qgsrasterlayer.cpp:1456
QgsCoordinateReferenceSystem::userFriendlyIdentifier
QString userFriendlyIdentifier(IdentifierType type=MediumString) const
Returns a user friendly identifier for the CRS.
Definition: qgscoordinatereferencesystem.cpp:1338
QgsSingleBandGrayRenderer::grayBand
int grayBand() const
Definition: qgssinglebandgrayrenderer.h:55
QgsRasterDataProvider::subLayers
QStringList subLayers() const override
Returns the sublayers of this layer - useful for providers that manage their own layers,...
Definition: qgsrasterdataprovider.h:269
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsRasterLayer::readSymbology
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
Definition: qgsrasterlayer.cpp:1765
QgsRasterDataProvider::useSourceNoDataValue
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
Definition: qgsrasterdataprovider.h:249
QgsRaster::AlphaBand
@ AlphaBand
Alpha (0=transparent, 255=opaque)
Definition: qgsraster.h:43
QgsRasterLayer::defaultContrastEnhancementSettings
bool defaultContrastEnhancementSettings(QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, QgsRasterMinMaxOrigin::Limits &myLimits) const
Returns default contrast enhancement settings for that type of raster.
Definition: qgsrasterlayer.cpp:1344
QgsMultiBandColorRenderer::redContrastEnhancement
const QgsContrastEnhancement * redContrastEnhancement() const
Definition: qgsmultibandcolorrenderer.h:58
QgsDataProvider::setSubLayerVisibility
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
Definition: qgsdataprovider.h:329
QgsRasterLayer::resamplingStage
QgsRasterPipe::ResamplingStage resamplingStage() const
Returns which stage of the pipe should apply resampling.
Definition: qgsrasterlayer.h:288
QgsMapLayer::clone
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
QgsMapLayer::blendMode
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Definition: qgsmaplayer.cpp:212
QgsRasterLayer::setDefaultContrastEnhancement
void setDefaultContrastEnhancement()
Sets the default contrast enhancement.
Definition: qgsrasterlayer.cpp:1404
qgsmaptopixel.h
QgsRasterMinMaxOrigin::Limits
Limits
This enumerator describes the limits used to compute min/max values.
Definition: qgsrasterminmaxorigin.h:59
QgsMapLayer::setCustomProperty
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
Definition: qgsmaplayer.cpp:1708
algorithm
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
QgsCoordinateReferenceSystem::WKT_PREFERRED
@ WKT_PREFERRED
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
Definition: qgscoordinatereferencesystem.h:679
QgsRasterInterface::cumulativeCut
virtual void cumulativeCut(int bandNo, double lowerCount, double upperCount, double &lowerValue, double &upperValue, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0)
Find values for cumulative pixel count cut.
Definition: qgsrasterinterface.cpp:523
QgsRasterBandStats
The RasterBandStats struct is a container for statistics about a single raster band.
Definition: qgsrasterbandstats.h:35
QgsLayerMetadataFormatter::historySectionHtml
QString historySectionHtml() const
Formats the "History" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:230
QgsMapLayer::mReadFlags
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
Definition: qgsmaplayer.h:1589
qgsreadwritecontext.h
QgsLayerMetadataFormatter
Class for metadata formatter.
Definition: qgslayermetadataformatter.h:34
QgsRasterDataProvider::ResamplingMethod::Cubic
@ Cubic
Bicubic resamplikng.
qgsrasterdrawer.h
QgsSingleBandPseudoColorRenderer::setShader
void setShader(QgsRasterShader *shader)
Takes ownership of the shader.
Definition: qgssinglebandpseudocolorrenderer.cpp:111
QgsDataProvider::setSubsetString
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
Definition: qgsdataprovider.h:249
QgsRasterLayer::LayerOptions::skipCrsValidation
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
Definition: qgsrasterlayer.h:137
QgsRaster::IdentifyFormatText
@ IdentifyFormatText
Definition: qgsraster.h:61
QgsRasterPipe::set
bool set(QgsRasterInterface *interface)
Insert a new known interface in default place or replace interface of the same role if it already exi...
Definition: qgsrasterpipe.cpp:163
QgsRaster::SingleBandGray
@ SingleBandGray
Definition: qgsraster.h:92
QgsRasterLayer::ColorLayer
@ ColorLayer
Definition: qgsrasterlayer.h:184
QgsDataProvider::FlagTrustDataSource
@ FlagTrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
Definition: qgsdataprovider.h:120
QgsRasterLayer::GrayOrUndefined
@ GrayOrUndefined
Definition: qgsrasterlayer.h:181
QgsRasterShader::rasterShaderFunction
QgsRasterShaderFunction * rasterShaderFunction()
Definition: qgsrastershader.h:65
QgsRasterViewPort::mSrcCRS
QgsCoordinateReferenceSystem mSrcCRS
Source coordinate system.
Definition: qgsrasterviewport.h:64
QgsRasterDataProvider::ProviderHintCanPerformProviderResampling
@ ProviderHintCanPerformProviderResampling
Provider can perform resampling (to be opposed to post rendering resampling) (since QGIS 3....
Definition: qgsrasterdataprovider.h:104
qgssymbollayerutils.h
QgsMapLayerType
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:68
QgsRasterDataProvider::dataTimestamp
QDateTime dataTimestamp() const override
Current time stamp of data source.
Definition: qgsrasterdataprovider.h:431
QgsRasterRendererRegistryEntry
Registry for raster renderer entries.
Definition: qgsrasterrendererregistry.h:45
QgsRasterLayer::SAMPLE_SIZE
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
Definition: qgsrasterlayer.h:76
QgsDataProvider::error
virtual QgsError error() const
Gets current status error.
Definition: qgsdataprovider.h:423
QgsRasterBandStats::mean
double mean
The mean cell value for the band. NO_DATA values are excluded.
Definition: qgsrasterbandstats.h:97
QgsRasterDataProvider::extent
QgsRectangle extent() const override=0
Returns the extent of the layer.
QgsRaster::DrawingStyle
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
Definition: qgsraster.h:90
QgsColorRampShader::classifyColorRamp
void classifyColorRamp(int classes=0, int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
Classify color ramp shader.
Definition: qgscolorrampshader.cpp:136
qgspathresolver.h
QgsMapLayer::statusChanged
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
QgsRasterLayer::decodedSource
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
Definition: qgsrasterlayer.cpp:2274
QgsRaster::IdentifyFormatHtml
@ IdentifyFormatHtml
Definition: qgsraster.h:62
QgsRaster::UndefinedDrawingStyle
@ UndefinedDrawingStyle
Definition: qgsraster.h:91
QgsMultiBandColorRenderer::greenContrastEnhancement
const QgsContrastEnhancement * greenContrastEnhancement() const
Definition: qgsmultibandcolorrenderer.h:62
QgsSingleBandGrayRenderer
Raster renderer pipe for single band gray.
Definition: qgssinglebandgrayrenderer.h:34
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
qgscolorrampshader.h
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
qgssinglebandcolordatarenderer.h
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QgsLayerMetadataFormatter::contactsSectionHtml
QString contactsSectionHtml() const
Formats the "Contacts" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:51
QgsRasterLayer::subsetStringChanged
void subsetStringChanged()
Emitted when the layer's subset string has changed.
QgsMapLayer::setBlendMode
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
Definition: qgsmaplayer.cpp:202
QgsRasterInterface::IdentifyFeature
@ IdentifyFeature
Definition: qgsrasterinterface.h:194
qgsrasterrendererregistry.h
QgsRasterLayer::setTransformContext
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
Definition: qgsrasterlayer.cpp:1681
QgsRasterMinMaxOrigin::stdDevFactor
double stdDevFactor() const
Returns the factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ].
Definition: qgsrasterminmaxorigin.h:111
QgsMapLayer::readCustomProperties
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
Definition: qgsmaplayer.cpp:629
QgsRasterRenderer::type
virtual QString type() const
Definition: qgsrasterrenderer.h:64
QgsRasterLayer::Multiband
@ Multiband
Definition: qgsrasterlayer.h:183
QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type Byte.
Definition: qgsrasterlayer.h:82
QgsRasterLayer::htmlMetadata
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
Definition: qgsrasterlayer.cpp:316
QgsMapLayer::isValid
bool isValid
Definition: qgsmaplayer.h:91
QgsRasterViewPort::mTopLeftPoint
QgsPointXY mTopLeftPoint
Coordinate (in output device coordinate system) of top left corner of the part of the raster that is ...
Definition: qgsrasterviewport.h:46
QgsRasterViewPort
This class provides details of the viewable area that a raster will be rendered into.
Definition: qgsrasterviewport.h:35
QgsRasterRenderer::toSld
virtual void toSld(QDomDocument &doc, QDomElement &element, const QgsStringMap &props=QgsStringMap()) const
Used from subclasses to create SLD Rule elements following SLD v1.0 specs.
Definition: qgsrasterrenderer.cpp:175
QgsSingleBandPseudoColorRenderer::band
int band() const
Returns the band used by the renderer.
Definition: qgssinglebandpseudocolorrenderer.h:89
QgsRasterLayer::setDataSource
void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag=false) override
Updates the data source of the layer.
Definition: qgsrasterlayer.cpp:864
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsRasterLayer::setSubsetString
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.
Definition: qgsrasterlayer.cpp:1312
QgsRasterRendererRegistryEntry::rendererCreateFunction
QgsRasterRendererCreateFunc rendererCreateFunction
Definition: qgsrasterrendererregistry.h:56
QgsReadWriteContext::transformContext
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
Definition: qgsreadwritecontext.cpp:77
QgsDataProvider::dataSourceUri
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
Definition: qgsdataprovider.h:159
QgsRasterRange::min
double min() const
Returns the minimum value for the range.
Definition: qgsrasterrange.h:65
QgsMultiBandColorRenderer::setRedContrastEnhancement
void setRedContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
Definition: qgsmultibandcolorrenderer.cpp:70
QgsRasterLayer::previewAsImage
QImage previewAsImage(QSize size, const QColor &bgColor=Qt::white, QImage::Format format=QImage::Format_ARGB32_Premultiplied)
Draws a preview of the rasterlayer into a QImage.
Definition: qgsrasterlayer.cpp:1696
QgsRasterLayer::refreshContrastEnhancement
void refreshContrastEnhancement(const QgsRectangle &extent)
Refresh contrast enhancement with new extent.
Definition: qgsrasterlayer.cpp:1152
QgsMapLayer::setMetadata
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
Definition: qgsmaplayer.cpp:1836
QgsColorRampShader
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
Definition: qgscolorrampshader.h:40
qgssinglebandpseudocolorrenderer.h
QgsMapLayer::setCrs
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Definition: qgsmaplayer.cpp:771
QgsRasterLayer::SINGLE_BAND_ENHANCEMENT_ALGORITHM
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
Definition: qgsrasterlayer.h:79
QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
Definition: qgsrasterlayer.h:94
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsRasterLayer::legendSymbologyItems
QgsLegendColorList legendSymbologyItems() const
Returns a list with classification items (Text and color)
Definition: qgsrasterlayer.cpp:305
qgscubicrasterresampler.h
QgsRasterLayer::setRenderer
void setRenderer(QgsRasterRenderer *renderer)
Sets the raster's renderer.
Definition: qgsrasterlayer.cpp:1659
QgsRasterMinMaxOrigin::WholeRaster
@ WholeRaster
Whole raster is used to compute statistics.
Definition: qgsrasterminmaxorigin.h:71
QgsRasterLayer::bandName
QString bandName(int bandNoInt) const
Returns the name of a band given its number.
Definition: qgsrasterlayer.cpp:223
QgsMapLayer::mShouldValidateCrs
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
Definition: qgsmaplayer.h:1596
QgsRasterLayerTemporalProperties
Implementation of map layer temporal properties for raster layers.
Definition: qgsrasterlayertemporalproperties.h:36
QgsMapLayer::mProviderKey
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:1584
Qgis::CFloat32
@ CFloat32
Complex Float32.
Definition: qgis.h:113
QgsSymbolLayerUtils::mergeScaleDependencies
static void mergeScaleDependencies(double mScaleMinDenom, double mScaleMaxDenom, QgsStringMap &props)
Merges the local scale limits, if any, with the ones already in the map, if any.
Definition: qgssymbollayerutils.cpp:4540
QgsRasterDataProvider::ResamplingMethod::Bilinear
@ Bilinear
Bilinear resamplikng.
QgsBilinearRasterResampler
Bilinear Raster Resampler.
Definition: qgsbilinearrasterresampler.h:34
QgsDataProvider::transformContext
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
Definition: qgsdataprovider.cpp:76
QgsMapLayerRenderer
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Definition: qgsmaplayerrenderer.h:51
QgsRasterPipe::at
QgsRasterInterface * at(int idx) const
Definition: qgsrasterpipe.h:113
QgsLayerMetadataFormatter::linksSectionHtml
QString linksSectionHtml() const
Formats the "Links" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:256
QgsRasterDataProvider::setZoomedInResamplingMethod
virtual bool setZoomedInResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-in operations.
Definition: qgsrasterdataprovider.h:627
QgsSingleBandGrayRenderer::contrastEnhancement
const QgsContrastEnhancement * contrastEnhancement() const
Definition: qgssinglebandgrayrenderer.h:57
QgsRasterMinMaxOrigin
This class describes the origin of min/max values.
Definition: qgsrasterminmaxorigin.h:34
QgsRasterLayer::Palette
@ Palette
Definition: qgsrasterlayer.h:182
qgsapplication.h
QgsPainting::getBlendModeEnum
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:80
QgsMapLayer::mLayerName
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1541
QgsRasterLayer::isValidRasterFileName
static bool isValidRasterFileName(const QString &fileNameQString, QString &retError)
This helper checks to see whether the file name appears to be a valid raster file name.
Definition: qgsrasterlayer.cpp:173
qgsrasteriterator.h
QgsRasterProjector
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
Definition: qgsrasterprojector.h:48
QgsSingleBandPseudoColorRenderer::setClassificationMax
void setClassificationMax(double max)
Definition: qgssinglebandpseudocolorrenderer.cpp:66
QgsRasterBandStats::maximumValue
double maximumValue
The maximum cell value in the raster band.
Definition: qgsrasterbandstats.h:88
QgsDataSourceUri::param
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
Definition: qgsdatasourceuri.cpp:823
QgsMapLayer::dataSourceChanged
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
QgsBrightnessContrastFilter::readXml
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
Definition: qgsbrightnesscontrastfilter.cpp:205
QgsColorRampShader::Discrete
@ Discrete
Assigns the color of the higher class for every pixel between two class breaks.
Definition: qgscolorrampshader.h:48
QgsDataSourceUri::setUsername
void setUsername(const QString &username)
Sets the username for the URI.
Definition: qgsdatasourceuri.cpp:264
QgsContrastEnhancement::contrastEnhancementAlgorithmString
static QString contrastEnhancementAlgorithmString(ContrastEnhancementAlgorithm algorithm)
Returns a string to serialize ContrastEnhancementAlgorithm.
Definition: qgscontrastenhancement.cpp:343
QgsMultiBandColorRenderer::setBlueContrastEnhancement
void setBlueContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
Definition: qgsmultibandcolorrenderer.cpp:82
QgsMapLayer::FlagDontResolveLayers
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
Definition: qgsmaplayer.h:556
QgsRasterLayer::~QgsRasterLayer
~QgsRasterLayer() override
Definition: qgsrasterlayer.cpp:139
QgsMapLayer::flags
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
Definition: qgsmaplayer.cpp:134
Qgis::CFloat64
@ CFloat64
Complex Float64.
Definition: qgis.h:114
QgsPathResolver::writePath
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
Definition: qgspathresolver.cpp:192
QgsRasterLayer::subLayers
QStringList subLayers() const override
Returns the sublayers of this layer.
Definition: qgsrasterlayer.cpp:1687
QgsRasterPipe::remove
bool remove(int idx)
Remove and delete interface at given index if possible.
Definition: qgsrasterpipe.cpp:268
qgsprojectfiletransform.h
QgsColorRampShader::setColorRampType
void setColorRampType(QgsColorRampShader::Type colorRampType)
Sets the color ramp type.
Definition: qgscolorrampshader.cpp:100
QgsRasterBlock::typeSize
static int typeSize(int dataType) SIP_HOLDGIL
Returns the size in bytes for the specified dataType.
Definition: qgsrasterblock.h:83
QgsRasterLayer::width
int width() const
Returns the width of the (unclipped) raster.
Definition: qgsrasterlayer.cpp:2448
QgsDataProvider::reloadData
virtual void reloadData()
Reloads the data from the source by calling reloadProviderData() implemented by providers with data c...
Definition: qgsdataprovider.cpp:40
QgsRasterLayer::lastModified
static QDateTime lastModified(const QString &name)
Returns time stamp for given file name.
Definition: qgsrasterlayer.cpp:185
QgsRasterLayer::accept
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
Definition: qgsrasterlayer.cpp:1445
QgsContrastEnhancement::ContrastEnhancementAlgorithm
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used.
Definition: qgscontrastenhancement.h:49
QgsMapLayer::setExtent
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
Definition: qgsmaplayer.cpp:1858
QgsRaster::IdentifyFormatValue
@ IdentifyFormatValue
Definition: qgsraster.h:60
QgsRasterMinMaxOrigin::CumulativeCut
@ CumulativeCut
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ].
Definition: qgsrasterminmaxorigin.h:63
QgsRasterInterface::IdentifyValue
@ IdentifyValue
Definition: qgsrasterinterface.h:191
QgsRasterDrawer::draw
void draw(QPainter *p, QgsRasterViewPort *viewPort, const QgsMapToPixel *qgsMapToPixel, QgsRasterBlockFeedback *feedback=nullptr)
Draws raster data.
Definition: qgsrasterdrawer.cpp:36
QgsHueSaturationFilter::grayscaleMode
QgsHueSaturationFilter::GrayscaleMode grayscaleMode() const
Definition: qgshuesaturationfilter.h:60
qgsproviderregistry.h
QgsRasterMinMaxOrigin::MinMax
@ MinMax
Real min-max values.
Definition: qgsrasterminmaxorigin.h:61
QgsRasterLayer::encodedSource
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
Definition: qgsrasterlayer.cpp:2178
QgsRasterLayer::draw
void draw(QPainter *theQPainter, QgsRasterViewPort *myRasterViewPort, const QgsMapToPixel *qgsMapToPixel=nullptr)
This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPix...
Definition: qgsrasterlayer.cpp:258
qgsdatasourceuri.h
Qgis::CInt16
@ CInt16
Complex Int16.
Definition: qgis.h:111
QgsRasterPipe::renderer
QgsRasterRenderer * renderer() const
Definition: qgsrasterpipe.cpp:238
qgspalettedrasterrenderer.h
QgsRasterInterface::xSize
virtual int xSize() const
Gets raster size.
Definition: qgsrasterinterface.h:241
QgsRasterRenderer
Raster renderer pipe that applies colors to a raster.
Definition: qgsrasterrenderer.h:39
QgsRasterResampleFilter::readXml
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
Definition: qgsrasterresamplefilter.cpp:284
QgsBrightnessContrastFilter::brightness
int brightness() const
Returns current brightness level.
Definition: qgsbrightnesscontrastfilter.h:73
QgsContrastEnhancement::StretchToMinimumMaximum
@ StretchToMinimumMaximum
Definition: qgscontrastenhancement.h:51
QgsMultiBandColorRenderer::blueBand
int blueBand() const
Definition: qgsmultibandcolorrenderer.h:55
QgsMultiBandColorRenderer::redBand
int redBand() const
Definition: qgsmultibandcolorrenderer.h:51
QgsRasterDataProvider::providerCapabilities
virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
Definition: qgsrasterdataprovider.cpp:245
QgsRasterViewPort::mTransformContext
QgsCoordinateTransformContext mTransformContext
Coordinate transform context.
Definition: qgsrasterviewport.h:72
QgsMapLayer::readStyleManager
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
Definition: qgsmaplayer.cpp:639
QgsUnitTypes::toString
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
Definition: qgsunittypes.cpp:199
QgsMapLayer::writeCommonStyle
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
Definition: qgsmaplayer.cpp:540
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::temporalCapabilities
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
Definition: qgsrasterdataprovider.cpp:427
QgsMapLayer::styleChanged
void styleChanged()
Signal emitted whenever a change affects the layer's style.
QgsMapLayer::repaintRequested
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
QgsRasterLayer::height
int height() const
Returns the height of the (unclipped) raster.
Definition: qgsrasterlayer.cpp:2454
QgsRasterMinMaxOrigin::cumulativeCutLower
double cumulativeCutLower() const
Returns the lower bound of cumulative cut method (between 0 and 1).
Definition: qgsrasterminmaxorigin.h:105
QgsMapLayer::extent
virtual QgsRectangle extent() const
Returns the extent of the layer.
Definition: qgsmaplayer.cpp:197
QgsRasterLayer::temporalProperties
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
Definition: qgsrasterlayer.cpp:1006
QgsContrastEnhancement::NoEnhancement
@ NoEnhancement
Definition: qgscontrastenhancement.h:50
QgsPainting::getCompositionMode
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:20
QgsRasterDataProvider::ProviderHintBenefitsFromResampling
@ ProviderHintBenefitsFromResampling
Provider benefits from resampling and should apply user default resampling settings (since QGIS 3....
Definition: qgsrasterdataprovider.h:103
QgsRasterBandStats::StdDev
@ StdDev
Definition: qgsrasterbandstats.h:45
QgsMultiBandColorRenderer::blueContrastEnhancement
const QgsContrastEnhancement * blueContrastEnhancement() const
Definition: qgsmultibandcolorrenderer.h:66
QgsDataSourceUri::setParam
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
Definition: qgsdatasourceuri.cpp:778
QgsRasterLayer::timestamp
QDateTime timestamp() const override
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsrasterlayer.cpp:1438
QgsRasterMinMaxOrigin::limitsFromString
static Limits limitsFromString(const QString &limits)
Deserialize Limits.
Definition: qgsrasterminmaxorigin.cpp:62
QgsRasterMinMaxOrigin::limitsString
static QString limitsString(Limits limits)
Returns a string to serialize Limits.
Definition: qgsrasterminmaxorigin.cpp:46
qgsrendercontext.h
QgsRasterDrawer
The drawing pipe for raster layers.
Definition: qgsrasterdrawer.h:38
QgsRasterInterface::clone
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
qgspainting.h
QgsMapLayer::loadDefaultStyle
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
Definition: qgsmaplayer.cpp:862
QgsMultiBandColorRenderer::greenBand
int greenBand() const
Definition: qgsmultibandcolorrenderer.h:53
QgsCubicRasterResampler
Cubic Raster Resampler.
Definition: qgscubicrasterresampler.h:33
QgsRasterDataProvider::ReadLayerMetadata
@ ReadLayerMetadata
Provider can read layer metadata from data store. Since QGIS 3.0. See QgsDataProvider::layerMetadata(...
Definition: qgsrasterdataprovider.h:101
QgsRasterLayer::dataProvider
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Definition: qgsrasterlayer.cpp:234
QgsRasterProjector::setCrs
Q_DECL_DEPRECATED void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.
QgsProviderRegistry::decodeUri
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
Definition: qgsproviderregistry.cpp:433
QgsApplication::profiler
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
Definition: qgsapplication.cpp:482
QgsRasterLayer::readXml
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
Definition: qgsrasterlayer.cpp:1886
QgsSingleBandPseudoColorRenderer::setClassificationMin
void setClassificationMin(double min)
Definition: qgssinglebandpseudocolorrenderer.cpp:53
QgsRasterBandStats::Min
@ Min
Definition: qgsrasterbandstats.h:40
qgscoordinatetransform.h
QgsRasterLayer::LayerOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsrasterlayer.h:122
QgsRasterRangeList
QList< QgsRasterRange > QgsRasterRangeList
Definition: qgsrasterrange.h:26
QgsMapLayer::title
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:293
QgsMapLayerTemporalProperties
Base class for storage of map layer temporal properties.
Definition: qgsmaplayertemporalproperties.h:43
QgsRasterResampleFilter::setZoomedInResampler
void setZoomedInResampler(QgsRasterResampler *r)
Sets resampler for zoomed in scales. Takes ownership of the object.
Definition: qgsrasterresamplefilter.cpp:111
QgsRasterLayer::subsetString
virtual QString subsetString() const
Returns the string (typically sql) used to define a subset of the layer.
Definition: qgsrasterlayer.cpp:1298
QgsMapLayer::mDataSource
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1538
QgsHueSaturationFilter
Color and saturation filter pipe for rasters.
Definition: qgshuesaturationfilter.h:32
QgsColorRampShader::setColorRampItemList
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &list)
Sets a custom colormap.
Definition: qgscolorrampshader.cpp:92
QgsContrastEnhancement::contrastEnhancementAlgorithm
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
Definition: qgscontrastenhancement.h:157
QgsRasterDataProvider::colorTable
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
Definition: qgsrasterdataprovider.h:262
QgsMultiBandColorRenderer
Renderer for multiband images with the color components.
Definition: qgsmultibandcolorrenderer.h:33
QgsMapLayer::hasScaleBasedVisibility
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
Definition: qgsmaplayer.cpp:678
QgsDataSourceUri::removeParam
int removeParam(const QString &key)
Removes a generic parameter by key.
Definition: qgsdatasourceuri.cpp:802
QgsCoordinateReferenceSystem::FullString
@ FullString
Full definition – possibly a very lengthy string, e.g. with no truncation of custom WKT definitions.
Definition: qgscoordinatereferencesystem.h:633
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
QgsRasterBandStats::Mean
@ Mean
Definition: qgsrasterbandstats.h:44
QgsRasterLayer::setContrastEnhancement
void setContrastEnhancement(QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, QgsRasterMinMaxOrigin::Limits limits=QgsRasterMinMaxOrigin::MinMax, const QgsRectangle &extent=QgsRectangle(), int sampleSize=QgsRasterLayer::SAMPLE_SIZE, bool generateLookupTableFlag=true)
Set contrast enhancement algorithm.
Definition: qgsrasterlayer.cpp:1011
QgsRasterIterator
Iterator for sequentially processing raster cells.
Definition: qgsrasteriterator.h:35
qgsrasterresamplefilter.h
Qgis::UInt16
@ UInt16
Sixteen bit unsigned integer (quint16)
Definition: qgis.h:105
QgsBrightnessContrastFilter::contrast
int contrast() const
Returns current contrast level.
Definition: qgsbrightnesscontrastfilter.h:85
QgsMapLayer::minimumScale
double minimumScale() const
Returns the minimum map scale (i.e.
Definition: qgsmaplayer.cpp:743
QgsMapLayer::rendererChanged
void rendererChanged()
Signal emitted when renderer is changed.
QgsMapLayer::maximumScale
double maximumScale() const
Returns the maximum map scale (i.e.
Definition: qgsmaplayer.cpp:727
qgsbrightnesscontrastfilter.h
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
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
QgsContrastEnhancement
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
Definition: qgscontrastenhancement.h:43
QgsRaster::IdentifyFormatFeature
@ IdentifyFormatFeature
Definition: qgsraster.h:63
qgsrasterlayerrenderer.h
qgssinglebandgrayrenderer.h
QgsHueSaturationFilter::saturation
int saturation() const
Definition: qgshuesaturationfilter.h:57
QgsRasterInterface::ySize
virtual int ySize() const
Definition: qgsrasterinterface.h:242
QgsRasterLayer::readStyle
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
Definition: qgsrasterlayer.cpp:1881
QgsRasterMinMaxOrigin::UpdatedCanvas
@ UpdatedCanvas
Constantly updated extent of the canvas is used to compute statistics.
Definition: qgsrasterminmaxorigin.h:75
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
QgsRasterLayerTemporalProperties::setDefaultsFromDataProviderTemporalCapabilities
void setDefaultsFromDataProviderTemporalCapabilities(const QgsDataProviderTemporalCapabilities *capabilities) override
Sets the layers temporal settings to appropriate defaults based on a provider's temporal capabilities...
Definition: qgsrasterlayertemporalproperties.cpp:156
qgsrastershader.h
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
QgsRasterBandStats::minimumValue
double minimumValue
The minimum cell value in the raster band.
Definition: qgsrasterbandstats.h:94
QgsMapLayerLegend::defaultRasterLegend
static QgsMapLayerLegend * defaultRasterLegend(QgsRasterLayer *rl)
Create new legend implementation for raster layer.
Definition: qgsmaplayerlegend.cpp:52
QgsRasterLayer::rasterUnitsPerPixelY
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis.
Definition: qgsrasterlayer.cpp:583
QgsRasterDataProvider::timestamp
QDateTime timestamp() const override
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsrasterdataprovider.h:428
QgsRasterLayer::resampleFilter
QgsRasterResampleFilter * resampleFilter() const
Returns the raster's resample filter.
Definition: qgsrasterlayer.h:254
QgsMapLayer::dataChanged
void dataChanged()
Data of layer changed.
QgsMapLayer::appendError
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:1527
QgsRasterDataProvider::colorInterpretation
virtual int colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
Definition: qgsrasterdataprovider.h:154
QgsRasterBandStats::Max
@ Max
Definition: qgsrasterbandstats.h:41
QgsRasterLayer::reload
void reload() override
Synchronises with changes in the datasource.
Definition: qgsrasterlayer.cpp:244
QgsDataProvider::setTransformContext
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
Definition: qgsdataprovider.cpp:82
QgsMapLayer::publicSource
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Definition: qgsmaplayer.cpp:184
QgsPathResolver::readPath
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Definition: qgspathresolver.cpp:35
QgsRasterDataProvider::sourceDataType
Qgis::DataType sourceDataType(int bandNo) const override=0
Returns source data type for the band specified by number, source data type may be shorter than dataT...
qgshuesaturationfilter.h
QgsMapLayer::source
QString source() const
Returns the source for the layer.
Definition: qgsmaplayer.cpp:192
QgsRasterRenderer::setMinMaxOrigin
void setMinMaxOrigin(const QgsRasterMinMaxOrigin &origin)
Sets origin of min/max values.
Definition: qgsrasterrenderer.h:139
QgsRasterLayer::LayerOptions
Setting options for loading raster layers.
Definition: qgsrasterlayer.h:104
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsRasterLayer::LayerOptions::loadDefaultStyle
bool loadDefaultStyle
Sets to true if the default layer style should be loaded.
Definition: qgsrasterlayer.h:116
QgsRaster::GrayIndex
@ GrayIndex
Greyscale.
Definition: qgsraster.h:38
Qgis::ARGB32_Premultiplied
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Definition: qgis.h:116
QgsMapLayer::writeStyleManager
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
Definition: qgsmaplayer.cpp:648
QgsRasterInterface
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:117
QgsRasterPipe::last
QgsRasterInterface * last() const
Definition: qgsrasterpipe.h:114
QgsRasterViewPort::mHeight
qgssize mHeight
Height, number of rows to be rendered.
Definition: qgsrasterviewport.h:58
QgsRasterDataProvider::userNoDataValues
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
Definition: qgsrasterdataprovider.h:260
QgsRasterLayer::clone
QgsRasterLayer * clone() const override
Returns a new instance equivalent to this one.
Definition: qgsrasterlayer.cpp:147
QgsDataSourceUri::encodedUri
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
Definition: qgsdatasourceuri.cpp:610
QgsMapLayer::customProperty
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Definition: qgsmaplayer.cpp:1723
QgsMapLayer::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
Definition: qgsmaplayer.cpp:785
QgsRaster::SingleBandPseudoColor
@ SingleBandPseudoColor
Definition: qgsraster.h:93
QgsDataProvider::setDataSourceUri
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
Definition: qgsdataprovider.h:145
QgsRasterLayerRenderer
Implementation of threaded rendering for raster layers.
Definition: qgsrasterlayerrenderer.h:71
QgsRasterLayer::providerType
QString providerType() const
[ data provider interface ] Which provider is being used for this Raster Layer?
Definition: qgsrasterlayer.cpp:562
QgsDataSourceUri::setEncodedUri
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
Definition: qgsdatasourceuri.cpp:630
QgsRasterMinMaxOrigin::StdDev
@ StdDev
Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ].
Definition: qgsrasterminmaxorigin.h:62
QgsRasterLayer::writeXml
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files.
Definition: qgsrasterlayer.cpp:2095
QgsRasterPipe::setResamplingStage
void setResamplingStage(ResamplingStage stage)
Select which stage of the pipe should apply resampling.
Definition: qgsrasterpipe.cpp:345
QgsRasterViewPort::mWidth
qgssize mWidth
Width, number of columns to be rendered.
Definition: qgsrasterviewport.h:55
QgsBrightnessContrastFilter
Brightness/contrast and gamma correction filter pipe for rasters.
Definition: qgsbrightnesscontrastfilter.h:32
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsMapToPixel
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:38
QgsMapLayer::setName
void setName(const QString &name)
Set the display name of the layer.
Definition: qgsmaplayer.cpp:153
QgsRasterRenderer::legendSymbologyItems
virtual void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
Gets symbology items if provided by renderer.
Definition: qgsrasterrenderer.h:120
QgsColorRampShader::shade
bool shade(double value, int *returnRedValue, int *returnGreenValue, int *returnBlueValue, int *returnAlphaValue) const override
Generates and new RGB value based on one input value.
Definition: qgscolorrampshader.cpp:321
QgsRasterLayer::pipe
QgsRasterPipe * pipe()
Returns the raster pipe.
Definition: qgsrasterlayer.h:293
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type different from Byte.
Definition: qgsrasterlayer.h:85
QgsContrastEnhancement::contrastEnhancementAlgorithmFromString
static ContrastEnhancementAlgorithm contrastEnhancementAlgorithmFromString(const QString &contrastEnhancementString)
Deserialize ContrastEnhancementAlgorithm.
Definition: qgscontrastenhancement.cpp:361
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsHueSaturationFilter::GrayscaleOff
@ GrayscaleOff
Definition: qgshuesaturationfilter.h:38
QgsRasterResampleFilter
Resample filter pipe for rasters.
Definition: qgsrasterresamplefilter.h:33
QgsRasterInterface::IdentifyText
@ IdentifyText
Definition: qgsrasterinterface.h:192
QgsRasterInterface::input
virtual QgsRasterInterface * input() const
Current input.
Definition: qgsrasterinterface.h:269
QgsRasterDataProvider::setUseSourceNoDataValue
virtual void setUseSourceNoDataValue(int bandNo, bool use)
Sets the source nodata value usage.
Definition: qgsrasterdataprovider.cpp:34
QgsRasterMinMaxOrigin::setLimits
void setLimits(QgsRasterMinMaxOrigin::Limits limits)
Sets the limits.
Definition: qgsrasterminmaxorigin.h:116
qgsmultibandcolorrenderer.h
QgsRasterLayer::SINGLE_BAND_MIN_MAX_LIMITS
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
Definition: qgsrasterlayer.h:88
qgssettings.h
QgsRasterLayer::hueSaturationFilter
QgsHueSaturationFilter * hueSaturationFilter() const
Returns the raster's hue/saturation filter.
Definition: qgsrasterlayer.h:270
QgsRasterDataProvider::statusChanged
void statusChanged(const QString &) const
Emit a message to be displayed on status bar, usually used by network providers (WMS,...
QgsRasterLayer::refreshRendererIfNeeded
void refreshRendererIfNeeded(QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
Refresh renderer with new extent, if needed.
Definition: qgsrasterlayer.cpp:1193
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
Qgis::Int16
@ Int16
Sixteen bit signed integer (qint16)
Definition: qgis.h:106
QgsLegendColorList
QList< QPair< QString, QColor > > QgsLegendColorList
Definition: qgsrasterlayer.h:49
qgslayermetadataformatter.h
QgsMapLayer::name
QString name
Definition: qgsmaplayer.h:86
QgsRasterRange
Raster values range container.
Definition: qgsrasterrange.h:36
classFactoryFunction_t
QgsDataProvider * classFactoryFunction_t(const QString *, const QgsDataProvider::ProviderOptions &options)
Definition: qgsrasterlayer.cpp:209
QgsRasterLayer::brightnessFilter
QgsBrightnessContrastFilter * brightnessFilter() const
Returns the raster's brightness/contrast filter.
Definition: qgsrasterlayer.h:262
QgsRasterLayer::setDataProvider
Q_DECL_DEPRECATED void setDataProvider(const QString &provider)
Set the data provider.
Definition: qgsrasterlayer.cpp:203
qgsmaplayerlegend.h
QgsRaster::MultiBandColor
@ MultiBandColor
Definition: qgsraster.h:100
Qgis::Int32
@ Int32
Thirty two bit signed integer (qint32)
Definition: qgis.h:108
QgsRasterBandStats::stdDev
double stdDev
The standard deviation of the cell values.
Definition: qgsrasterbandstats.h:103
QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type Byte.
Definition: qgsrasterlayer.h:91
QgsRasterLayer::renderer
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
Definition: qgsrasterlayer.h:246
qgsrasterlayertemporalproperties.h
QgsRasterMinMaxOrigin::setExtent
void setExtent(QgsRasterMinMaxOrigin::Extent extent)
Sets the extent.
Definition: qgsrasterminmaxorigin.h:119
Qgis::CInt32
@ CInt32
Complex Int32.
Definition: qgis.h:112
qgsrasterrange.h
QgsDataProvider::subsetString
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
Definition: qgsdataprovider.h:269
QgsRasterDataProvider::setZoomedOutResamplingMethod
virtual bool setZoomedOutResamplingMethod(ResamplingMethod method)
Set resampling method to apply for zoomed-out operations.
Definition: qgsrasterdataprovider.h:641
QgsSingleBandPseudoColorRenderer
Raster renderer pipe for single band pseudocolor.
Definition: qgssinglebandpseudocolorrenderer.h:36
Qgis::ARGB32
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
Definition: qgis.h:115
QgsDataProvider::layerMetadata
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
Definition: qgsdataprovider.h:557
QgsRasterLayer::setSubLayerVisibility
void setSubLayerVisibility(const QString &name, bool vis) override
Set the visibility of the given sublayer name.
Definition: qgsrasterlayer.cpp:1427
QgsRasterLayer::isSpatial
bool isSpatial() const override
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
Definition: qgsrasterlayer.h:342
QgsRasterInterface::bandCount
virtual int bandCount() const =0
Gets number of bands.
QgsRasterPipe::projector
QgsRasterProjector * projector() const
Definition: qgsrasterpipe.cpp:258
QgsRasterShader::setRasterShaderFunction
void setRasterShaderFunction(QgsRasterShaderFunction *function)
A public method that allows the user to set their own shader function.
Definition: qgsrastershader.cpp:56
qgslogger.h
QgsRasterDataProvider::identifyFormatName
static QString identifyFormatName(QgsRaster::IdentifyFormat format)
Definition: qgsrasterdataprovider.cpp:461
QgsLayerMetadataFormatter::extentSectionHtml
QString extentSectionHtml(const bool showSpatialExtent=true) const
Formats the "Extents" section according to a metadata object (extent and temporal).
Definition: qgslayermetadataformatter.cpp:111
QgsRasterMinMaxOrigin::None
@ None
User defined.
Definition: qgsrasterminmaxorigin.h:60
QgsMapLayer::setValid
void setValid(bool valid)
Sets whether layer is valid or not.
Definition: qgsmaplayer.cpp:1775
QgsRasterMinMaxOrigin::CurrentCanvas
@ CurrentCanvas
Current extent of the canvas (at the time of computation) is used to compute statistics.
Definition: qgsrasterminmaxorigin.h:73
QgsRasterShader
Interface for all raster shaders.
Definition: qgsrastershader.h:35
QgsRasterMinMaxOrigin::extent
QgsRasterMinMaxOrigin::Extent extent() const
Returns the raster extent.
Definition: qgsrasterminmaxorigin.h:99
QgsRasterViewPort::mDestCRS
QgsCoordinateReferenceSystem mDestCRS
Target coordinate system.
Definition: qgsrasterviewport.h:67
QgsRasterLayer::writeStyle
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
Definition: qgsrasterlayer.cpp:2085
QgsSingleBandPseudoColorRenderer::shader
QgsRasterShader * shader()
Returns the raster shader.
Definition: qgssinglebandpseudocolorrenderer.h:58
QgsColorRampShader::Interpolated
@ Interpolated
Interpolates the color between two class breaks linearly.
Definition: qgscolorrampshader.h:47
Qgis::Byte
@ Byte
Eight bit unsigned integer (quint8)
Definition: qgis.h:104
QgsRaster::PaletteIndex
@ PaletteIndex
Paletted (see associated color table)
Definition: qgsraster.h:39
QgsRasterPipe::ResamplingStage
ResamplingStage
Stage at which resampling occurs.
Definition: qgsrasterpipe.h:139
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
QgsLayerMetadataFormatter::accessSectionHtml
QString accessSectionHtml() const
Formats the "Access" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:27
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
QgsMapLayer::setProviderType
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
Definition: qgsmaplayer.cpp:1899
QgsHueSaturationFilter::GrayscaleLightness
@ GrayscaleLightness
Definition: qgshuesaturationfilter.h:39
qgscoordinatereferencesystem.h
QgsRasterInterface::capabilities
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
Definition: qgsrasterinterface.h:206
QgsRasterLayer::createMapRenderer
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
Definition: qgsrasterlayer.cpp:252
QgsRasterLayer::showStatusMessage
void showStatusMessage(const QString &message)
Definition: qgsrasterlayer.cpp:1672
QgsRasterResampleFilter::setMaxOversampling
void setMaxOversampling(double os)
Definition: qgsrasterresamplefilter.h:55
QgsDataSourceUri::setPassword
void setPassword(const QString &password)
Sets the password for the URI.
Definition: qgsdatasourceuri.cpp:289
QgsRasterViewPort::mDrawnExtent
QgsRectangle mDrawnExtent
Intersection of current map extent and layer extent.
Definition: qgsrasterviewport.h:61
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:89
QgsDataProvider::setLayerOrder
virtual void setLayerOrder(const QStringList &layers)
Reorder the list of layer names to be rendered by this provider (in order from bottom to top)
Definition: qgsdataprovider.h:315
QgsRasterMinMaxOrigin::limits
QgsRasterMinMaxOrigin::Limits limits() const
Returns the raster limits.
Definition: qgsrasterminmaxorigin.h:96
QgsRasterPipe::size
int size() const
Definition: qgsrasterpipe.h:112
QgsMapLayer::setLegend
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
Definition: qgsmaplayer.cpp:1784
QgsRasterResampleFilter::setZoomedOutResampler
void setZoomedOutResampler(QgsRasterResampler *r)
Sets resampler for zoomed out scales. Takes ownership of the object.
Definition: qgsrasterresamplefilter.cpp:116
QgsMapLayer::metadata
QgsLayerMetadata metadata
Definition: qgsmaplayer.h:88
QgsProjectFileTransform::convertRasterProperties
static void convertRasterProperties(QDomDocument &doc, QDomNode &parentNode, QDomElement &rasterPropertiesElem, QgsRasterLayer *rlayer)
Definition: qgsprojectfiletransform.cpp:887
QgsRasterLayer::QgsRasterLayer
QgsRasterLayer()
Constructor. Provider is not set.
Definition: qgsrasterlayer.cpp:102
QgsRasterPipe::ResamplingStage::Provider
@ Provider
Resampling occurs in Provider.
QgsDataProvider::isValid
virtual bool isValid() const =0
Returns true if this is a valid layer.
QgsLayerMetadataFormatter::identificationSectionHtml
QString identificationSectionHtml() const
Formats the "Identification" section according to a metadata object.
Definition: qgslayermetadataformatter.cpp:181
QgsRasterMinMaxOrigin::cumulativeCutUpper
double cumulativeCutUpper() const
Returns the upper bound of cumulative cut method (between 0 and 1).
Definition: qgsrasterminmaxorigin.h:108
QgsRaster::ContinuousPalette
@ ContinuousPalette
Continuous palette, QGIS addition, GRASS.
Definition: qgsraster.h:54
QgsRasterLayer::rasterUnitsPerPixelX
double rasterUnitsPerPixelX() const
Returns the number of raster units per each raster pixel in X axis.
Definition: qgsrasterlayer.cpp:567
qgsrasterdataprovider.h
QgsReadWriteContext::pathResolver
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Definition: qgsreadwritecontext.cpp:47
qgsmessagelog.h
QgsDataProvider::crs
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
QgsMapLayer::error
virtual QgsError error() const
Gets current status error.
Definition: qgsmaplayer.cpp:1733
QgsRaster::IdentifyFormatUndefined
@ IdentifyFormatUndefined
Definition: qgsraster.h:59
QgsHueSaturationFilter::readXml
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
Definition: qgshuesaturationfilter.cpp:351
Qgis::Float64
@ Float64
Sixty four bit floating point (double)
Definition: qgis.h:110
QgsMapLayer::type
QgsMapLayerType type
Definition: qgsmaplayer.h:90