53 #include "qgsgdalprovider.h" 62 #include <QApplication> 65 #include <QDomElement> 70 #include <QFontMetrics> 76 #include <QMessageBox> 83 #define ERR(message) QGS_ERROR_MESSAGE(message,"Raster layer") 103 , QSTRING_NOT_SET( QStringLiteral(
"Not Set" ) )
104 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
112 const QString &baseName,
113 const QString &providerKey,
117 , QSTRING_NOT_SET( QStringLiteral(
"Not Set" ) )
118 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
150 for (
int i = 1; i < mPipe.
size(); i++ )
167 bool myIsValid = QgsGdalProvider::isValidRasterFileName( fileNameQString, retErrMsg );
182 QFileInfo fi( name );
188 t = fi.lastModified();
211 if ( !mDataProvider )
return 0;
227 return mDataProvider;
232 return mDataProvider;
275 drawer.draw( theQPainter, rasterViewPort, qgsMapToPixel );
277 QgsDebugMsgLevel( QStringLiteral(
"total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
282 QList< QPair< QString, QColor > > symbolList;
294 QString myMetadata = QStringLiteral(
"<html>\n<body>\n" );
297 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Information from provider" ) + QStringLiteral(
"</h1>\n<hr>\n" );
298 myMetadata += QLatin1String(
"<table class=\"list-view\">\n" );
301 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Name" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
306 if ( uriComponents.contains( QStringLiteral(
"path" ) ) )
308 path = uriComponents[QStringLiteral(
"path" )].toString();
309 if ( QFile::exists( path ) )
310 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" );
312 if ( uriComponents.contains( QStringLiteral(
"url" ) ) )
314 const QString url = uriComponents[QStringLiteral(
"url" )].toString();
315 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" );
320 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
324 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
327 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"CRS" ) + QStringLiteral(
"</td><td>" );
330 myMetadata +=
crs().
authid() + QStringLiteral(
" - " );
332 if (
crs().isGeographic() )
333 myMetadata += tr(
"Geographic" );
335 myMetadata += tr(
"Projected" );
337 myMetadata += QLatin1String(
"</td></tr>\n" );
340 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Extent" ) + QStringLiteral(
"</td><td>" ) +
extent().
toString() + QStringLiteral(
"</td></tr>\n" );
343 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Unit" ) + QStringLiteral(
"</td><td>" ) +
QgsUnitTypes::toString(
crs().mapUnits() ) + QStringLiteral(
"</td></tr>\n" );
346 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Width" ) + QStringLiteral(
"</td><td>" );
348 myMetadata += QString::number(
width() );
350 myMetadata += tr(
"n/a" );
351 myMetadata += QLatin1String(
"</td></tr>\n" );
354 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Height" ) + QStringLiteral(
"</td><td>" );
356 myMetadata += QString::number(
height() );
358 myMetadata += tr(
"n/a" );
359 myMetadata += QLatin1String(
"</td></tr>\n" );
362 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Data type" ) + QStringLiteral(
"</td><td>" );
367 myMetadata += tr(
"Byte - Eight bit unsigned integer" );
370 myMetadata += tr(
"UInt16 - Sixteen bit unsigned integer " );
373 myMetadata += tr(
"Int16 - Sixteen bit signed integer " );
376 myMetadata += tr(
"UInt32 - Thirty two bit unsigned integer " );
379 myMetadata += tr(
"Int32 - Thirty two bit signed integer " );
382 myMetadata += tr(
"Float32 - Thirty two bit floating point " );
385 myMetadata += tr(
"Float64 - Sixty four bit floating point " );
388 myMetadata += tr(
"CInt16 - Complex Int16 " );
391 myMetadata += tr(
"CInt32 - Complex Int32 " );
394 myMetadata += tr(
"CFloat32 - Complex Float32 " );
397 myMetadata += tr(
"CFloat64 - Complex Float64 " );
400 myMetadata += tr(
"Could not determine raster data type." );
402 myMetadata += QLatin1String(
"</td></tr>\n" );
408 myMetadata += QLatin1String(
"</table>\n<br><br>" );
411 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Identification" ) + QStringLiteral(
"</h1>\n<hr>\n" );
413 myMetadata += QLatin1String(
"<br><br>\n" );
416 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Extent" ) + QStringLiteral(
"</h1>\n<hr>\n" );
418 myMetadata += QLatin1String(
"<br><br>\n" );
421 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Access" ) + QStringLiteral(
"</h1>\n<hr>\n" );
423 myMetadata += QLatin1String(
"<br><br>\n" );
426 myMetadata += QStringLiteral(
"</table>\n<br><br><h1>" ) + tr(
"Bands" ) + QStringLiteral(
"</h1>\n<hr>\n<table class=\"list-view\">\n" );
429 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Band count" ) + QStringLiteral(
"</td><td>" ) + QString::number(
bandCount() ) + QStringLiteral(
"</td></tr>\n" );
432 myMetadata += QLatin1String(
"</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
433 myMetadata += QLatin1String(
"<tr><th>" ) + tr(
"Number" ) + QLatin1String(
"</th><th>" ) + tr(
"Band" ) + QLatin1String(
"</th><th>" ) + tr(
"No-Data" ) + QLatin1String(
"</th><th>" ) + tr(
"Min" ) + QLatin1String(
"</th><th>" ) + tr(
"Max" ) + QLatin1String(
"</th></tr>\n" );
440 rowClass = QStringLiteral(
"class=\"odd-row\"" );
441 myMetadata += QLatin1String(
"<tr " ) + rowClass + QLatin1String(
"><td>" ) + QString::number( i ) + QLatin1String(
"</td><td>" ) +
bandName( i ) + QLatin1String(
"</td><td>" );
444 myMetadata += QString::number(
dataProvider()->sourceNoDataValue( i ) );
446 myMetadata += tr(
"n/a" );
447 myMetadata += QLatin1String(
"</td>" );
452 myMetadata += QLatin1String(
"<td>" ) + QString::number( myRasterBandStats.
minimumValue,
'f', 10 ) + QLatin1String(
"</td>" );
453 myMetadata += QLatin1String(
"<td>" ) + QString::number( myRasterBandStats.
maximumValue,
'f', 10 ) + QLatin1String(
"</td>" );
457 myMetadata += QLatin1String(
"<td>" ) + tr(
"n/a" ) + QLatin1String(
"</td><td>" ) + tr(
"n/a" ) + QLatin1String(
"</td>" );
460 myMetadata += QLatin1String(
"</tr>\n" );
464 myMetadata += QLatin1String(
"</table>\n<br><br>" );
467 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Contacts" ) + QStringLiteral(
"</h1>\n<hr>\n" );
469 myMetadata += QLatin1String(
"<br><br>\n" );
472 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"References" ) + QStringLiteral(
"</h1>\n<hr>\n" );
474 myMetadata += QLatin1String(
"<br><br>\n" );
477 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"History" ) + QStringLiteral(
"</h1>\n<hr>\n" );
479 myMetadata += QLatin1String(
"<br><br>\n" );
481 myMetadata += QStringLiteral(
"\n</body>\n</html>\n" );
496 QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->
colorTable( bandNumber );
497 if ( !myColorRampItemList.isEmpty() )
504 QPixmap myPalettePixmap( mySize, mySize );
505 QPainter myQPainter( &myPalettePixmap );
507 QImage myQImage = QImage( mySize, mySize, QImage::Format_RGB32 );
509 myPalettePixmap.fill();
511 double myStep = (
static_cast< double >( myColorRampItemList.size() ) - 1 ) /
static_cast< double >( mySize * mySize );
512 double myValue = 0.0;
513 for (
int myRow = 0; myRow < mySize; myRow++ )
515 QRgb *myLineBuffer =
reinterpret_cast< QRgb *
>( myQImage.scanLine( myRow ) );
516 for (
int myCol = 0; myCol < mySize; myCol++ )
518 myValue = myStep *
static_cast< double >( myCol + myRow * mySize );
520 myShader.
shade( myValue, &c1, &c2, &c3, &c4 );
521 myLineBuffer[ myCol ] = qRgba( c1, c2, c3, c4 );
525 myQPainter.drawImage( 0, 0, myQImage );
526 return myPalettePixmap;
528 QPixmap myNullPixmap;
534 QPixmap myNullPixmap;
568 void QgsRasterLayer::init()
586 mPipe.
remove( mDataProvider );
587 mDataProvider =
nullptr;
602 if ( !mDataProvider )
609 mDataProvider->setParent(
this );
612 mPipe.
set( mDataProvider );
613 if ( !mDataProvider->
isValid() )
623 QgsDebugMsgLevel( QStringLiteral(
"Set Data provider QgsLayerMetadata identifier[%1]" ).arg(
metadata().identifier() ), 4 );
626 if ( provider == QLatin1String(
"gdal" ) )
658 if ( ( mDataProvider->
bandCount() > 1 ) )
706 QList<QgsColorRampShader::ColorRampItem> colorTable = mDataProvider->
colorTable( 1 );
729 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
743 mPipe.
set( brightnessFilter );
747 mPipe.
set( hueSaturationFilter );
751 mPipe.
set( resampleFilter );
756 QString resampling = settings.
value( QStringLiteral(
"/Raster/defaultZoomedInResampling" ), QStringLiteral(
"nearest neighbour" ) ).toString();
757 if ( resampling == QStringLiteral(
"bilinear" ) )
761 else if ( resampling == QStringLiteral(
"cubic" ) )
765 resampling = settings.
value( QStringLiteral(
"/Raster/defaultZoomedOutResampling" ), QStringLiteral(
"nearest neighbour" ) ).toString();
766 if ( resampling == QStringLiteral(
"bilinear" ) )
770 resampleFilter->
setMaxOversampling( settings.
value( QStringLiteral(
"/Raster/defaultOversampling" ), 2.0 ).toDouble() );
775 mPipe.
set( projector );
816 QDomImplementation domImplementation;
817 QDomDocumentType documentType;
821 if ( hadRenderer && ! loadDefaultStyleFlag )
823 documentType = domImplementation.createDocumentType(
824 QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
826 QDomDocument doc = QDomDocument( documentType );
827 QDomElement styleElem = doc.createElement( QStringLiteral(
"qgis" ) );
832 QgsDebugMsg( QStringLiteral(
"Could not store symbology for layer %1: %2" )
838 doc.appendChild( styleElem );
840 mOriginalStyleDocument = doc;
841 mOriginalStyleElement = styleElem;
850 for (
int i = mPipe.
size() - 1; i >= 0; --i )
863 bool defaultLoadedFlag =
false;
864 bool restoredStyle =
false;
865 if ( loadDefaultStyleFlag )
869 else if ( !mOriginalStyleElement.isNull() )
872 if ( !
readSymbology( mOriginalStyleElement, errorMsg, readContext ) )
874 QgsDebugMsg( QStringLiteral(
"Could not restore symbology for layer %1: %2" )
881 restoredStyle =
true;
888 if ( !defaultLoadedFlag && !restoredStyle )
898 void QgsRasterLayer::closeDataProvider()
901 mPipe.
remove( mDataProvider );
902 mDataProvider =
nullptr;
905 void QgsRasterLayer::computeMinMax(
int band,
910 double &min,
double &max )
913 min = std::numeric_limits<double>::quiet_NaN();
914 max = std::numeric_limits<double>::quiet_NaN();
932 QgsDebugMsgLevel( QStringLiteral(
"myLower = %1 myUpper = %2" ).arg( myLower ).arg( myUpper ), 4 );
933 mDataProvider->
cumulativeCut( band, myLower, myUpper, min, max, extent, sampleSize );
935 QgsDebugMsgLevel( QStringLiteral(
"band = %1 min = %2 max = %3" ).arg( band ).arg( min ).arg( max ), 4 );
941 return mDataProvider ? mDataProvider->
ignoreExtents() :
false;
950 generateLookupTableFlag,
958 bool generateLookupTableFlag,
962 if ( !rasterRenderer || !mDataProvider )
968 QList<QgsContrastEnhancement *> myEnhancements;
974 QString rendererType = rasterRenderer->
type();
975 if ( rendererType == QLatin1String(
"singlebandgray" ) )
978 if ( !myGrayRenderer )
982 myBands << myGrayRenderer->
grayBand();
983 myRasterRenderer = myGrayRenderer;
986 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
989 if ( !myMultiBandRenderer )
994 myRasterRenderer = myMultiBandRenderer;
997 else if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
1000 if ( !myPseudoColorRenderer )
1004 myBands << myPseudoColorRenderer->
band();
1005 myRasterRenderer = myPseudoColorRenderer;
1006 myMinMaxOrigin = myPseudoColorRenderer->
minMaxOrigin();
1013 const auto constMyBands = myBands;
1014 for (
int myBand : constMyBands )
1019 std::unique_ptr<QgsContrastEnhancement> myEnhancement(
new QgsContrastEnhancement( static_cast< Qgis::DataType >( myType ) ) );
1020 myEnhancement->setContrastEnhancementAlgorithm(
algorithm, generateLookupTableFlag );
1024 computeMinMax( myBand, myMinMaxOrigin, limits, extent, sampleSize, min, max );
1026 if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
1030 if ( myPseudoColorRenderer->
shader() )
1033 if ( colorRampShader )
1041 myEnhancement->setMinimumValue( min );
1042 myEnhancement->setMaximumValue( max );
1043 myEnhancements.append( myEnhancement.release() );
1048 myEnhancements.append(
nullptr );
1052 if ( rendererType == QLatin1String(
"singlebandgray" ) )
1056 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
1064 qDeleteAll( myEnhancements );
1072 if ( myRasterRenderer )
1077 if ( rasterRenderer ==
renderer() )
1090 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) ) )
1094 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) ) )
1129 if ( !( mDataProvider &&
1130 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded != extent &&
1139 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>( rasterRenderer ) ) )
1143 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>( rasterRenderer ) ) )
1147 else if ( ( sbpcr = dynamic_cast<QgsSingleBandPseudoColorRenderer *>( rasterRenderer ) ) )
1149 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1152 computeMinMax( sbpcr->
band(),
1162 if ( colorRampShader )
1175 if ( colorRampShader )
1190 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1200 if ( singleBandRenderer )
1202 else if ( multiBandRenderer )
1231 QString defaultLimits;
1234 if ( dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) )
1236 key = QStringLiteral(
"singleBand" );
1242 else if ( dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) )
1246 key = QStringLiteral(
"multiBandSingleByte" );
1254 key = QStringLiteral(
"multiBandMultiByte" );
1262 if ( key.isEmpty() )
1264 QgsDebugMsg( QStringLiteral(
"No default contrast enhancement for this drawing style" ) );
1271 QString myAlgorithmString = mySettings.
value(
"/Raster/defaultContrastEnhancementAlgorithm/" + key, defaultAlg ).toString();
1276 QString myLimitsString = mySettings.
value(
"/Raster/defaultContrastEnhancementLimits/" + key, defaultLimits ).toString();
1298 if ( mDataProvider )
1300 QgsDebugMsgLevel( QStringLiteral(
"About to mDataProvider->setLayerOrder(layers)." ), 4 );
1309 if ( mDataProvider )
1311 QgsDebugMsgLevel( QStringLiteral(
"About to mDataProvider->setSubLayerVisibility(name, vis)." ), 4 );
1335 Q_UNUSED( errorMessage )
1347 QDomElement constraintElem = doc.createElement( QStringLiteral(
"sld:LayerFeatureConstraints" ) );
1348 node.appendChild( constraintElem );
1350 QDomElement featureTypeConstraintElem = doc.createElement( QStringLiteral(
"sld:FeatureTypeConstraint" ) );
1351 constraintElem.appendChild( featureTypeConstraintElem );
1353 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"sld:UserStyle" ) );
1354 node.appendChild( userStyleElem );
1356 if ( !
name().isEmpty() )
1358 QDomElement nameElem = doc.createElement( QStringLiteral(
"sld:Name" ) );
1359 nameElem.appendChild( doc.createTextNode(
name() ) );
1360 userStyleElem.appendChild( nameElem );
1363 if ( !
abstract().isEmpty() )
1365 QDomElement abstractElem = doc.createElement( QStringLiteral(
"sld:Abstract" ) );
1366 abstractElem.appendChild( doc.createTextNode(
abstract() ) );
1367 userStyleElem.appendChild( abstractElem );
1370 if ( !
title().isEmpty() )
1372 QDomElement titleElem = doc.createElement( QStringLiteral(
"sld:Title" ) );
1373 titleElem.appendChild( doc.createTextNode(
title() ) );
1374 userStyleElem.appendChild( titleElem );
1377 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"sld:FeatureTypeStyle" ) );
1378 userStyleElem.appendChild( featureTypeStyleElem );
1388 QDomElement typeStyleNameElem = doc.createElement( QStringLiteral(
"sld:Name" ) );
1389 featureTypeStyleElem.appendChild( typeStyleNameElem );
1392 QDomElement typeStyleRuleElem = doc.createElement( QStringLiteral(
"sld:Rule" ) );
1393 featureTypeStyleElem.appendChild( typeStyleRuleElem );
1401 QDomElement minScaleElem = doc.createElement( QStringLiteral(
"sld:MinScaleDenominator" ) );
1402 minScaleElem.appendChild( doc.createTextNode( QString::number(
maximumScale() ) ) );
1403 typeStyleRuleElem.appendChild( minScaleElem );
1406 QDomElement maxScaleElem = doc.createElement( QStringLiteral(
"sld:MaxScaleDenominator" ) );
1407 maxScaleElem.appendChild( doc.createTextNode( QString::number(
minimumScale() ) ) );
1408 typeStyleRuleElem.appendChild( maxScaleElem );
1412 mPipe.
renderer()->
toSld( doc, typeStyleRuleElem, localProps );
1417 QDomNodeList elements = typeStyleRuleElem.elementsByTagName( QStringLiteral(
"sld:RasterSymbolizer" ) );
1418 if ( elements.size() != 0 )
1421 QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();
1424 auto vendorOptionWriter = [&]( QString
name, QString value )
1426 QDomElement vendorOptionElem = doc.createElement( QStringLiteral(
"sld:VendorOption" ) );
1427 vendorOptionElem.setAttribute( QStringLiteral(
"name" ), name );
1428 vendorOptionElem.appendChild( doc.createTextNode( value ) );
1429 rasterSymbolizerElem.appendChild( vendorOptionElem );
1439 property = QStringLiteral(
"lightness" );
1442 property = QStringLiteral(
"luminosity" );
1445 property = QStringLiteral(
"average" );
1451 if ( !property.isEmpty() )
1452 vendorOptionWriter( QStringLiteral(
"grayScale" ), property );
1458 vendorOptionWriter( QStringLiteral(
"colorizeOn" ), QString::number(
hueSaturationFilter()->colorizeOn() ) );
1459 vendorOptionWriter( QStringLiteral(
"colorizeRed" ), QString::number(
hueSaturationFilter()->colorizeColor().red() ) );
1460 vendorOptionWriter( QStringLiteral(
"colorizeGreen" ), QString::number(
hueSaturationFilter()->colorizeColor().green() ) );
1461 vendorOptionWriter( QStringLiteral(
"colorizeBlue" ), QString::number(
hueSaturationFilter()->colorizeColor().blue() ) );
1463 vendorOptionWriter( QStringLiteral(
"colorizeStrength" ), QString::number(
hueSaturationFilter()->colorizeStrength() / 100.0 ) );
1464 vendorOptionWriter( QStringLiteral(
"saturation" ), QString::number(
hueSaturationFilter()->colorizeColor().saturationF() ) );
1473 double sF = ( s - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1474 vendorOptionWriter( QStringLiteral(
"saturation" ), QString::number( sF ) );
1483 double bF = ( b - ( -255.0 ) ) / ( 255.0 - ( -255.0 ) );
1484 vendorOptionWriter( QStringLiteral(
"brightness" ), QString::number( bF ) );
1492 double cF = ( c - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1493 vendorOptionWriter( QStringLiteral(
"contrast" ), QString::number( cF ) );
1507 if ( newProps.contains( QStringLiteral(
"contrast" ) ) )
1510 double contrast = newProps[ QStringLiteral(
"contrast" ) ].toDouble();
1511 double percentage = ( contrast - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1512 if ( percentage <= 0.5 )
1515 gamma = percentage / 0.5;
1522 QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral(
"sld:ContrastEnhancement" ) );
1523 rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1525 QDomElement gammaValueElem = doc.createElement( QStringLiteral(
"sld:GammaValue" ) );
1526 gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1527 globalContrastEnhancementElem.appendChild( gammaValueElem );
1544 mPipe.
set( renderer );
1560 if ( mDataProvider )
1573 QImage image( size, format );
1578 if ( image.format() == QImage::Format_Indexed8 )
1580 image.setColor( 0, bgColor.rgba() );
1585 image.fill( bgColor );
1590 double mapUnitsPerPixel;
1594 if ( extent.
width() / extent.
height() >=
static_cast< double >( image.width() ) / image.height() )
1596 mapUnitsPerPixel = extent.
width() / image.width();
1597 y = ( image.height() - extent.
height() / mapUnitsPerPixel ) / 2;
1601 mapUnitsPerPixel = extent.
height() / image.height();
1602 x = ( image.width() - extent.
width() / mapUnitsPerPixel ) / 2;
1605 const double pixelWidth = extent.
width() / mapUnitsPerPixel;
1606 const double pixelHeight = extent.
height() / mapUnitsPerPixel;
1610 rasterViewPort->
mWidth = image.width();
1611 rasterViewPort->
mHeight = image.height();
1619 QPainter *painter =
new QPainter( &image );
1620 draw( painter, rasterViewPort, mapToPixel );
1621 delete rasterViewPort;
1643 Q_UNUSED( errorMessage )
1646 QDomElement rasterRendererElem;
1648 QDomElement layerElement = layer_node.toElement();
1655 QDomNode pipeNode = layer_node.firstChildElement( QStringLiteral(
"pipe" ) );
1656 if ( pipeNode.isNull() )
1658 pipeNode = layer_node;
1662 if ( !layer_node.firstChildElement( QStringLiteral(
"rasterproperties" ) ).isNull() )
1665 QDomNode layerNodeCopy = layer_node.cloneNode();
1666 QDomDocument doc = layerNodeCopy.ownerDocument();
1667 QDomElement rasterPropertiesElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterproperties" ) );
1670 rasterRendererElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1675 rasterRendererElem = pipeNode.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1678 if ( !rasterRendererElem.isNull() )
1680 QString rendererType = rasterRendererElem.attribute( QStringLiteral(
"type" ) );
1685 mPipe.
set( renderer );
1691 mPipe.
set( brightnessFilter );
1694 QDomElement brightnessElem = pipeNode.firstChildElement( QStringLiteral(
"brightnesscontrast" ) );
1695 if ( !brightnessElem.isNull() )
1697 brightnessFilter->
readXml( brightnessElem );
1702 mPipe.
set( hueSaturationFilter );
1705 QDomElement hueSaturationElem = pipeNode.firstChildElement( QStringLiteral(
"huesaturation" ) );
1706 if ( !hueSaturationElem.isNull() )
1708 hueSaturationFilter->
readXml( hueSaturationElem );
1713 mPipe.
set( resampleFilter );
1716 QDomElement resampleElem = pipeNode.firstChildElement( QStringLiteral(
"rasterresampler" ) );
1717 if ( !resampleElem.isNull() )
1719 resampleFilter->
readXml( resampleElem );
1723 QDomNode blendModeNode = layer_node.namedItem( QStringLiteral(
"blendMode" ) );
1724 if ( !blendModeNode.isNull() )
1726 QDomElement e = blendModeNode.toElement();
1737 return readSymbology( node, errorMessage, context, categories );
1746 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
1748 if ( pkeyNode.isNull() )
1754 QDomElement pkeyElt = pkeyNode.toElement();
1768 QDomNode rpNode = layer_node.namedItem( QStringLiteral(
"rasterproperties" ) );
1774 if ( !
mDataSource.contains( QLatin1String(
"crs=" ) ) && !
mDataSource.contains( QLatin1String(
"format=" ) ) )
1776 QgsDebugMsgLevel( QStringLiteral(
"Old WMS URI format detected -> adding params" ), 4 );
1779 QDomElement layerElement = rpNode.firstChildElement( QStringLiteral(
"wmsSublayer" ) );
1780 while ( !layerElement.isNull() )
1785 uri.
setParam( QStringLiteral(
"layers" ), layerElement.namedItem( QStringLiteral(
"name" ) ).toElement().text() );
1788 uri.
setParam( QStringLiteral(
"styles" ), layerElement.namedItem( QStringLiteral(
"style" ) ).toElement().text() );
1790 layerElement = layerElement.nextSiblingElement( QStringLiteral(
"wmsSublayer" ) );
1794 QDomNode formatNode = rpNode.namedItem( QStringLiteral(
"wmsFormat" ) );
1795 uri.
setParam( QStringLiteral(
"format" ), rpNode.namedItem( QStringLiteral(
"wmsFormat" ) ).toElement().text() );
1799 uri.
setParam( QStringLiteral(
"crs" ),
crs().authid() );
1811 mOriginalStyleElement = layer_node.namedItem( QStringLiteral(
"originalStyle" ) ).firstChildElement();
1812 if ( mOriginalStyleElement.isNull() )
1813 mOriginalStyleElement = layer_node.toElement();
1814 mOriginalStyleDocument = layer_node.ownerDocument();
1816 if ( ! mDataProvider )
1818 if ( !(
mReadFlags & QgsMapLayer::FlagDontResolveLayers ) )
1840 QDomNode stampNode = layer_node.namedItem(
"timestamp" );
1841 if ( !stampNode.isNull() )
1843 QDateTime stamp = QDateTime::fromString( stampNode.toElement().text(), Qt::ISODate );
1845 if ( stamp < mDataProvider->dataTimestamp() )
1847 QgsDebugMsg( QStringLiteral(
"data changed, reload provider" ) );
1848 closeDataProvider();
1851 if ( !
mValid )
return false;
1857 QDomElement noDataElement = layer_node.firstChildElement( QStringLiteral(
"noData" ) );
1859 QDomNodeList noDataBandList = noDataElement.elementsByTagName( QStringLiteral(
"noDataList" ) );
1861 for (
int i = 0; i < noDataBandList.size(); ++i )
1863 QDomElement bandElement = noDataBandList.at( i ).toElement();
1865 int bandNo = bandElement.attribute( QStringLiteral(
"bandNo" ) ).toInt( &ok );
1867 if ( ok && ( bandNo > 0 ) && ( bandNo <= mDataProvider->
bandCount() ) )
1869 mDataProvider->
setUseSourceNoDataValue( bandNo, bandElement.attribute( QStringLiteral(
"useSrcNoData" ) ).toInt() );
1872 QDomNodeList rangeList = bandElement.elementsByTagName( QStringLiteral(
"noDataRange" ) );
1874 myNoDataRangeList.reserve( rangeList.size() );
1875 for (
int j = 0; j < rangeList.size(); ++j )
1877 QDomElement rangeElement = rangeList.at( j ).toElement();
1878 QgsRasterRange myNoDataRange( rangeElement.attribute( QStringLiteral(
"min" ) ).toDouble(),
1879 rangeElement.attribute( QStringLiteral(
"max" ) ).toDouble() );
1880 QgsDebugMsgLevel( QStringLiteral(
"min = %1 %2" ).arg( rangeElement.attribute(
"min" ) ).arg( myNoDataRange.min() ), 4 );
1881 myNoDataRangeList << myNoDataRange;
1895 Q_UNUSED( errorMessage )
1898 QDomElement layerElement = layer_node.toElement();
1903 QDomElement pipeElement = document.createElement( QStringLiteral(
"pipe" ) );
1905 for (
int i = 1; i < mPipe.
size(); i++ )
1908 if ( !interface )
continue;
1909 interface->writeXml( document, pipeElement );
1912 layer_node.appendChild( pipeElement );
1914 if ( !
isValid() && !mOriginalStyleElement.isNull() )
1916 QDomElement originalStyleElement = document.createElement( QStringLiteral(
"originalStyle" ) );
1917 originalStyleElement.appendChild( mOriginalStyleElement );
1918 layer_node.appendChild( originalStyleElement );
1922 QDomElement blendModeElement = document.createElement( QStringLiteral(
"blendMode" ) );
1924 blendModeElement.appendChild( blendModeText );
1925 layer_node.appendChild( blendModeElement );
1932 return writeSymbology( node, doc, errorMessage, context, categories );
1940 QDomDocument &document,
1945 QDomElement mapLayerNode = layer_node.toElement();
1947 if ( mapLayerNode.isNull() ||
"maplayer" != mapLayerNode.nodeName() )
1953 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"raster" ) );
1957 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
1958 QDomText providerText = document.createTextNode(
mProviderKey );
1959 provider.appendChild( providerText );
1960 layer_node.appendChild( provider );
1963 QDomElement noData = document.createElement( QStringLiteral(
"noData" ) );
1965 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
1967 QDomElement noDataRangeList = document.createElement( QStringLiteral(
"noDataList" ) );
1968 noDataRangeList.setAttribute( QStringLiteral(
"bandNo" ), bandNo );
1969 noDataRangeList.setAttribute( QStringLiteral(
"useSrcNoData" ), mDataProvider->
useSourceNoDataValue( bandNo ) );
1971 const auto constUserNoDataValues = mDataProvider->
userNoDataValues( bandNo );
1974 QDomElement noDataRange = document.createElement( QStringLiteral(
"noDataRange" ) );
1978 noDataRangeList.appendChild( noDataRange );
1981 noData.appendChild( noDataRangeList );
1984 if ( noData.hasChildNodes() )
1986 layer_node.appendChild( noData );
1993 return writeSymbology( layer_node, document, errorMsg, context );
1997 static bool _parseGpkgColons(
const QString &src, QString &filename, QString &tablename )
2002 QStringList lst = src.split(
':' );
2003 if ( lst.count() != 3 && lst.count() != 4 )
2006 tablename = lst.last();
2007 if ( lst.count() == 3 )
2012 else if ( lst.count() == 4 && lst[1].count() == 1 && ( lst[2][0] ==
'/' || lst[2][0] ==
'\\' ) )
2015 filename = lst[1] +
":" + lst[2];
2024 QString src( source );
2025 bool handled =
false;
2030 if ( src.startsWith( QLatin1String(
"NETCDF:" ) ) )
2034 QRegExp r(
"NETCDF:(.+):([^:]+)" );
2035 if ( r.exactMatch( src ) )
2037 QString filename = r.cap( 1 );
2038 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2039 filename = filename.mid( 1, filename.length() - 2 );
2044 else if ( src.startsWith( QLatin1String(
"GPKG:" ) ) )
2047 QString filename, tablename;
2048 if ( _parseGpkgColons( src, filename, tablename ) )
2051 src = QStringLiteral(
"GPKG:%1:%2" ).arg( filename, tablename );
2055 else if ( src.startsWith( QLatin1String(
"HDF4_SDS:" ) ) )
2059 QRegExp r(
"HDF4_SDS:([^:]+):(.+):([^:]+)" );
2060 if ( r.exactMatch( src ) )
2062 QString filename = r.cap( 2 );
2063 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2064 filename = filename.mid( 1, filename.length() - 2 );
2065 src =
"HDF4_SDS:" + r.cap( 1 ) +
":\"" + context.
pathResolver().
writePath( filename ) +
"\":" + r.cap( 3 );
2069 else if ( src.startsWith( QLatin1String(
"HDF5:" ) ) )
2073 QRegExp r(
"HDF5:(.+):([^:]+)" );
2074 if ( r.exactMatch( src ) )
2076 QString filename = r.cap( 1 );
2077 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2078 filename = filename.mid( 1, filename.length() - 2 );
2083 else if ( src.contains( QRegExp(
"^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2087 QRegExp r(
"([^:]+):([^:]+):(.+)" );
2088 if ( r.exactMatch( src ) )
2100 QUrl srcUrl( uri.
param( QStringLiteral(
"url" ) ) );
2101 if ( srcUrl.isLocalFile() )
2106 uri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
2120 QString src( source );
2122 if ( provider == QLatin1String(
"wms" ) )
2136 if ( !src.contains( QLatin1String(
"type=" ) ) &&
2137 !src.contains( QLatin1String(
"crs=" ) ) && !src.contains( QLatin1String(
"format=" ) ) )
2139 QgsDebugMsg( QStringLiteral(
"Old WMS URI format detected -> converting to new format" ) );
2141 if ( !src.startsWith( QLatin1String(
"http:" ) ) )
2143 QStringList parts = src.split(
',' );
2144 QStringListIterator iter( parts );
2145 while ( iter.hasNext() )
2147 QString item = iter.next();
2148 if ( item.startsWith( QLatin1String(
"username=" ) ) )
2150 uri.
setParam( QStringLiteral(
"username" ), item.mid( 9 ) );
2152 else if ( item.startsWith( QLatin1String(
"password=" ) ) )
2154 uri.
setParam( QStringLiteral(
"password" ), item.mid( 9 ) );
2156 else if ( item.startsWith( QLatin1String(
"tiled=" ) ) )
2162 QStringList params = item.mid( 6 ).split(
';' );
2164 if ( params.size() == 2 )
2166 uri.
setParam( QStringLiteral(
"maxWidth" ), params.takeFirst() );
2167 uri.
setParam( QStringLiteral(
"maxHeight" ), params.takeFirst() );
2169 else if ( params.size() > 2 )
2173 uri.
setParam( QStringLiteral(
"tileMatrixSet" ), QString() );
2176 else if ( item.startsWith( QLatin1String(
"featureCount=" ) ) )
2178 uri.
setParam( QStringLiteral(
"featureCount" ), item.mid( 13 ) );
2180 else if ( item.startsWith( QLatin1String(
"url=" ) ) )
2182 uri.
setParam( QStringLiteral(
"url" ), item.mid( 4 ) );
2184 else if ( item.startsWith( QLatin1String(
"ignoreUrl=" ) ) )
2186 uri.
setParam( QStringLiteral(
"ignoreUrl" ), item.mid( 10 ).split(
';' ) );
2192 uri.
setParam( QStringLiteral(
"url" ), src );
2203 QUrl srcUrl( uri.
param( QStringLiteral(
"url" ) ) );
2204 if ( srcUrl.isLocalFile() )
2208 uri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
2215 bool handled =
false;
2217 if ( provider == QLatin1String(
"gdal" ) )
2219 if ( src.startsWith( QLatin1String(
"NETCDF:" ) ) )
2223 QRegExp r(
"NETCDF:(.+):([^:]+)" );
2224 if ( r.exactMatch( src ) )
2226 QString filename = r.cap( 1 );
2227 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2228 filename = filename.mid( 1, filename.length() - 2 );
2233 else if ( src.startsWith( QLatin1String(
"GPKG:" ) ) )
2236 QString filename, tablename;
2237 if ( _parseGpkgColons( src, filename, tablename ) )
2240 src = QStringLiteral(
"GPKG:%1:%2" ).arg( filename, tablename );
2244 else if ( src.startsWith( QLatin1String(
"HDF4_SDS:" ) ) )
2248 QRegExp r(
"HDF4_SDS:([^:]+):(.+):([^:]+)" );
2249 if ( r.exactMatch( src ) )
2251 QString filename = r.cap( 2 );
2252 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2253 filename = filename.mid( 1, filename.length() - 2 );
2254 src =
"HDF4_SDS:" + r.cap( 1 ) +
":\"" + context.
pathResolver().
readPath( filename ) +
"\":" + r.cap( 3 );
2258 else if ( src.startsWith( QLatin1String(
"HDF5:" ) ) )
2262 QRegExp r(
"HDF5:(.+):([^:]+)" );
2263 if ( r.exactMatch( src ) )
2265 QString filename = r.cap( 1 );
2266 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2267 filename = filename.mid( 1, filename.length() - 2 );
2272 else if ( src.contains( QRegExp(
"^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2276 QRegExp r(
"([^:]+):([^:]+):(.+)" );
2277 if ( r.exactMatch( src ) )
2294 if ( !mDataProvider )
return 0;
2295 return mDataProvider->
xSize();
2300 if ( !mDataProvider )
return 0;
2301 return mDataProvider->
ySize();
2309 bool QgsRasterLayer::update()
2316 closeDataProvider();
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.
QgsDataProvider * classFactoryFunction_t(const QString *, const QgsDataProvider::ProviderOptions &options)
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
int width() const
Returns the width of the (unclipped) raster.
QgsRasterMinMaxOrigin::Limits limits() const
Returns the raster limits.
bool shade(double value, int *returnRedValue, int *returnGreenValue, int *returnBlueValue, int *returnAlphaValue) const override
Generates and new RGB value based on one input value.
virtual int bandCount() const =0
Gets number of bands.
QgsRasterMinMaxOrigin::Extent extent() const
Returns the raster extent.
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
Base class for all map layer types.
Thirty two bit signed integer (qint32)
Interface for all raster shaders.
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &list)
Sets a custom colormap.
QgsRasterLayer * clone() const override
Returns a new instance equivalent to this one.
QStringList subLayers() const override
Returns the sublayers of this layer.
static const QString QGIS_VERSION
Version string.
static QString printValue(double value)
Print double value with all necessary significant digits.
void refreshContrastEnhancement(const QgsRectangle &extent)
Refresh contrast enhancement with new extent.
virtual void setUseSourceNoDataValue(int bandNo, bool use)
Sets the source nodata value usage.
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
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.
const QgsContrastEnhancement * blueContrastEnhancement() const
QgsMapLayerType type() const
Returns the type of the layer.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
void setMaxOversampling(double os)
Iterator for sequentially processing raster cells.
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type different from Byte.
int bandCount() const
Returns the number of bands in this layer.
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.
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
This class is a composition of two QSettings instances:
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
QgsHueSaturationFilter * hueSaturationFilter() const
Returns the raster's hue/saturation filter.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
DrawingStyle
This enumerator describes the different kinds of drawing we can do.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
virtual QgsError error() const
Gets current status error.
QgsRasterRenderer * renderer() const
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setRenderer(QgsRasterRenderer *renderer)
Sets the raster's renderer.
virtual QgsError error() const
Gets current status error.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
void setLayerOrder(const QStringList &layers) override
Reorders the previously selected sublayers of this layer from bottom to top.
double rasterUnitsPerPixelX() const
Returns the number of raster units per each raster pixel in X axis.
QString mProviderKey
Data provider key (name of the data provider)
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
QgsRasterPipe * pipe()
Returns the raster pipe.
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...
A class to represent a 2D point.
virtual bool ignoreExtents() const
Returns true if the extents reported by the data provider are not reliable and it's possible that the...
void setDefaultContrastEnhancement()
Sets the default contrast enhancement.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void showStatusMessage(const QString &message)
virtual QgsRasterInterface * input() const
Current input.
QgsRasterProjector * projector() const
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
virtual QString type() const
Thirty two bit unsigned integer (quint32)
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
DataType
Raster data types.
QgsRasterInterface * last() const
double maximumValue
The maximum cell value in the raster band.
static Limits limitsFromString(const QString &limits)
Deserialize Limits.
const QgsContrastEnhancement * contrastEnhancement() const
virtual int ySize() const
int mWidth
Width, number of columns to be rendered.
bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files...
virtual const QgsLayerMetadata & metadata() const
Returns a reference to the layer's metadata store.
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis.
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...
static QDateTime lastModified(const QString &name)
Returns time stamp for given file name.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Raster values range container.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
Resample filter pipe for rasters.
Abstract base class for spatial data provider implementations.
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
int height() const
Returns the height of the (unclipped) raster.
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
Thirty two bit floating point (float)
bool isValid() const
Returns the status of the layer.
An interface for classes which can visit style entity (e.g.
Implementation of threaded rendering for raster layers.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
QgsRasterShader * shader()
Returns the raster shader.
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.
QPixmap paletteAsPixmap(int bandNumber=1)
Returns a 100x100 pixmap of the color palette.
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
QMap< QString, QString > QgsStringMap
Sixteen bit signed integer (qint16)
void setClassificationMax(double max)
QDateTime timestamp() const override
Time stamp of data source in the moment when data/metadata were loaded by provider.
QString mLayerName
Name of the layer - used for display.
void setShader(QgsRasterShader *shader)
Takes ownership of the shader.
void styleChanged()
Signal emitted whenever a change affects the layer's style.
void setGreenContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
void statusChanged(const QString &) const
Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
Sixty four bit floating point (double)
Current extent of the canvas (at the time of computation) is used to compute statistics.
static QString identifyFormatName(QgsRaster::IdentifyFormat format)
virtual QgsRectangle extent() const
Returns the extent of the layer.
void setExtent(QgsRasterMinMaxOrigin::Extent extent)
Sets the extent.
QgsCoordinateReferenceSystem mDestCRS
Target coordinate system.
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
Creates a new instance of a provider.
QgsBrightnessContrastFilter * brightnessFilter() const
Returns the raster's brightness/contrast filter.
Provider benefits from resampling and should apply user default resampling settings (since QGIS 3...
QDateTime timestamp() const override
Time stamp of data source in the moment when data/metadata were loaded by provider.
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar) ...
double cumulativeCutLower() const
Returns the lower bound of cumulative cut method (between 0 and 1).
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
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Perform transforms between map coordinates and device coordinates.
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type Byte.
The drawing pipe for raster layers.
double stdDev
The standard deviation of the cell values.
Paletted (see associated color table)
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.
void setColorRampType(QgsColorRampShader::Type colorRampType)
Sets the color ramp type.
Alpha (0=transparent, 255=opaque)
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
This class describes the origin of min/max values.
The RasterBandStats struct is a container for statistics about a single raster band.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
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...
double mean
The mean cell value for the band. NO_DATA values are excluded.
Continuous palette, QGIS addition, GRASS.
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. ...
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
void setRedContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
int removeParam(const QString &key)
Removes a generic parameter by key.
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
Returns true if the rectangle is empty.
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
QgsPointXY mBottomRightPoint
Coordinate (in output device coordinate system) of bottom right corner of the part of the raster that...
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
QgsRectangle extent() const override=0
Returns the extent of the layer.
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
bool loadDefaultStyle
Sets to true if the default layer style should be loaded.
QgsRasterInterface * at(int idx) const
QString providerType() const
[ data provider interface ] Which provider is being used for this Raster Layer?
double width() const
Returns the width of the rectangle.
QgsRasterShaderFunction * rasterShaderFunction()
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
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).
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
double cumulativeCutUpper() const
Returns the upper bound of cumulative cut method (between 0 and 1).
QString bandName(int bandNoInt) const
Returns the name of a band given its number.
Constantly updated extent of the canvas is used to compute statistics.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
Don't resolve layer paths or create data providers for layers.
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).
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
Raster renderer pipe for single band pseudocolor.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
void setRasterShaderFunction(QgsRasterShaderFunction *function)
A public method that allows the user to set their own shader function.
Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ].
static QString contrastEnhancementAlgorithmString(ContrastEnhancementAlgorithm algorithm)
Returns a string to serialize ContrastEnhancementAlgorithm.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
bool defaultContrastEnhancementSettings(QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, QgsRasterMinMaxOrigin::Limits &myLimits) const
Returns default contrast enhancement settings for that type of raster.
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
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...
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
Raster renderer pipe for single band gray.
static int typeSize(int dataType)
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Sixteen bit unsigned integer (quint16)
virtual void setLayerOrder(const QStringList &layers)
Reorder the list of layer names to be rendered by this provider (in order from bottom to top) ...
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
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...
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
void rendererChanged()
Signal emitted when renderer is changed.
double minimumScale() const
Returns the minimum map scale (i.e.
Contains information about the context in which a coordinate transform is executed.
void setAlphaBand(int band)
double maximumScale() const
Returns the maximum map scale (i.e.
bool mValid
Indicates if the layer is valid and can be drawn.
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
void setName(const QString &name)
Set the display name of the layer.
Q_DECL_DEPRECATED void setDataProvider(const QString &provider)
Set the data provider.
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]...
Base class for processing filters like renderers, reprojector, resampler etc.
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
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
static QString limitsString(Limits limits)
Returns a string to serialize Limits.
void setSubLayerVisibility(const QString &name, bool vis) override
Set the visibility of the given sublayer name.
virtual QString htmlMetadata()=0
Returns metadata in a format suitable for feeding directly into a subset of the GUI raster properties...
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
static ContrastEnhancementAlgorithm contrastEnhancementAlgorithmFromString(const QString &contrastEnhancementString)
Deserialize ContrastEnhancementAlgorithm.
void classifyColorRamp(int classes=0, int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
Classify color ramp shader.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void setMinMaxOrigin(const QgsRasterMinMaxOrigin &origin)
Sets origin of min/max values.
Limits
This enumerator describes the limits used to compute min/max values.
QgsCoordinateReferenceSystem mSrcCRS
Source coordinate system.
void setLimits(QgsRasterMinMaxOrigin::Limits limits)
Sets the limits.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
bool writeSymbology(QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
bool set(QgsRasterInterface *interface)
Insert a new known interface in default place or replace interface of the same role if it already exi...
Registry for raster renderer entries.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
virtual QgsRasterBandStats bandStatistics(int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0, QgsRasterBlockFeedback *feedback=nullptr)
Returns the band statistics.
QList< QPair< QString, QColor > > QgsLegendColorList
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.
void setContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used...
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...
Contains information about the context of a rendering operation.
Setting options for creating vector data providers.
QString name() const
Returns the display name of the layer.
void setClassificationMin(double min)
static QgsMapLayerLegend * defaultRasterLegend(QgsRasterLayer *rl)
Create new legend implementation for raster layer.
const QgsContrastEnhancement * redContrastEnhancement() const
const QgsContrastEnhancement * greenContrastEnhancement() const
void setZoomedInResampler(QgsRasterResampler *r)
Sets resampler for zoomed in scales. Takes ownership of the object.
QgsRasterResampleFilter * resampleFilter() const
Returns the raster's resample filter.
bool remove(int idx)
Remove and delete interface at given index if possible.
QList< QgsRasterRange > QgsRasterRangeList
QString mDataSource
Data source description string, varies by layer type.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
QgsCoordinateTransformContext mTransformContext
Coordinate transform context.
QString source() const
Returns the source for the layer.
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
Whole raster is used to compute statistics.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
virtual void reloadData()
Reloads the data from the source.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer...
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
int mHeight
Distance in map units from bottom edge to top edge for the part of the raster that is to be rendered...
Brightness/contrast filter pipe for rasters.
Bilinear Raster Resampler.
This class represents a coordinate reference system (CRS).
Color and saturation filter pipe for rasters.
void setBlueContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
Provider can read layer metadata from data store. Since QGIS 3.0. See QgsDataProvider::layerMetadata(...
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
void setZoomedOutResampler(QgsRasterResampler *r)
Sets resampler for zoomed out scales. Takes ownership of the object.
bool ignoreExtents() const
If the ignoreExtent flag is set, the layer will also render outside the bounding box reported by the ...
QStringList subLayers() const override
Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
double minimumValue
The minimum cell value in the raster band.
Renderer for multiband images with the color components.
bool isSpatial() const override
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
void dataChanged()
Data of layer changed.
void appendError(const QgsErrorMessage &error)
Add error message.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
Base class for utility classes that encapsulate information necessary for rendering of map layers...
Interpolates the color between two class breaks linearly.
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
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...
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
QgsMapLayerType
Types of layers that can be added to a map.
void refreshRendererIfNeeded(QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
Refresh renderer with new extent, if needed.
~QgsRasterLayer() override
This class provides details of the viewable area that a raster will be rendered into.
QDateTime dataTimestamp() const override
Current time stamp of data source.
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
Assigns the color of the higher class for every pixel between two class breaks.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
virtual void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
Gets symbology items if provided by renderer.
virtual QString generateBandName(int bandNumber) const
helper function to create zero padded band names
void reload() override
Synchronises with changes in the datasource.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
Class for storing the component parts of a RDBMS data source URI (e.g.
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
QgsLegendColorList legendSymbologyItems() const
Returns a list with classification items (Text and color)
virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
double stdDevFactor() const
Returns the factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ]...
virtual int xSize() const
Gets raster size.
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers...
Raster renderer pipe that applies colors to a raster.
QgsRasterRendererCreateFunc rendererCreateFunction
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type Byte.
void setError(const QgsError &error)
Sets error message.
QString authid() const
Returns the authority identifier for the CRS.
Eight bit unsigned integer (quint8)
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
Setting options for loading raster layers.
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
int band() const
Returns the band used by the renderer.
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
double height() const
Returns the height of the rectangle.
Q_DECL_DEPRECATED void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.
virtual int colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
QgsRectangle mDrawnExtent
Intersection of current map extent and layer extent.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
Base class for raster data providers.
QgsPointXY mTopLeftPoint
Coordinate (in output device coordinate system) of top left corner of the part of the raster that is ...
QgsRasterLayer()
Constructor. Provider is not set.