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" ) )
144 for (
int i = 1; i < mPipe.
size(); i++ )
164 QgsDebugMsg( QStringLiteral(
"Could not resolve isValidRasterFileName in gdal provider library" ) );
168 bool myIsValid = pValid( fileNameQString, retErrMsg );
183 QFileInfo fi( name );
189 t = fi.lastModified();
212 if ( !mDataProvider )
return 0;
228 return mDataProvider;
233 return mDataProvider;
276 drawer.draw( theQPainter, rasterViewPort, qgsMapToPixel );
278 QgsDebugMsgLevel( QStringLiteral(
"total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
283 QList< QPair< QString, QColor > > symbolList;
295 QString myMetadata = QStringLiteral(
"<html>\n<body>\n" );
298 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Information from provider" ) + QStringLiteral(
"</h1>\n<hr>\n" );
299 myMetadata += QLatin1String(
"<table class=\"list-view\">\n" );
302 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Name" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
307 if ( uriComponents.contains( QStringLiteral(
"path" ) ) )
309 path = uriComponents[QStringLiteral(
"path" )].toString();
310 if ( QFile::exists( path ) )
311 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" );
313 if ( uriComponents.contains( QStringLiteral(
"url" ) ) )
315 const QString url = uriComponents[QStringLiteral(
"url" )].toString();
316 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" );
321 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
325 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
328 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"CRS" ) + QStringLiteral(
"</td><td>" );
331 myMetadata +=
crs().
authid() + QStringLiteral(
" - " );
333 if (
crs().isGeographic() )
334 myMetadata += tr(
"Geographic" );
336 myMetadata += tr(
"Projected" );
338 myMetadata += QLatin1String(
"</td></tr>\n" );
341 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Extent" ) + QStringLiteral(
"</td><td>" ) +
extent().
toString() + QStringLiteral(
"</td></tr>\n" );
344 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Unit" ) + QStringLiteral(
"</td><td>" ) +
QgsUnitTypes::toString(
crs().mapUnits() ) + QStringLiteral(
"</td></tr>\n" );
347 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Width" ) + QStringLiteral(
"</td><td>" );
349 myMetadata += QString::number(
width() );
351 myMetadata += tr(
"n/a" );
352 myMetadata += QLatin1String(
"</td></tr>\n" );
355 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Height" ) + QStringLiteral(
"</td><td>" );
357 myMetadata += QString::number(
height() );
359 myMetadata += tr(
"n/a" );
360 myMetadata += QLatin1String(
"</td></tr>\n" );
363 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Data type" ) + QStringLiteral(
"</td><td>" );
368 myMetadata += tr(
"Byte - Eight bit unsigned integer" );
371 myMetadata += tr(
"UInt16 - Sixteen bit unsigned integer " );
374 myMetadata += tr(
"Int16 - Sixteen bit signed integer " );
377 myMetadata += tr(
"UInt32 - Thirty two bit unsigned integer " );
380 myMetadata += tr(
"Int32 - Thirty two bit signed integer " );
383 myMetadata += tr(
"Float32 - Thirty two bit floating point " );
386 myMetadata += tr(
"Float64 - Sixty four bit floating point " );
389 myMetadata += tr(
"CInt16 - Complex Int16 " );
392 myMetadata += tr(
"CInt32 - Complex Int32 " );
395 myMetadata += tr(
"CFloat32 - Complex Float32 " );
398 myMetadata += tr(
"CFloat64 - Complex Float64 " );
401 myMetadata += tr(
"Could not determine raster data type." );
403 myMetadata += QLatin1String(
"</td></tr>\n" );
409 myMetadata += QLatin1String(
"</table>\n<br><br>" );
412 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Identification" ) + QStringLiteral(
"</h1>\n<hr>\n" );
414 myMetadata += QLatin1String(
"<br><br>\n" );
417 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Extent" ) + QStringLiteral(
"</h1>\n<hr>\n" );
419 myMetadata += QLatin1String(
"<br><br>\n" );
422 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Access" ) + QStringLiteral(
"</h1>\n<hr>\n" );
424 myMetadata += QLatin1String(
"<br><br>\n" );
427 myMetadata += QStringLiteral(
"</table>\n<br><br><h1>" ) + tr(
"Bands" ) + QStringLiteral(
"</h1>\n<hr>\n<table class=\"list-view\">\n" );
430 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Band count" ) + QStringLiteral(
"</td><td>" ) + QString::number(
bandCount() ) + QStringLiteral(
"</td></tr>\n" );
433 myMetadata += QLatin1String(
"</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
434 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" );
441 rowClass = QStringLiteral(
"class=\"odd-row\"" );
442 myMetadata += QLatin1String(
"<tr " ) + rowClass + QLatin1String(
"><td>" ) + QString::number( i ) + QLatin1String(
"</td><td>" ) +
bandName( i ) + QLatin1String(
"</td><td>" );
445 myMetadata += QString::number(
dataProvider()->sourceNoDataValue( i ) );
447 myMetadata += tr(
"n/a" );
448 myMetadata += QLatin1String(
"</td>" );
453 myMetadata += QLatin1String(
"<td>" ) + QString::number( myRasterBandStats.
minimumValue,
'f', 10 ) + QLatin1String(
"</td>" );
454 myMetadata += QLatin1String(
"<td>" ) + QString::number( myRasterBandStats.
maximumValue,
'f', 10 ) + QLatin1String(
"</td>" );
458 myMetadata += QLatin1String(
"<td>" ) + tr(
"n/a" ) + QLatin1String(
"</td><td>" ) + tr(
"n/a" ) + QLatin1String(
"</td>" );
461 myMetadata += QLatin1String(
"</tr>\n" );
465 myMetadata += QLatin1String(
"</table>\n<br><br>" );
468 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Contacts" ) + QStringLiteral(
"</h1>\n<hr>\n" );
470 myMetadata += QLatin1String(
"<br><br>\n" );
473 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"References" ) + QStringLiteral(
"</h1>\n<hr>\n" );
475 myMetadata += QLatin1String(
"<br><br>\n" );
478 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"History" ) + QStringLiteral(
"</h1>\n<hr>\n" );
480 myMetadata += QLatin1String(
"<br><br>\n" );
482 myMetadata += QStringLiteral(
"\n</body>\n</html>\n" );
497 QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->
colorTable( bandNumber );
498 if ( !myColorRampItemList.isEmpty() )
505 QPixmap myPalettePixmap( mySize, mySize );
506 QPainter myQPainter( &myPalettePixmap );
508 QImage myQImage = QImage( mySize, mySize, QImage::Format_RGB32 );
510 myPalettePixmap.fill();
512 double myStep = (
static_cast< double >( myColorRampItemList.size() ) - 1 ) /
static_cast< double >( mySize * mySize );
513 double myValue = 0.0;
514 for (
int myRow = 0; myRow < mySize; myRow++ )
516 QRgb *myLineBuffer =
reinterpret_cast< QRgb *
>( myQImage.scanLine( myRow ) );
517 for (
int myCol = 0; myCol < mySize; myCol++ )
519 myValue = myStep *
static_cast< double >( myCol + myRow * mySize );
521 myShader.
shade( myValue, &c1, &c2, &c3, &c4 );
522 myLineBuffer[ myCol ] = qRgba( c1, c2, c3, c4 );
526 myQPainter.drawImage( 0, 0, myQImage );
527 return myPalettePixmap;
529 QPixmap myNullPixmap;
535 QPixmap myNullPixmap;
569 void QgsRasterLayer::init()
587 mPipe.
remove( mDataProvider );
588 mDataProvider =
nullptr;
603 if ( !mDataProvider )
610 mDataProvider->setParent(
this );
613 mPipe.
set( mDataProvider );
614 if ( !mDataProvider->
isValid() )
624 QgsDebugMsgLevel( QStringLiteral(
"Set Data provider QgsLayerMetadata identifier[%1]" ).arg(
metadata().identifier() ), 4 );
627 if ( provider == QLatin1String(
"gdal" ) )
659 if ( ( mDataProvider->
bandCount() > 1 ) )
707 QList<QgsColorRampShader::ColorRampItem> colorTable = mDataProvider->
colorTable( 1 );
730 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
744 mPipe.
set( brightnessFilter );
748 mPipe.
set( hueSaturationFilter );
752 mPipe.
set( resampleFilter );
756 mPipe.
set( projector );
798 QDomImplementation domImplementation;
799 QDomDocumentType documentType;
802 QDomElement rootNode;
805 if ( wasValid && ! loadDefaultStyleFlag )
807 documentType = domImplementation.createDocumentType(
808 QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
809 doc = QDomDocument( documentType );
810 rootNode = doc.createElement( QStringLiteral(
"qgis" ) );
812 doc.appendChild( rootNode );
816 QgsDebugMsg( QStringLiteral(
"Could not store symbology for layer %1: %2" )
827 for (
int i = mPipe.
size() - 1; i >= 0; --i )
840 bool defaultLoadedFlag =
false;
841 if ( loadDefaultStyleFlag )
845 else if ( wasValid && errorMsg.isEmpty() )
850 QgsDebugMsg( QStringLiteral(
"Could not restore symbology for layer %1: %2" )
857 if ( !defaultLoadedFlag )
867 void QgsRasterLayer::closeDataProvider()
870 mPipe.
remove( mDataProvider );
871 mDataProvider =
nullptr;
874 void QgsRasterLayer::computeMinMax(
int band,
879 double &min,
double &max )
882 min = std::numeric_limits<double>::quiet_NaN();
883 max = std::numeric_limits<double>::quiet_NaN();
901 QgsDebugMsgLevel( QStringLiteral(
"myLower = %1 myUpper = %2" ).arg( myLower ).arg( myUpper ), 4 );
902 mDataProvider->
cumulativeCut( band, myLower, myUpper, min, max, extent, sampleSize );
904 QgsDebugMsgLevel( QStringLiteral(
"band = %1 min = %2 max = %3" ).arg( band ).arg( min ).arg( max ), 4 );
915 generateLookupTableFlag,
923 bool generateLookupTableFlag,
927 if ( !rasterRenderer || !mDataProvider )
933 QList<QgsContrastEnhancement *> myEnhancements;
939 QString rendererType = rasterRenderer->
type();
940 if ( rendererType == QLatin1String(
"singlebandgray" ) )
943 if ( !myGrayRenderer )
947 myBands << myGrayRenderer->
grayBand();
948 myRasterRenderer = myGrayRenderer;
951 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
954 if ( !myMultiBandRenderer )
959 myRasterRenderer = myMultiBandRenderer;
962 else if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
965 if ( !myPseudoColorRenderer )
969 myBands << myPseudoColorRenderer->
band();
970 myRasterRenderer = myPseudoColorRenderer;
978 Q_FOREACH (
int myBand, myBands )
983 std::unique_ptr<QgsContrastEnhancement> myEnhancement(
new QgsContrastEnhancement( static_cast< Qgis::DataType >( myType ) ) );
984 myEnhancement->setContrastEnhancementAlgorithm(
algorithm, generateLookupTableFlag );
988 computeMinMax( myBand, myMinMaxOrigin, limits, extent, sampleSize, min, max );
990 if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
994 if ( myPseudoColorRenderer->
shader() )
997 if ( colorRampShader )
1005 myEnhancement->setMinimumValue( min );
1006 myEnhancement->setMaximumValue( max );
1007 myEnhancements.append( myEnhancement.release() );
1012 myEnhancements.append(
nullptr );
1016 if ( rendererType == QLatin1String(
"singlebandgray" ) )
1020 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
1028 qDeleteAll( myEnhancements );
1036 if ( myRasterRenderer )
1041 if ( rasterRenderer ==
renderer() )
1054 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) ) )
1058 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) ) )
1093 if ( !( mDataProvider &&
1094 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded != extent &&
1103 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>( rasterRenderer ) ) )
1107 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>( rasterRenderer ) ) )
1111 else if ( ( sbpcr = dynamic_cast<QgsSingleBandPseudoColorRenderer *>( rasterRenderer ) ) )
1113 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1116 computeMinMax( sbpcr->
band(),
1126 if ( colorRampShader )
1139 if ( colorRampShader )
1154 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1164 if ( singleBandRenderer )
1166 else if ( multiBandRenderer )
1195 QString defaultLimits;
1198 if ( dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) )
1200 key = QStringLiteral(
"singleBand" );
1206 else if ( dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) )
1210 key = QStringLiteral(
"multiBandSingleByte" );
1218 key = QStringLiteral(
"multiBandMultiByte" );
1226 if ( key.isEmpty() )
1228 QgsDebugMsg( QStringLiteral(
"No default contrast enhancement for this drawing style" ) );
1235 QString myAlgorithmString = mySettings.
value(
"/Raster/defaultContrastEnhancementAlgorithm/" + key, defaultAlg ).toString();
1240 QString myLimitsString = mySettings.
value(
"/Raster/defaultContrastEnhancementLimits/" + key, defaultLimits ).toString();
1262 if ( mDataProvider )
1264 QgsDebugMsgLevel( QStringLiteral(
"About to mDataProvider->setLayerOrder(layers)." ), 4 );
1273 if ( mDataProvider )
1275 QgsDebugMsgLevel( QStringLiteral(
"About to mDataProvider->setSubLayerVisibility(name, vis)." ), 4 );
1289 Q_UNUSED( errorMessage );
1301 QDomElement constraintElem = doc.createElement( QStringLiteral(
"sld:LayerFeatureConstraints" ) );
1302 node.appendChild( constraintElem );
1304 QDomElement featureTypeConstraintElem = doc.createElement( QStringLiteral(
"sld:FeatureTypeConstraint" ) );
1305 constraintElem.appendChild( featureTypeConstraintElem );
1307 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"sld:UserStyle" ) );
1308 node.appendChild( userStyleElem );
1310 if ( !
name().isEmpty() )
1312 QDomElement nameElem = doc.createElement( QStringLiteral(
"sld:Name" ) );
1313 nameElem.appendChild( doc.createTextNode(
name() ) );
1314 userStyleElem.appendChild( nameElem );
1317 if ( !
abstract().isEmpty() )
1319 QDomElement abstractElem = doc.createElement( QStringLiteral(
"sld:Abstract" ) );
1320 abstractElem.appendChild( doc.createTextNode(
abstract() ) );
1321 userStyleElem.appendChild( abstractElem );
1324 if ( !
title().isEmpty() )
1326 QDomElement titleElem = doc.createElement( QStringLiteral(
"sld:Title" ) );
1327 titleElem.appendChild( doc.createTextNode(
title() ) );
1328 userStyleElem.appendChild( titleElem );
1331 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"sld:FeatureTypeStyle" ) );
1332 userStyleElem.appendChild( featureTypeStyleElem );
1342 QDomElement typeStyleNameElem = doc.createElement( QStringLiteral(
"sld:Name" ) );
1343 featureTypeStyleElem.appendChild( typeStyleNameElem );
1346 QDomElement typeStyleRuleElem = doc.createElement( QStringLiteral(
"sld:Rule" ) );
1347 featureTypeStyleElem.appendChild( typeStyleRuleElem );
1355 QDomElement minScaleElem = doc.createElement( QStringLiteral(
"sld:MinScaleDenominator" ) );
1356 minScaleElem.appendChild( doc.createTextNode( QString::number(
maximumScale() ) ) );
1357 typeStyleRuleElem.appendChild( minScaleElem );
1360 QDomElement maxScaleElem = doc.createElement( QStringLiteral(
"sld:MaxScaleDenominator" ) );
1361 maxScaleElem.appendChild( doc.createTextNode( QString::number(
minimumScale() ) ) );
1362 typeStyleRuleElem.appendChild( maxScaleElem );
1366 mPipe.
renderer()->
toSld( doc, typeStyleRuleElem, localProps );
1371 QDomNodeList elements = typeStyleRuleElem.elementsByTagName( QStringLiteral(
"sld:RasterSymbolizer" ) );
1372 if ( elements.size() != 0 )
1375 QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();
1378 auto vendorOptionWriter = [&]( QString
name, QString value )
1380 QDomElement vendorOptionElem = doc.createElement( QStringLiteral(
"sld:VendorOption" ) );
1381 vendorOptionElem.setAttribute( QStringLiteral(
"name" ), name );
1382 vendorOptionElem.appendChild( doc.createTextNode( value ) );
1383 rasterSymbolizerElem.appendChild( vendorOptionElem );
1393 property = QStringLiteral(
"lightness" );
1396 property = QStringLiteral(
"luminosity" );
1399 property = QStringLiteral(
"average" );
1405 if ( !property.isEmpty() )
1406 vendorOptionWriter( QStringLiteral(
"grayScale" ), property );
1412 vendorOptionWriter( QStringLiteral(
"colorizeOn" ), QString::number(
hueSaturationFilter()->colorizeOn() ) );
1413 vendorOptionWriter( QStringLiteral(
"colorizeRed" ), QString::number(
hueSaturationFilter()->colorizeColor().red() ) );
1414 vendorOptionWriter( QStringLiteral(
"colorizeGreen" ), QString::number(
hueSaturationFilter()->colorizeColor().green() ) );
1415 vendorOptionWriter( QStringLiteral(
"colorizeBlue" ), QString::number(
hueSaturationFilter()->colorizeColor().blue() ) );
1417 vendorOptionWriter( QStringLiteral(
"colorizeStrength" ), QString::number(
hueSaturationFilter()->colorizeStrength() / 100.0 ) );
1418 vendorOptionWriter( QStringLiteral(
"saturation" ), QString::number(
hueSaturationFilter()->colorizeColor().saturationF() ) );
1427 double sF = ( s - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1428 vendorOptionWriter( QStringLiteral(
"saturation" ), QString::number( sF ) );
1437 double bF = ( b - ( -255.0 ) ) / ( 255.0 - ( -255.0 ) );
1438 vendorOptionWriter( QStringLiteral(
"brightness" ), QString::number( bF ) );
1446 double cF = ( c - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1447 vendorOptionWriter( QStringLiteral(
"contrast" ), QString::number( cF ) );
1461 if ( newProps.contains( QStringLiteral(
"contrast" ) ) )
1464 double contrast = newProps[ QStringLiteral(
"contrast" ) ].toDouble();
1465 double percentage = ( contrast - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1466 if ( percentage <= 0.5 )
1469 gamma = percentage / 0.5;
1476 QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral(
"sld:ContrastEnhancement" ) );
1477 rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1479 QDomElement gammaValueElem = doc.createElement( QStringLiteral(
"sld:GammaValue" ) );
1480 gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1481 globalContrastEnhancementElem.appendChild( gammaValueElem );
1498 mPipe.
set( renderer );
1521 QImage myQImage( size, format );
1526 myQImage.setColor( 0, bgColor.rgba() );
1532 double myMapUnitsPerPixel;
1536 if ( myExtent.
width() / myExtent.
height() >=
static_cast< double >( myQImage.width() ) / myQImage.height() )
1538 myMapUnitsPerPixel = myExtent.
width() / myQImage.width();
1539 myY = ( myQImage.height() - myExtent.
height() / myMapUnitsPerPixel ) / 2;
1543 myMapUnitsPerPixel = myExtent.
height() / myQImage.height();
1544 myX = ( myQImage.width() - myExtent.
width() / myMapUnitsPerPixel ) / 2;
1547 double myPixelWidth = myExtent.
width() / myMapUnitsPerPixel;
1548 double myPixelHeight = myExtent.
height() / myMapUnitsPerPixel;
1552 myRasterViewPort->
mWidth = myQImage.width();
1553 myRasterViewPort->
mHeight = myQImage.height();
1563 QPainter *myQPainter =
new QPainter( &myQImage );
1564 draw( myQPainter, myRasterViewPort, myMapToPixel );
1565 delete myRasterViewPort;
1566 delete myMapToPixel;
1586 Q_UNUSED( errorMessage );
1589 QDomElement rasterRendererElem;
1591 QDomElement layerElement = layer_node.toElement();
1598 QDomNode pipeNode = layer_node.firstChildElement( QStringLiteral(
"pipe" ) );
1599 if ( pipeNode.isNull() )
1601 pipeNode = layer_node;
1605 if ( !layer_node.firstChildElement( QStringLiteral(
"rasterproperties" ) ).isNull() )
1608 QDomNode layerNodeCopy = layer_node.cloneNode();
1609 QDomDocument doc = layerNodeCopy.ownerDocument();
1610 QDomElement rasterPropertiesElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterproperties" ) );
1613 rasterRendererElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1618 rasterRendererElem = pipeNode.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1621 if ( !rasterRendererElem.isNull() )
1623 QString rendererType = rasterRendererElem.attribute( QStringLiteral(
"type" ) );
1628 mPipe.
set( renderer );
1634 mPipe.
set( brightnessFilter );
1637 QDomElement brightnessElem = pipeNode.firstChildElement( QStringLiteral(
"brightnesscontrast" ) );
1638 if ( !brightnessElem.isNull() )
1640 brightnessFilter->
readXml( brightnessElem );
1645 mPipe.
set( hueSaturationFilter );
1648 QDomElement hueSaturationElem = pipeNode.firstChildElement( QStringLiteral(
"huesaturation" ) );
1649 if ( !hueSaturationElem.isNull() )
1651 hueSaturationFilter->
readXml( hueSaturationElem );
1656 mPipe.
set( resampleFilter );
1659 QDomElement resampleElem = pipeNode.firstChildElement( QStringLiteral(
"rasterresampler" ) );
1660 if ( !resampleElem.isNull() )
1662 resampleFilter->
readXml( resampleElem );
1666 QDomNode blendModeNode = layer_node.namedItem( QStringLiteral(
"blendMode" ) );
1667 if ( !blendModeNode.isNull() )
1669 QDomElement e = blendModeNode.toElement();
1680 return readSymbology( node, errorMessage, context, categories );
1689 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
1691 if ( pkeyNode.isNull() )
1697 QDomElement pkeyElt = pkeyNode.toElement();
1711 QDomNode rpNode = layer_node.namedItem( QStringLiteral(
"rasterproperties" ) );
1717 if ( !
mDataSource.contains( QLatin1String(
"crs=" ) ) && !
mDataSource.contains( QLatin1String(
"format=" ) ) )
1719 QgsDebugMsgLevel( QStringLiteral(
"Old WMS URI format detected -> adding params" ), 4 );
1722 QDomElement layerElement = rpNode.firstChildElement( QStringLiteral(
"wmsSublayer" ) );
1723 while ( !layerElement.isNull() )
1728 uri.
setParam( QStringLiteral(
"layers" ), layerElement.namedItem( QStringLiteral(
"name" ) ).toElement().text() );
1731 uri.
setParam( QStringLiteral(
"styles" ), layerElement.namedItem( QStringLiteral(
"style" ) ).toElement().text() );
1733 layerElement = layerElement.nextSiblingElement( QStringLiteral(
"wmsSublayer" ) );
1737 QDomNode formatNode = rpNode.namedItem( QStringLiteral(
"wmsFormat" ) );
1738 uri.
setParam( QStringLiteral(
"format" ), rpNode.namedItem( QStringLiteral(
"wmsFormat" ) ).toElement().text() );
1742 uri.
setParam( QStringLiteral(
"crs" ),
crs().authid() );
1751 if ( ! mDataProvider )
1772 QDomNode stampNode = layer_node.namedItem(
"timestamp" );
1773 if ( !stampNode.isNull() )
1775 QDateTime stamp = QDateTime::fromString( stampNode.toElement().text(), Qt::ISODate );
1777 if ( stamp < mDataProvider->dataTimestamp() )
1779 QgsDebugMsg( QStringLiteral(
"data changed, reload provider" ) );
1780 closeDataProvider();
1783 if ( !
mValid )
return false;
1789 QDomElement noDataElement = layer_node.firstChildElement( QStringLiteral(
"noData" ) );
1791 QDomNodeList noDataBandList = noDataElement.elementsByTagName( QStringLiteral(
"noDataList" ) );
1793 for (
int i = 0; i < noDataBandList.size(); ++i )
1795 QDomElement bandElement = noDataBandList.at( i ).toElement();
1797 int bandNo = bandElement.attribute( QStringLiteral(
"bandNo" ) ).toInt( &ok );
1799 if ( ok && ( bandNo > 0 ) && ( bandNo <= mDataProvider->
bandCount() ) )
1801 mDataProvider->
setUseSourceNoDataValue( bandNo, bandElement.attribute( QStringLiteral(
"useSrcNoData" ) ).toInt() );
1804 QDomNodeList rangeList = bandElement.elementsByTagName( QStringLiteral(
"noDataRange" ) );
1806 myNoDataRangeList.reserve( rangeList.size() );
1807 for (
int j = 0; j < rangeList.size(); ++j )
1809 QDomElement rangeElement = rangeList.at( j ).toElement();
1810 QgsRasterRange myNoDataRange( rangeElement.attribute( QStringLiteral(
"min" ) ).toDouble(),
1811 rangeElement.attribute( QStringLiteral(
"max" ) ).toDouble() );
1812 QgsDebugMsgLevel( QStringLiteral(
"min = %1 %2" ).arg( rangeElement.attribute(
"min" ) ).arg( myNoDataRange.min() ), 4 );
1813 myNoDataRangeList << myNoDataRange;
1833 Q_UNUSED( errorMessage );
1836 QDomElement layerElement = layer_node.toElement();
1841 QDomElement pipeElement = document.createElement( QStringLiteral(
"pipe" ) );
1843 for (
int i = 1; i < mPipe.
size(); i++ )
1846 if ( !interface )
continue;
1847 interface->writeXml( document, pipeElement );
1850 layer_node.appendChild( pipeElement );
1853 QDomElement blendModeElement = document.createElement( QStringLiteral(
"blendMode" ) );
1855 blendModeElement.appendChild( blendModeText );
1856 layer_node.appendChild( blendModeElement );
1864 return writeSymbology( node, doc, errorMessage, context, categories );
1872 QDomDocument &document,
1877 QDomElement mapLayerNode = layer_node.toElement();
1879 if ( mapLayerNode.isNull() ||
"maplayer" != mapLayerNode.nodeName() )
1885 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"raster" ) );
1889 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
1890 QDomText providerText = document.createTextNode(
mProviderKey );
1891 provider.appendChild( providerText );
1892 layer_node.appendChild( provider );
1895 QDomElement noData = document.createElement( QStringLiteral(
"noData" ) );
1897 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
1899 QDomElement noDataRangeList = document.createElement( QStringLiteral(
"noDataList" ) );
1900 noDataRangeList.setAttribute( QStringLiteral(
"bandNo" ), bandNo );
1901 noDataRangeList.setAttribute( QStringLiteral(
"useSrcNoData" ), mDataProvider->
useSourceNoDataValue( bandNo ) );
1905 QDomElement noDataRange = document.createElement( QStringLiteral(
"noDataRange" ) );
1909 noDataRangeList.appendChild( noDataRange );
1912 noData.appendChild( noDataRangeList );
1915 if ( noData.hasChildNodes() )
1917 layer_node.appendChild( noData );
1924 return writeSymbology( layer_node, document, errorMsg, context );
1928 static bool _parseGpkgColons(
const QString &src, QString &filename, QString &tablename )
1933 QStringList lst = src.split(
':' );
1934 if ( lst.count() != 3 && lst.count() != 4 )
1937 tablename = lst.last();
1938 if ( lst.count() == 3 )
1943 else if ( lst.count() == 4 && lst[1].count() == 1 && ( lst[2][0] ==
'/' || lst[2][0] ==
'\\' ) )
1946 filename = lst[1] +
":" + lst[2];
1955 QString src( source );
1956 bool handled =
false;
1961 if ( src.startsWith( QLatin1String(
"NETCDF:" ) ) )
1965 QRegExp r(
"NETCDF:(.+):([^:]+)" );
1966 if ( r.exactMatch( src ) )
1968 QString filename = r.cap( 1 );
1969 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
1970 filename = filename.mid( 1, filename.length() - 2 );
1975 else if ( src.startsWith( QLatin1String(
"GPKG:" ) ) )
1978 QString filename, tablename;
1979 if ( _parseGpkgColons( src, filename, tablename ) )
1982 src = QStringLiteral(
"GPKG:%1:%2" ).arg( filename, tablename );
1986 else if ( src.startsWith( QLatin1String(
"HDF4_SDS:" ) ) )
1990 QRegExp r(
"HDF4_SDS:([^:]+):(.+):([^:]+)" );
1991 if ( r.exactMatch( src ) )
1993 QString filename = r.cap( 2 );
1994 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
1995 filename = filename.mid( 1, filename.length() - 2 );
1996 src =
"HDF4_SDS:" + r.cap( 1 ) +
":\"" + context.
pathResolver().
writePath( filename ) +
"\":" + r.cap( 3 );
2000 else if ( src.startsWith( QLatin1String(
"HDF5:" ) ) )
2004 QRegExp r(
"HDF5:(.+):([^:]+)" );
2005 if ( r.exactMatch( src ) )
2007 QString filename = r.cap( 1 );
2008 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2009 filename = filename.mid( 1, filename.length() - 2 );
2014 else if ( src.contains( QRegExp(
"^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2018 QRegExp r(
"([^:]+):([^:]+):(.+)" );
2019 if ( r.exactMatch( src ) )
2035 QString src( source );
2037 if ( provider == QLatin1String(
"wms" ) )
2051 if ( !src.contains( QLatin1String(
"type=" ) ) &&
2052 !src.contains( QLatin1String(
"crs=" ) ) && !src.contains( QLatin1String(
"format=" ) ) )
2054 QgsDebugMsg( QStringLiteral(
"Old WMS URI format detected -> converting to new format" ) );
2056 if ( !src.startsWith( QLatin1String(
"http:" ) ) )
2058 QStringList parts = src.split(
',' );
2059 QStringListIterator iter( parts );
2060 while ( iter.hasNext() )
2062 QString item = iter.next();
2063 if ( item.startsWith( QLatin1String(
"username=" ) ) )
2065 uri.
setParam( QStringLiteral(
"username" ), item.mid( 9 ) );
2067 else if ( item.startsWith( QLatin1String(
"password=" ) ) )
2069 uri.
setParam( QStringLiteral(
"password" ), item.mid( 9 ) );
2071 else if ( item.startsWith( QLatin1String(
"tiled=" ) ) )
2077 QStringList params = item.mid( 6 ).split(
';' );
2079 if ( params.size() == 2 )
2081 uri.
setParam( QStringLiteral(
"maxWidth" ), params.takeFirst() );
2082 uri.
setParam( QStringLiteral(
"maxHeight" ), params.takeFirst() );
2084 else if ( params.size() > 2 )
2088 uri.
setParam( QStringLiteral(
"tileMatrixSet" ), QString() );
2091 else if ( item.startsWith( QLatin1String(
"featureCount=" ) ) )
2093 uri.
setParam( QStringLiteral(
"featureCount" ), item.mid( 13 ) );
2095 else if ( item.startsWith( QLatin1String(
"url=" ) ) )
2097 uri.
setParam( QStringLiteral(
"url" ), item.mid( 4 ) );
2099 else if ( item.startsWith( QLatin1String(
"ignoreUrl=" ) ) )
2101 uri.
setParam( QStringLiteral(
"ignoreUrl" ), item.mid( 10 ).split(
';' ) );
2107 uri.
setParam( QStringLiteral(
"url" ), src );
2117 bool handled =
false;
2119 if ( provider == QLatin1String(
"gdal" ) )
2121 if ( src.startsWith( QLatin1String(
"NETCDF:" ) ) )
2125 QRegExp r(
"NETCDF:(.+):([^:]+)" );
2126 if ( r.exactMatch( src ) )
2128 QString filename = r.cap( 1 );
2129 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2130 filename = filename.mid( 1, filename.length() - 2 );
2135 else if ( src.startsWith( QLatin1String(
"GPKG:" ) ) )
2138 QString filename, tablename;
2139 if ( _parseGpkgColons( src, filename, tablename ) )
2142 src = QStringLiteral(
"GPKG:%1:%2" ).arg( filename, tablename );
2146 else if ( src.startsWith( QLatin1String(
"HDF4_SDS:" ) ) )
2150 QRegExp r(
"HDF4_SDS:([^:]+):(.+):([^:]+)" );
2151 if ( r.exactMatch( src ) )
2153 QString filename = r.cap( 2 );
2154 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2155 filename = filename.mid( 1, filename.length() - 2 );
2156 src =
"HDF4_SDS:" + r.cap( 1 ) +
":\"" + context.
pathResolver().
readPath( filename ) +
"\":" + r.cap( 3 );
2160 else if ( src.startsWith( QLatin1String(
"HDF5:" ) ) )
2164 QRegExp r(
"HDF5:(.+):([^:]+)" );
2165 if ( r.exactMatch( src ) )
2167 QString filename = r.cap( 1 );
2168 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2169 filename = filename.mid( 1, filename.length() - 2 );
2174 else if ( src.contains( QRegExp(
"^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2178 QRegExp r(
"([^:]+):([^:]+):(.+)" );
2179 if ( r.exactMatch( src ) )
2196 if ( !mDataProvider )
return 0;
2197 return mDataProvider->
xSize();
2202 if ( !mDataProvider )
return 0;
2203 return mDataProvider->
ySize();
2211 bool QgsRasterLayer::update()
2218 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)
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
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.
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:
QgsHueSaturationFilter * hueSaturationFilter() const
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 raster renderer. Takes ownership of the renderer object.
virtual QgsError error() const
Gets current status error.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
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.
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.
double max() const
Returns the maximum value for the range.
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
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.
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.
QgsMapLayer::LayerType type() const
Returns the type of the layer.
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
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) ...
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 layer's data provider, it may be null.
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. ...
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.
#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...
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.
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)
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) ...
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.
double minimumScale() const
Returns the minimum map scale (i.e.
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.
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
QgsRasterResampleFilter * resampleFilter() const
Sets raster resample filter. Takes ownership of the resample filter object.
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.
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.
QByteArray encodedUri() const
Returns complete encoded uri (generic mode)
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(...
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
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 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.
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.
virtual void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
Gets symbology items if provided by renderer.
double min() const
Returns the minimum value for the range.
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 PostgreSQL/RDBMS datasource URI.
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.
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.
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.