59 #include <QApplication> 62 #include <QDomElement> 67 #include <QFontMetrics> 74 #include <QMessageBox> 84 #define ERR(message) QGS_ERROR_MESSAGE(message,"Raster layer") 104 , QSTRING_NOT_SET( QStringLiteral(
"Not Set" ) )
105 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
113 const QString &baseName,
114 const QString &providerKey,
118 , QSTRING_NOT_SET( QStringLiteral(
"Not Set" ) )
119 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
120 , mProviderKey( providerKey )
130 bool defaultLoadedFlag =
false;
135 if ( !defaultLoadedFlag )
159 for (
int i = 1; i < mPipe.
size(); i++ )
179 QgsDebugMsg( QStringLiteral(
"Could not resolve isValidRasterFileName in gdal provider library" ) );
183 bool myIsValid = pValid( fileNameQString, retErrMsg );
198 QFileInfo fi( name );
204 t = fi.lastModified();
227 if ( !mDataProvider )
return 0;
243 return mDataProvider;
248 return mDataProvider;
291 drawer.draw( theQPainter, rasterViewPort, qgsMapToPixel );
293 QgsDebugMsgLevel( QStringLiteral(
"total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
298 QList< QPair< QString, QColor > > symbolList;
310 QString myMetadata = QStringLiteral(
"<html>\n<body>\n" );
313 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Information from provider" ) + QStringLiteral(
"</h1>\n<hr>\n" );
314 myMetadata += QLatin1String(
"<table class=\"list-view\">\n" );
317 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Name" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
322 if ( uriComponents.contains( QStringLiteral(
"path" ) ) )
324 path = uriComponents[QStringLiteral(
"path" )].toString();
325 if ( QFile::exists( path ) )
326 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" );
331 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
335 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
338 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"CRS" ) + QStringLiteral(
"</td><td>" );
341 myMetadata +=
crs().
authid() + QStringLiteral(
" - " );
343 if (
crs().isGeographic() )
344 myMetadata += tr(
"Geographic" );
346 myMetadata += tr(
"Projected" );
348 myMetadata += QLatin1String(
"</td></tr>\n" );
351 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Extent" ) + QStringLiteral(
"</td><td>" ) +
extent().
toString() + QStringLiteral(
"</td></tr>\n" );
354 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Unit" ) + QStringLiteral(
"</td><td>" ) +
QgsUnitTypes::toString(
crs().mapUnits() ) + QStringLiteral(
"</td></tr>\n" );
357 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Width" ) + QStringLiteral(
"</td><td>" );
359 myMetadata += QString::number(
width() );
361 myMetadata += tr(
"n/a" );
362 myMetadata += QLatin1String(
"</td></tr>\n" );
365 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Height" ) + QStringLiteral(
"</td><td>" );
367 myMetadata += QString::number(
height() );
369 myMetadata += tr(
"n/a" );
370 myMetadata += QLatin1String(
"</td></tr>\n" );
373 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Data type" ) + QStringLiteral(
"</td><td>" );
378 myMetadata += tr(
"Byte - Eight bit unsigned integer" );
381 myMetadata += tr(
"UInt16 - Sixteen bit unsigned integer " );
384 myMetadata += tr(
"Int16 - Sixteen bit signed integer " );
387 myMetadata += tr(
"UInt32 - Thirty two bit unsigned integer " );
390 myMetadata += tr(
"Int32 - Thirty two bit signed integer " );
393 myMetadata += tr(
"Float32 - Thirty two bit floating point " );
396 myMetadata += tr(
"Float64 - Sixty four bit floating point " );
399 myMetadata += tr(
"CInt16 - Complex Int16 " );
402 myMetadata += tr(
"CInt32 - Complex Int32 " );
405 myMetadata += tr(
"CFloat32 - Complex Float32 " );
408 myMetadata += tr(
"CFloat64 - Complex Float64 " );
411 myMetadata += tr(
"Could not determine raster data type." );
413 myMetadata += QLatin1String(
"</td></tr>\n" );
419 myMetadata += QLatin1String(
"</table>\n<br><br>" );
422 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Identification" ) + QStringLiteral(
"</h1>\n<hr>\n" );
424 myMetadata += QLatin1String(
"<br><br>\n" );
427 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Extent" ) + QStringLiteral(
"</h1>\n<hr>\n" );
429 myMetadata += QLatin1String(
"<br><br>\n" );
432 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Access" ) + QStringLiteral(
"</h1>\n<hr>\n" );
434 myMetadata += QLatin1String(
"<br><br>\n" );
437 myMetadata += QStringLiteral(
"</table>\n<br><br><h1>" ) + tr(
"Bands" ) + QStringLiteral(
"</h1>\n<hr>\n<table class=\"list-view\">\n" );
440 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Band count" ) + QStringLiteral(
"</td><td>" ) + QString::number(
bandCount() ) + QStringLiteral(
"</td></tr>\n" );
443 myMetadata += QLatin1String(
"</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
444 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" );
451 rowClass = QStringLiteral(
"class=\"odd-row\"" );
452 myMetadata += QLatin1String(
"<tr " ) + rowClass + QLatin1String(
"><td>" ) + QString::number( i ) + QLatin1String(
"</td><td>" ) +
bandName( i ) + QLatin1String(
"</td><td>" );
455 myMetadata += QString::number(
dataProvider()->sourceNoDataValue( i ) );
457 myMetadata += tr(
"n/a" );
458 myMetadata += QLatin1String(
"</td>" );
463 myMetadata += QLatin1String(
"<td>" ) + QString::number( myRasterBandStats.
minimumValue,
'f', 10 ) + QLatin1String(
"</td>" );
464 myMetadata += QLatin1String(
"<td>" ) + QString::number( myRasterBandStats.
maximumValue,
'f', 10 ) + QLatin1String(
"</td>" );
468 myMetadata += QLatin1String(
"<td>" ) + tr(
"n/a" ) + QLatin1String(
"</td><td>" ) + tr(
"n/a" ) + QLatin1String(
"</td>" );
471 myMetadata += QLatin1String(
"</tr>\n" );
475 myMetadata += QLatin1String(
"</table>\n<br><br>" );
478 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Contacts" ) + QStringLiteral(
"</h1>\n<hr>\n" );
480 myMetadata += QLatin1String(
"<br><br>\n" );
483 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"References" ) + QStringLiteral(
"</h1>\n<hr>\n" );
485 myMetadata += QLatin1String(
"<br><br>\n" );
488 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"History" ) + QStringLiteral(
"</h1>\n<hr>\n" );
490 myMetadata += QLatin1String(
"<br><br>\n" );
492 myMetadata += QStringLiteral(
"\n</body>\n</html>\n" );
507 QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->
colorTable( bandNumber );
508 if ( !myColorRampItemList.isEmpty() )
515 QPixmap myPalettePixmap( mySize, mySize );
516 QPainter myQPainter( &myPalettePixmap );
518 QImage myQImage = QImage( mySize, mySize, QImage::Format_RGB32 );
520 myPalettePixmap.fill();
522 double myStep = (
static_cast< double >( myColorRampItemList.size() ) - 1 ) /
static_cast< double >( mySize * mySize );
523 double myValue = 0.0;
524 for (
int myRow = 0; myRow < mySize; myRow++ )
526 QRgb *myLineBuffer =
reinterpret_cast< QRgb *
>( myQImage.scanLine( myRow ) );
527 for (
int myCol = 0; myCol < mySize; myCol++ )
529 myValue = myStep *
static_cast< double >( myCol + myRow * mySize );
531 myShader.
shade( myValue, &c1, &c2, &c3, &c4 );
532 myLineBuffer[ myCol ] = qRgba( c1, c2, c3, c4 );
536 myQPainter.drawImage( 0, 0, myQImage );
537 return myPalettePixmap;
539 QPixmap myNullPixmap;
545 QPixmap myNullPixmap;
579 void QgsRasterLayer::init()
597 mPipe.
remove( mDataProvider );
598 mDataProvider =
nullptr;
603 mProviderKey = provider;
613 if ( !mDataProvider )
616 appendError(
ERR( tr(
"Cannot instantiate the '%1' data provider" ).arg( mProviderKey ) ) );
620 mDataProvider->setParent(
this );
623 mPipe.
set( mDataProvider );
624 if ( !mDataProvider->
isValid() )
634 QgsDebugMsgLevel( QStringLiteral(
"Set Data provider QgsLayerMetadata identifier[%1]" ).arg(
metadata().identifier() ), 4 );
637 if ( provider == QLatin1String(
"gdal" ) )
669 if ( ( mDataProvider->
bandCount() > 1 ) )
717 QList<QgsColorRampShader::ColorRampItem> colorTable = mDataProvider->
colorTable( 1 );
740 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
754 mPipe.
set( brightnessFilter );
758 mPipe.
set( hueSaturationFilter );
762 mPipe.
set( resampleFilter );
766 mPipe.
set( projector );
803 void QgsRasterLayer::closeDataProvider()
806 mPipe.
remove( mDataProvider );
807 mDataProvider =
nullptr;
810 void QgsRasterLayer::computeMinMax(
int band,
815 double &min,
double &max )
818 min = std::numeric_limits<double>::quiet_NaN();
819 max = std::numeric_limits<double>::quiet_NaN();
837 QgsDebugMsgLevel( QStringLiteral(
"myLower = %1 myUpper = %2" ).arg( myLower ).arg( myUpper ), 4 );
838 mDataProvider->
cumulativeCut( band, myLower, myUpper, min, max, extent, sampleSize );
840 QgsDebugMsgLevel( QStringLiteral(
"band = %1 min = %2 max = %3" ).arg( band ).arg( min ).arg( max ), 4 );
851 generateLookupTableFlag,
859 bool generateLookupTableFlag,
863 if ( !rasterRenderer || !mDataProvider )
869 QList<QgsContrastEnhancement *> myEnhancements;
875 QString rendererType = rasterRenderer->
type();
876 if ( rendererType == QLatin1String(
"singlebandgray" ) )
879 if ( !myGrayRenderer )
883 myBands << myGrayRenderer->
grayBand();
884 myRasterRenderer = myGrayRenderer;
887 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
890 if ( !myMultiBandRenderer )
895 myRasterRenderer = myMultiBandRenderer;
898 else if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
901 if ( !myPseudoColorRenderer )
905 myBands << myPseudoColorRenderer->
band();
906 myRasterRenderer = myPseudoColorRenderer;
914 Q_FOREACH (
int myBand, myBands )
919 std::unique_ptr<QgsContrastEnhancement> myEnhancement(
new QgsContrastEnhancement( static_cast< Qgis::DataType >( myType ) ) );
920 myEnhancement->setContrastEnhancementAlgorithm(
algorithm, generateLookupTableFlag );
924 computeMinMax( myBand, myMinMaxOrigin, limits, extent, sampleSize, min, max );
926 if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
930 if ( myPseudoColorRenderer->
shader() )
933 if ( colorRampShader )
941 myEnhancement->setMinimumValue( min );
942 myEnhancement->setMaximumValue( max );
943 myEnhancements.append( myEnhancement.release() );
948 myEnhancements.append(
nullptr );
952 if ( rendererType == QLatin1String(
"singlebandgray" ) )
956 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
964 qDeleteAll( myEnhancements );
972 if ( myRasterRenderer )
990 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) ) )
994 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) ) )
1029 if ( !( mDataProvider &&
1030 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded != extent &&
1039 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>( rasterRenderer ) ) )
1043 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>( rasterRenderer ) ) )
1047 else if ( ( sbpcr = dynamic_cast<QgsSingleBandPseudoColorRenderer *>( rasterRenderer ) ) )
1049 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1052 computeMinMax( sbpcr->
band(),
1062 if ( colorRampShader )
1075 if ( colorRampShader )
1090 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1100 if ( singleBandRenderer )
1102 else if ( multiBandRenderer )
1131 QString defaultLimits;
1134 if ( dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) )
1136 key = QStringLiteral(
"singleBand" );
1142 else if ( dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) )
1146 key = QStringLiteral(
"multiBandSingleByte" );
1154 key = QStringLiteral(
"multiBandMultiByte" );
1162 if ( key.isEmpty() )
1164 QgsDebugMsg( QStringLiteral(
"No default contrast enhancement for this drawing style" ) );
1171 QString myAlgorithmString = mySettings.
value(
"/Raster/defaultContrastEnhancementAlgorithm/" + key, defaultAlg ).toString();
1176 QString myLimitsString = mySettings.
value(
"/Raster/defaultContrastEnhancementLimits/" + key, defaultLimits ).toString();
1198 if ( mDataProvider )
1200 QgsDebugMsgLevel( QStringLiteral(
"About to mDataProvider->setLayerOrder(layers)." ), 4 );
1209 if ( mDataProvider )
1211 QgsDebugMsgLevel( QStringLiteral(
"About to mDataProvider->setSubLayerVisibility(name, vis)." ), 4 );
1225 Q_UNUSED( errorMessage );
1237 QDomElement constraintElem = doc.createElement( QStringLiteral(
"sld:LayerFeatureConstraints" ) );
1238 node.appendChild( constraintElem );
1240 QDomElement featureTypeConstraintElem = doc.createElement( QStringLiteral(
"sld:FeatureTypeConstraint" ) );
1241 constraintElem.appendChild( featureTypeConstraintElem );
1243 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"sld:UserStyle" ) );
1244 node.appendChild( userStyleElem );
1246 if ( !
name().isEmpty() )
1248 QDomElement nameElem = doc.createElement( QStringLiteral(
"sld:Name" ) );
1249 nameElem.appendChild( doc.createTextNode(
name() ) );
1250 userStyleElem.appendChild( nameElem );
1253 if ( !
abstract().isEmpty() )
1255 QDomElement abstractElem = doc.createElement( QStringLiteral(
"sld:Abstract" ) );
1256 abstractElem.appendChild( doc.createTextNode(
abstract() ) );
1257 userStyleElem.appendChild( abstractElem );
1260 if ( !
title().isEmpty() )
1262 QDomElement titleElem = doc.createElement( QStringLiteral(
"sld:Title" ) );
1263 titleElem.appendChild( doc.createTextNode(
title() ) );
1264 userStyleElem.appendChild( titleElem );
1267 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"sld:FeatureTypeStyle" ) );
1268 userStyleElem.appendChild( featureTypeStyleElem );
1278 QDomElement typeStyleNameElem = doc.createElement( QStringLiteral(
"sld:Name" ) );
1279 featureTypeStyleElem.appendChild( typeStyleNameElem );
1282 QDomElement typeStyleRuleElem = doc.createElement( QStringLiteral(
"sld:Rule" ) );
1283 featureTypeStyleElem.appendChild( typeStyleRuleElem );
1291 QDomElement minScaleElem = doc.createElement( QStringLiteral(
"sld:MinScaleDenominator" ) );
1292 minScaleElem.appendChild( doc.createTextNode( QString::number(
maximumScale() ) ) );
1293 typeStyleRuleElem.appendChild( minScaleElem );
1296 QDomElement maxScaleElem = doc.createElement( QStringLiteral(
"sld:MaxScaleDenominator" ) );
1297 maxScaleElem.appendChild( doc.createTextNode( QString::number(
minimumScale() ) ) );
1298 typeStyleRuleElem.appendChild( maxScaleElem );
1302 mPipe.
renderer()->
toSld( doc, typeStyleRuleElem, localProps );
1307 QDomNodeList elements = typeStyleRuleElem.elementsByTagName( QStringLiteral(
"sld:RasterSymbolizer" ) );
1308 if ( elements.size() != 0 )
1311 QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();
1314 auto vendorOptionWriter = [&]( QString
name, QString value )
1316 QDomElement vendorOptionElem = doc.createElement( QStringLiteral(
"sld:VendorOption" ) );
1317 vendorOptionElem.setAttribute( QStringLiteral(
"name" ), name );
1318 vendorOptionElem.appendChild( doc.createTextNode( value ) );
1319 rasterSymbolizerElem.appendChild( vendorOptionElem );
1329 property = QStringLiteral(
"lightness" );
1332 property = QStringLiteral(
"luminosity" );
1335 property = QStringLiteral(
"average" );
1341 if ( !property.isEmpty() )
1342 vendorOptionWriter( QStringLiteral(
"grayScale" ), property );
1348 vendorOptionWriter( QStringLiteral(
"colorizeOn" ), QString::number(
hueSaturationFilter()->colorizeOn() ) );
1349 vendorOptionWriter( QStringLiteral(
"colorizeRed" ), QString::number(
hueSaturationFilter()->colorizeColor().red() ) );
1350 vendorOptionWriter( QStringLiteral(
"colorizeGreen" ), QString::number(
hueSaturationFilter()->colorizeColor().green() ) );
1351 vendorOptionWriter( QStringLiteral(
"colorizeBlue" ), QString::number(
hueSaturationFilter()->colorizeColor().blue() ) );
1353 vendorOptionWriter( QStringLiteral(
"colorizeStrength" ), QString::number(
hueSaturationFilter()->colorizeStrength() / 100.0 ) );
1354 vendorOptionWriter( QStringLiteral(
"saturation" ), QString::number(
hueSaturationFilter()->colorizeColor().saturationF() ) );
1363 double sF = ( s - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1364 vendorOptionWriter( QStringLiteral(
"saturation" ), QString::number( sF ) );
1373 double bF = ( b - ( -255.0 ) ) / ( 255.0 - ( -255.0 ) );
1374 vendorOptionWriter( QStringLiteral(
"brightness" ), QString::number( bF ) );
1382 double cF = ( c - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1383 vendorOptionWriter( QStringLiteral(
"contrast" ), QString::number( cF ) );
1397 if ( newProps.contains( QStringLiteral(
"contrast" ) ) )
1400 double contrast = newProps[ QStringLiteral(
"contrast" ) ].toDouble();
1401 double percentage = ( contrast - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1402 if ( percentage <= 0.5 )
1405 gamma = percentage / 0.5;
1412 QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral(
"sld:ContrastEnhancement" ) );
1413 rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1415 QDomElement gammaValueElem = doc.createElement( QStringLiteral(
"sld:GammaValue" ) );
1416 gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1417 globalContrastEnhancementElem.appendChild( gammaValueElem );
1434 mPipe.
set( renderer );
1457 QImage myQImage( size, format );
1459 myQImage.setColor( 0, bgColor.rgba() );
1464 double myMapUnitsPerPixel;
1468 if ( myExtent.
width() / myExtent.
height() >=
static_cast< double >( myQImage.width() ) / myQImage.height() )
1470 myMapUnitsPerPixel = myExtent.
width() / myQImage.width();
1471 myY = ( myQImage.height() - myExtent.
height() / myMapUnitsPerPixel ) / 2;
1475 myMapUnitsPerPixel = myExtent.
height() / myQImage.height();
1476 myX = ( myQImage.width() - myExtent.
width() / myMapUnitsPerPixel ) / 2;
1479 double myPixelWidth = myExtent.
width() / myMapUnitsPerPixel;
1480 double myPixelHeight = myExtent.
height() / myMapUnitsPerPixel;
1484 myRasterViewPort->
mWidth = myQImage.width();
1485 myRasterViewPort->
mHeight = myQImage.height();
1495 QPainter *myQPainter =
new QPainter( &myQImage );
1496 draw( myQPainter, myRasterViewPort, myMapToPixel );
1497 delete myRasterViewPort;
1498 delete myMapToPixel;
1518 Q_UNUSED( errorMessage );
1521 QDomElement rasterRendererElem;
1523 QDomElement layerElement = layer_node.toElement();
1530 QDomNode pipeNode = layer_node.firstChildElement( QStringLiteral(
"pipe" ) );
1531 if ( pipeNode.isNull() )
1533 pipeNode = layer_node;
1537 if ( !layer_node.firstChildElement( QStringLiteral(
"rasterproperties" ) ).isNull() )
1540 QDomNode layerNodeCopy = layer_node.cloneNode();
1541 QDomDocument doc = layerNodeCopy.ownerDocument();
1542 QDomElement rasterPropertiesElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterproperties" ) );
1545 rasterRendererElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1550 rasterRendererElem = pipeNode.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1553 if ( !rasterRendererElem.isNull() )
1555 QString rendererType = rasterRendererElem.attribute( QStringLiteral(
"type" ) );
1560 mPipe.
set( renderer );
1566 mPipe.
set( brightnessFilter );
1569 QDomElement brightnessElem = pipeNode.firstChildElement( QStringLiteral(
"brightnesscontrast" ) );
1570 if ( !brightnessElem.isNull() )
1572 brightnessFilter->
readXml( brightnessElem );
1577 mPipe.
set( hueSaturationFilter );
1580 QDomElement hueSaturationElem = pipeNode.firstChildElement( QStringLiteral(
"huesaturation" ) );
1581 if ( !hueSaturationElem.isNull() )
1583 hueSaturationFilter->
readXml( hueSaturationElem );
1588 mPipe.
set( resampleFilter );
1591 QDomElement resampleElem = pipeNode.firstChildElement( QStringLiteral(
"rasterresampler" ) );
1592 if ( !resampleElem.isNull() )
1594 resampleFilter->
readXml( resampleElem );
1598 QDomNode blendModeNode = layer_node.namedItem( QStringLiteral(
"blendMode" ) );
1599 if ( !blendModeNode.isNull() )
1601 QDomElement e = blendModeNode.toElement();
1612 return readSymbology( node, errorMessage, context, categories );
1621 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
1623 if ( pkeyNode.isNull() )
1625 mProviderKey = QStringLiteral(
"gdal" );
1629 QDomElement pkeyElt = pkeyNode.toElement();
1630 mProviderKey = pkeyElt.text();
1631 if ( mProviderKey.isEmpty() )
1633 mProviderKey = QStringLiteral(
"gdal" );
1643 QDomNode rpNode = layer_node.namedItem( QStringLiteral(
"rasterproperties" ) );
1645 if ( mProviderKey == QLatin1String(
"wms" ) )
1649 if ( !
mDataSource.contains( QLatin1String(
"crs=" ) ) && !
mDataSource.contains( QLatin1String(
"format=" ) ) )
1651 QgsDebugMsgLevel( QStringLiteral(
"Old WMS URI format detected -> adding params" ), 4 );
1654 QDomElement layerElement = rpNode.firstChildElement( QStringLiteral(
"wmsSublayer" ) );
1655 while ( !layerElement.isNull() )
1660 uri.
setParam( QStringLiteral(
"layers" ), layerElement.namedItem( QStringLiteral(
"name" ) ).toElement().text() );
1663 uri.
setParam( QStringLiteral(
"styles" ), layerElement.namedItem( QStringLiteral(
"style" ) ).toElement().text() );
1665 layerElement = layerElement.nextSiblingElement( QStringLiteral(
"wmsSublayer" ) );
1669 QDomNode formatNode = rpNode.namedItem( QStringLiteral(
"wmsFormat" ) );
1670 uri.
setParam( QStringLiteral(
"format" ), rpNode.namedItem( QStringLiteral(
"wmsFormat" ) ).toElement().text() );
1674 uri.
setParam( QStringLiteral(
"crs" ),
crs().authid() );
1682 if ( !
mValid )
return false;
1688 if ( res && mProviderKey == QLatin1String(
"wms" ) && ( !
renderer() ||
renderer()->
type() != QLatin1String(
"singlebandcolordata" ) ) )
1699 QDomNode stampNode = layer_node.namedItem(
"timestamp" );
1700 if ( !stampNode.isNull() )
1702 QDateTime stamp = QDateTime::fromString( stampNode.toElement().text(), Qt::ISODate );
1704 if ( stamp < mDataProvider->dataTimestamp() )
1706 QgsDebugMsg( QStringLiteral(
"data changed, reload provider" ) );
1707 closeDataProvider();
1710 if ( !
mValid )
return false;
1716 QDomElement noDataElement = layer_node.firstChildElement( QStringLiteral(
"noData" ) );
1718 QDomNodeList noDataBandList = noDataElement.elementsByTagName( QStringLiteral(
"noDataList" ) );
1720 for (
int i = 0; i < noDataBandList.size(); ++i )
1722 QDomElement bandElement = noDataBandList.at( i ).toElement();
1724 int bandNo = bandElement.attribute( QStringLiteral(
"bandNo" ) ).toInt( &ok );
1726 if ( ok && ( bandNo > 0 ) && ( bandNo <= mDataProvider->
bandCount() ) )
1728 mDataProvider->
setUseSourceNoDataValue( bandNo, bandElement.attribute( QStringLiteral(
"useSrcNoData" ) ).toInt() );
1731 QDomNodeList rangeList = bandElement.elementsByTagName( QStringLiteral(
"noDataRange" ) );
1733 myNoDataRangeList.reserve( rangeList.size() );
1734 for (
int j = 0; j < rangeList.size(); ++j )
1736 QDomElement rangeElement = rangeList.at( j ).toElement();
1737 QgsRasterRange myNoDataRange( rangeElement.attribute( QStringLiteral(
"min" ) ).toDouble(),
1738 rangeElement.attribute( QStringLiteral(
"max" ) ).toDouble() );
1739 QgsDebugMsgLevel( QStringLiteral(
"min = %1 %2" ).arg( rangeElement.attribute(
"min" ) ).arg( myNoDataRange.min() ), 4 );
1740 myNoDataRangeList << myNoDataRange;
1760 Q_UNUSED( errorMessage );
1763 QDomElement layerElement = layer_node.toElement();
1768 QDomElement pipeElement = document.createElement( QStringLiteral(
"pipe" ) );
1770 for (
int i = 1; i < mPipe.
size(); i++ )
1773 if ( !interface )
continue;
1774 interface->writeXml( document, pipeElement );
1777 layer_node.appendChild( pipeElement );
1780 QDomElement blendModeElement = document.createElement( QStringLiteral(
"blendMode" ) );
1782 blendModeElement.appendChild( blendModeText );
1783 layer_node.appendChild( blendModeElement );
1791 return writeSymbology( node, doc, errorMessage, context, categories );
1799 QDomDocument &document,
1804 QDomElement mapLayerNode = layer_node.toElement();
1806 if ( mapLayerNode.isNull() ||
"maplayer" != mapLayerNode.nodeName() )
1812 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"raster" ) );
1816 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
1817 QDomText providerText = document.createTextNode( mProviderKey );
1818 provider.appendChild( providerText );
1819 layer_node.appendChild( provider );
1822 QDomElement noData = document.createElement( QStringLiteral(
"noData" ) );
1824 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
1826 QDomElement noDataRangeList = document.createElement( QStringLiteral(
"noDataList" ) );
1827 noDataRangeList.setAttribute( QStringLiteral(
"bandNo" ), bandNo );
1828 noDataRangeList.setAttribute( QStringLiteral(
"useSrcNoData" ), mDataProvider->
useSourceNoDataValue( bandNo ) );
1832 QDomElement noDataRange = document.createElement( QStringLiteral(
"noDataRange" ) );
1836 noDataRangeList.appendChild( noDataRange );
1839 noData.appendChild( noDataRangeList );
1842 if ( noData.hasChildNodes() )
1844 layer_node.appendChild( noData );
1851 return writeSymbology( layer_node, document, errorMsg, context );
1855 static bool _parseGpkgColons(
const QString &src, QString &filename, QString &tablename )
1860 QStringList lst = src.split(
':' );
1861 if ( lst.count() != 3 && lst.count() != 4 )
1864 tablename = lst.last();
1865 if ( lst.count() == 3 )
1870 else if ( lst.count() == 4 && lst[1].count() == 1 && ( lst[2][0] ==
'/' || lst[2][0] ==
'\\' ) )
1873 filename = lst[1] +
":" + lst[2];
1882 QString src( source );
1883 bool handled =
false;
1888 if ( src.startsWith( QLatin1String(
"NETCDF:" ) ) )
1892 QRegExp r(
"NETCDF:(.+):([^:]+)" );
1893 if ( r.exactMatch( src ) )
1895 QString filename = r.cap( 1 );
1896 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
1897 filename = filename.mid( 1, filename.length() - 2 );
1902 else if ( src.startsWith( QLatin1String(
"GPKG:" ) ) )
1905 QString filename, tablename;
1906 if ( _parseGpkgColons( src, filename, tablename ) )
1909 src = QStringLiteral(
"GPKG:%1:%2" ).arg( filename, tablename );
1913 else if ( src.startsWith( QLatin1String(
"HDF4_SDS:" ) ) )
1917 QRegExp r(
"HDF4_SDS:([^:]+):(.+):([^:]+)" );
1918 if ( r.exactMatch( src ) )
1920 QString filename = r.cap( 2 );
1921 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
1922 filename = filename.mid( 1, filename.length() - 2 );
1923 src =
"HDF4_SDS:" + r.cap( 1 ) +
":\"" + context.
pathResolver().
writePath( filename ) +
"\":" + r.cap( 3 );
1927 else if ( src.startsWith( QLatin1String(
"HDF5:" ) ) )
1931 QRegExp r(
"HDF5:(.+):([^:]+)" );
1932 if ( r.exactMatch( src ) )
1934 QString filename = r.cap( 1 );
1935 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
1936 filename = filename.mid( 1, filename.length() - 2 );
1941 else if ( src.contains( QRegExp(
"^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
1945 QRegExp r(
"([^:]+):([^:]+):(.+)" );
1946 if ( r.exactMatch( src ) )
1962 QString src( source );
1964 if ( provider == QLatin1String(
"wms" ) )
1978 if ( !src.contains( QLatin1String(
"type=" ) ) &&
1979 !src.contains( QLatin1String(
"crs=" ) ) && !src.contains( QLatin1String(
"format=" ) ) )
1981 QgsDebugMsg( QStringLiteral(
"Old WMS URI format detected -> converting to new format" ) );
1983 if ( !src.startsWith( QLatin1String(
"http:" ) ) )
1985 QStringList parts = src.split(
',' );
1986 QStringListIterator iter( parts );
1987 while ( iter.hasNext() )
1989 QString item = iter.next();
1990 if ( item.startsWith( QLatin1String(
"username=" ) ) )
1992 uri.
setParam( QStringLiteral(
"username" ), item.mid( 9 ) );
1994 else if ( item.startsWith( QLatin1String(
"password=" ) ) )
1996 uri.
setParam( QStringLiteral(
"password" ), item.mid( 9 ) );
1998 else if ( item.startsWith( QLatin1String(
"tiled=" ) ) )
2004 QStringList params = item.mid( 6 ).split(
';' );
2006 if ( params.size() == 2 )
2008 uri.
setParam( QStringLiteral(
"maxWidth" ), params.takeFirst() );
2009 uri.
setParam( QStringLiteral(
"maxHeight" ), params.takeFirst() );
2011 else if ( params.size() > 2 )
2015 uri.
setParam( QStringLiteral(
"tileMatrixSet" ), QString() );
2018 else if ( item.startsWith( QLatin1String(
"featureCount=" ) ) )
2020 uri.
setParam( QStringLiteral(
"featureCount" ), item.mid( 13 ) );
2022 else if ( item.startsWith( QLatin1String(
"url=" ) ) )
2024 uri.
setParam( QStringLiteral(
"url" ), item.mid( 4 ) );
2026 else if ( item.startsWith( QLatin1String(
"ignoreUrl=" ) ) )
2028 uri.
setParam( QStringLiteral(
"ignoreUrl" ), item.mid( 10 ).split(
';' ) );
2034 uri.
setParam( QStringLiteral(
"url" ), src );
2044 bool handled =
false;
2046 if ( provider == QLatin1String(
"gdal" ) )
2048 if ( src.startsWith( QLatin1String(
"NETCDF:" ) ) )
2052 QRegExp r(
"NETCDF:(.+):([^:]+)" );
2053 if ( r.exactMatch( src ) )
2055 QString filename = r.cap( 1 );
2056 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2057 filename = filename.mid( 1, filename.length() - 2 );
2062 else if ( src.startsWith( QLatin1String(
"GPKG:" ) ) )
2065 QString filename, tablename;
2066 if ( _parseGpkgColons( src, filename, tablename ) )
2069 src = QStringLiteral(
"GPKG:%1:%2" ).arg( filename, tablename );
2073 else if ( src.startsWith( QLatin1String(
"HDF4_SDS:" ) ) )
2077 QRegExp r(
"HDF4_SDS:([^:]+):(.+):([^:]+)" );
2078 if ( r.exactMatch( src ) )
2080 QString filename = r.cap( 2 );
2081 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2082 filename = filename.mid( 1, filename.length() - 2 );
2083 src =
"HDF4_SDS:" + r.cap( 1 ) +
":\"" + context.
pathResolver().
readPath( filename ) +
"\":" + r.cap( 3 );
2087 else if ( src.startsWith( QLatin1String(
"HDF5:" ) ) )
2091 QRegExp r(
"HDF5:(.+):([^:]+)" );
2092 if ( r.exactMatch( src ) )
2094 QString filename = r.cap( 1 );
2095 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2096 filename = filename.mid( 1, filename.length() - 2 );
2101 else if ( src.contains( QRegExp(
"^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2105 QRegExp r(
"([^:]+):([^:]+):(.+)" );
2106 if ( r.exactMatch( src ) )
2123 if ( !mDataProvider )
return 0;
2124 return mDataProvider->
xSize();
2129 if ( !mDataProvider )
return 0;
2130 return mDataProvider->
ySize();
2138 bool QgsRasterLayer::update()
2145 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)
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.
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...
bool defaultContrastEnhancementSettings(QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, QgsRasterMinMaxOrigin::Limits &myLimits) const
Returns default contrast enhancement settings for that type of raster.
A rectangle specified with double values.
Base class for all map layer types.
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis.
Thirty two bit signed integer (qint32)
Interface for all raster shaders.
void statusChanged(const QString &) const
Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &list)
Sets a custom colormap.
QgsRasterLayer * clone() const override
Returns a new instance equivalent to this one.
bool isEmpty() const
Returns true if the rectangle is empty.
QStringList subLayers() const override
Returns the sublayers of this layer.
QgsMapLayer::LayerType type() const
Returns the type of the layer.
static QString printValue(double value)
Print double value with all necessary significant digits.
void refreshContrastEnhancement(const QgsRectangle &extent)
Refresh contrast enhancement with new extent.
bool isValid() const
Returns the status of the layer.
virtual void setUseSourceNoDataValue(int bandNo, bool use)
Sets the source nodata value usage.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
const QgsContrastEnhancement * greenContrastEnhancement() const
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
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.
QString name() const
Returns the display name of the layer.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
double stdDevFactor() const
Returns the factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ]...
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
This class is a composition of two QSettings instances:
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.
QgsRasterInterface * at(int idx) const
void setRenderer(QgsRasterRenderer *renderer)
Sets raster renderer. Takes ownership of the renderer object.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
double maximumScale() const
Returns the maximum map scale (i.e.
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.
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.
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)
const QgsContrastEnhancement * contrastEnhancement() const
void showStatusMessage(const QString &message)
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
virtual int colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
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.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
DataType
Raster data types.
double maximumValue
The maximum cell value in the raster band.
static Limits limitsFromString(const QString &limits)
Deserialize Limits.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
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...
QgsRasterInterface * last() const
virtual QgsRasterInterface * input() const
Current input.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
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...
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
static QDateTime lastModified(const QString &name)
Returns time stamp for given file name.
QString source() const
Returns the source for the layer.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Raster values range container.
const QgsContrastEnhancement * redContrastEnhancement() const
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Returns the components (e.g.
Resample filter pipe for rasters.
Abstract base class for spatial data provider implementations.
static const double SAMPLE_SIZE
Default sample size (number of pixels) for estimated statistics/histogram calculation.
Thirty two bit floating point (float)
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.
virtual int ySize() const
void setGreenContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
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)
void setExtent(QgsRasterMinMaxOrigin::Extent extent)
Sets the extent.
QgsCoordinateReferenceSystem mDestCRS
Target coordinate system.
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
Creates a new instance of a provider.
void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.
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) ...
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)
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.
QgsRasterDataProvider * dataProvider() override
Returns the layer's data provider.
This class describes the origin of min/max values.
QgsRasterMinMaxOrigin::Extent extent() const
Returns the raster extent.
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.
int height() const
Returns the height of the (unclipped) raster.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Continuous palette, QGIS addition, GRASS.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
void setRedContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
QgsRasterRenderer * renderer() const
int bandCount() const
Returns the number of bands in this layer.
#define QgsDebugMsgLevel(str, level)
virtual QgsRectangle extent() const
Returns the extent of the layer.
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...
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.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
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.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
int band() const
Returns the band used by the renderer.
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).
QgsRasterMinMaxOrigin::Limits limits() const
Returns the raster limits.
Constantly updated extent of the canvas is used to compute statistics.
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)
set complete encoded uri (generic mode)
Raster renderer pipe for single band pseudocolor.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
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.
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...
double min() const
Returns the minimum value for the range.
Raster renderer pipe for single band gray.
QgsRasterResampleFilter * resampleFilter() const
Sets raster resample filter. Takes ownership of the resample filter object.
static int typeSize(int dataType)
void setParam(const QString &key, const QString &value)
Set generic param (generic mode)
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) ...
QgsRasterProjector * projector() const
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...
void rendererChanged()
Signal emitted when renderer is changed.
void setAlphaBand(int band)
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.
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. ...
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
double minimumScale() const
Returns the minimum map scale (i.e.
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.
QByteArray encodedUri() const
Returns complete encoded uri (generic mode)
virtual QString htmlMetadata()=0
Returns metadata in a format suitable for feeding directly into a subset of the GUI raster properties...
const QgsContrastEnhancement * blueContrastEnhancement() const
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.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
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.
virtual const QgsLayerMetadata & metadata() const
Returns a reference to the layer's metadata store.
QgsCoordinateReferenceSystem mSrcCRS
Source coordinate system.
void setLimits(QgsRasterMinMaxOrigin::Limits limits)
Sets the limits.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
virtual QString generateBandName(int bandNumber) const
helper function to create zero padded band names
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.
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.
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.
virtual void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
Gets symbology items if provided by renderer.
Setting options for creating vector data providers.
void setClassificationMin(double min)
static QgsMapLayerLegend * defaultRasterLegend(QgsRasterLayer *rl)
Create new legend implementation for raster layer.
bool remove(int idx)
Remove and delete interface at given index if possible.
QList< QgsRasterRange > QgsRasterRangeList
virtual int xSize() const
Gets raster size.
QString mDataSource
Data source description string, varies by layer type.
virtual QgsError error() const
Gets current status error.
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.
virtual QString type() const
virtual void reloadData()
Reloads the data from the source.
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
double cumulativeCutLower() const
Returns the lower bound of cumulative cut method (between 0 and 1).
double cumulativeCutUpper() const
Returns the upper bound of cumulative cut method (between 0 and 1).
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.
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(...
QString authid() const
Returns the authority identifier for the CRS.
bool isvalidrasterfilename_t(QString const &fileNameQString, QString &retErrMsg)
QStringList subLayers() const override
Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS.
QString bandName(int bandNoInt) const
Returns the name of a band given its number.
QgsHueSaturationFilter * hueSaturationFilter() const
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
double minimumValue
The minimum cell value in the raster band.
Renderer for multiband images with the color components.
void dataChanged()
Data of layer changed.
bool isSpatial() const override
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
void appendError(const QgsErrorMessage &error)
Add error message.
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...
double max() const
Returns the maximum value for the 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.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
void refreshRendererIfNeeded(QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
Refresh renderer with new extent, if needed.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
~QgsRasterLayer() override
QString providerType() const
[ data provider interface ] Which provider is being used for this Raster Layer?
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.
Assigns the color of the higher class for every pixel between two class breaks.
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 PostgreSQL/RDBMS datasource URI.
double width() const
Returns the width of the rectangle.
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
QgsLegendColorList legendSymbologyItems() const
Returns a list with classification items (Text and color)
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
QgsRasterRenderer * renderer() const
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers...
virtual QgsError error() const
Gets current status error.
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.
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.
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
double height() const
Returns the height of the rectangle.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QgsBrightnessContrastFilter * brightnessFilter() const
QgsRectangle mDrawnExtent
Intersection of current map extent and layer extent.
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 ...
int width() const
Returns the width of the (unclipped) raster.
QgsRasterLayer()
Constructor. Provider is not set.