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