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" ) )
149 for (
int i = 1; i < mPipe.
size(); i++ )
169 QgsDebugMsg( QStringLiteral(
"Could not resolve isValidRasterFileName in gdal provider library" ) );
173 bool myIsValid = pValid( fileNameQString, retErrMsg );
188 QFileInfo fi( name );
194 t = fi.lastModified();
217 if ( !mDataProvider )
return 0;
233 return mDataProvider;
238 return mDataProvider;
281 drawer.draw( theQPainter, rasterViewPort, qgsMapToPixel );
283 QgsDebugMsgLevel( QStringLiteral(
"total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
288 QList< QPair< QString, QColor > > symbolList;
300 QString myMetadata = QStringLiteral(
"<html>\n<body>\n" );
303 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Information from provider" ) + QStringLiteral(
"</h1>\n<hr>\n" );
304 myMetadata += QLatin1String(
"<table class=\"list-view\">\n" );
307 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Name" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
312 if ( uriComponents.contains( QStringLiteral(
"path" ) ) )
314 path = uriComponents[QStringLiteral(
"path" )].toString();
315 if ( QFile::exists( path ) )
316 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" );
318 if ( uriComponents.contains( QStringLiteral(
"url" ) ) )
320 const QString url = uriComponents[QStringLiteral(
"url" )].toString();
321 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" );
326 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
330 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() ) + QStringLiteral(
"</td></tr>\n" );
333 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"CRS" ) + QStringLiteral(
"</td><td>" );
336 myMetadata +=
crs().
authid() + QStringLiteral(
" - " );
338 if (
crs().isGeographic() )
339 myMetadata += tr(
"Geographic" );
341 myMetadata += tr(
"Projected" );
343 myMetadata += QLatin1String(
"</td></tr>\n" );
346 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Extent" ) + QStringLiteral(
"</td><td>" ) +
extent().
toString() + QStringLiteral(
"</td></tr>\n" );
349 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Unit" ) + QStringLiteral(
"</td><td>" ) +
QgsUnitTypes::toString(
crs().mapUnits() ) + QStringLiteral(
"</td></tr>\n" );
352 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Width" ) + QStringLiteral(
"</td><td>" );
354 myMetadata += QString::number(
width() );
356 myMetadata += tr(
"n/a" );
357 myMetadata += QLatin1String(
"</td></tr>\n" );
360 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Height" ) + QStringLiteral(
"</td><td>" );
362 myMetadata += QString::number(
height() );
364 myMetadata += tr(
"n/a" );
365 myMetadata += QLatin1String(
"</td></tr>\n" );
368 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Data type" ) + QStringLiteral(
"</td><td>" );
373 myMetadata += tr(
"Byte - Eight bit unsigned integer" );
376 myMetadata += tr(
"UInt16 - Sixteen bit unsigned integer " );
379 myMetadata += tr(
"Int16 - Sixteen bit signed integer " );
382 myMetadata += tr(
"UInt32 - Thirty two bit unsigned integer " );
385 myMetadata += tr(
"Int32 - Thirty two bit signed integer " );
388 myMetadata += tr(
"Float32 - Thirty two bit floating point " );
391 myMetadata += tr(
"Float64 - Sixty four bit floating point " );
394 myMetadata += tr(
"CInt16 - Complex Int16 " );
397 myMetadata += tr(
"CInt32 - Complex Int32 " );
400 myMetadata += tr(
"CFloat32 - Complex Float32 " );
403 myMetadata += tr(
"CFloat64 - Complex Float64 " );
406 myMetadata += tr(
"Could not determine raster data type." );
408 myMetadata += QLatin1String(
"</td></tr>\n" );
414 myMetadata += QLatin1String(
"</table>\n<br><br>" );
417 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Identification" ) + QStringLiteral(
"</h1>\n<hr>\n" );
419 myMetadata += QLatin1String(
"<br><br>\n" );
422 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Extent" ) + QStringLiteral(
"</h1>\n<hr>\n" );
424 myMetadata += QLatin1String(
"<br><br>\n" );
427 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Access" ) + QStringLiteral(
"</h1>\n<hr>\n" );
429 myMetadata += QLatin1String(
"<br><br>\n" );
432 myMetadata += QStringLiteral(
"</table>\n<br><br><h1>" ) + tr(
"Bands" ) + QStringLiteral(
"</h1>\n<hr>\n<table class=\"list-view\">\n" );
435 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Band count" ) + QStringLiteral(
"</td><td>" ) + QString::number(
bandCount() ) + QStringLiteral(
"</td></tr>\n" );
438 myMetadata += QLatin1String(
"</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
439 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" );
446 rowClass = QStringLiteral(
"class=\"odd-row\"" );
447 myMetadata += QLatin1String(
"<tr " ) + rowClass + QLatin1String(
"><td>" ) + QString::number( i ) + QLatin1String(
"</td><td>" ) +
bandName( i ) + QLatin1String(
"</td><td>" );
450 myMetadata += QString::number(
dataProvider()->sourceNoDataValue( i ) );
452 myMetadata += tr(
"n/a" );
453 myMetadata += QLatin1String(
"</td>" );
458 myMetadata += QLatin1String(
"<td>" ) + QString::number( myRasterBandStats.
minimumValue,
'f', 10 ) + QLatin1String(
"</td>" );
459 myMetadata += QLatin1String(
"<td>" ) + QString::number( myRasterBandStats.
maximumValue,
'f', 10 ) + QLatin1String(
"</td>" );
463 myMetadata += QLatin1String(
"<td>" ) + tr(
"n/a" ) + QLatin1String(
"</td><td>" ) + tr(
"n/a" ) + QLatin1String(
"</td>" );
466 myMetadata += QLatin1String(
"</tr>\n" );
470 myMetadata += QLatin1String(
"</table>\n<br><br>" );
473 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Contacts" ) + QStringLiteral(
"</h1>\n<hr>\n" );
475 myMetadata += QLatin1String(
"<br><br>\n" );
478 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"References" ) + QStringLiteral(
"</h1>\n<hr>\n" );
480 myMetadata += QLatin1String(
"<br><br>\n" );
483 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"History" ) + QStringLiteral(
"</h1>\n<hr>\n" );
485 myMetadata += QLatin1String(
"<br><br>\n" );
487 myMetadata += QStringLiteral(
"\n</body>\n</html>\n" );
502 QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->
colorTable( bandNumber );
503 if ( !myColorRampItemList.isEmpty() )
510 QPixmap myPalettePixmap( mySize, mySize );
511 QPainter myQPainter( &myPalettePixmap );
513 QImage myQImage = QImage( mySize, mySize, QImage::Format_RGB32 );
515 myPalettePixmap.fill();
517 double myStep = (
static_cast< double >( myColorRampItemList.size() ) - 1 ) /
static_cast< double >( mySize * mySize );
518 double myValue = 0.0;
519 for (
int myRow = 0; myRow < mySize; myRow++ )
521 QRgb *myLineBuffer =
reinterpret_cast< QRgb *
>( myQImage.scanLine( myRow ) );
522 for (
int myCol = 0; myCol < mySize; myCol++ )
524 myValue = myStep *
static_cast< double >( myCol + myRow * mySize );
526 myShader.
shade( myValue, &c1, &c2, &c3, &c4 );
527 myLineBuffer[ myCol ] = qRgba( c1, c2, c3, c4 );
531 myQPainter.drawImage( 0, 0, myQImage );
532 return myPalettePixmap;
534 QPixmap myNullPixmap;
540 QPixmap myNullPixmap;
574 void QgsRasterLayer::init()
592 mPipe.
remove( mDataProvider );
593 mDataProvider =
nullptr;
608 if ( !mDataProvider )
615 mDataProvider->setParent(
this );
618 mPipe.
set( mDataProvider );
619 if ( !mDataProvider->
isValid() )
629 QgsDebugMsgLevel( QStringLiteral(
"Set Data provider QgsLayerMetadata identifier[%1]" ).arg(
metadata().identifier() ), 4 );
632 if ( provider == QLatin1String(
"gdal" ) )
664 if ( ( mDataProvider->
bandCount() > 1 ) )
712 QList<QgsColorRampShader::ColorRampItem> colorTable = mDataProvider->
colorTable( 1 );
735 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
749 mPipe.
set( brightnessFilter );
753 mPipe.
set( hueSaturationFilter );
757 mPipe.
set( resampleFilter );
761 mPipe.
set( projector );
803 QDomImplementation domImplementation;
804 QDomDocumentType documentType;
807 QDomElement rootNode;
810 if ( wasValid && ! loadDefaultStyleFlag )
812 documentType = domImplementation.createDocumentType(
813 QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
814 doc = QDomDocument( documentType );
815 rootNode = doc.createElement( QStringLiteral(
"qgis" ) );
817 doc.appendChild( rootNode );
821 QgsDebugMsg( QStringLiteral(
"Could not store symbology for layer %1: %2" )
832 for (
int i = mPipe.
size() - 1; i >= 0; --i )
845 bool defaultLoadedFlag =
false;
846 if ( loadDefaultStyleFlag )
850 else if ( wasValid && errorMsg.isEmpty() )
855 QgsDebugMsg( QStringLiteral(
"Could not restore symbology for layer %1: %2" )
862 if ( !defaultLoadedFlag )
872 void QgsRasterLayer::closeDataProvider()
875 mPipe.
remove( mDataProvider );
876 mDataProvider =
nullptr;
879 void QgsRasterLayer::computeMinMax(
int band,
884 double &min,
double &max )
887 min = std::numeric_limits<double>::quiet_NaN();
888 max = std::numeric_limits<double>::quiet_NaN();
906 QgsDebugMsgLevel( QStringLiteral(
"myLower = %1 myUpper = %2" ).arg( myLower ).arg( myUpper ), 4 );
907 mDataProvider->
cumulativeCut( band, myLower, myUpper, min, max, extent, sampleSize );
909 QgsDebugMsgLevel( QStringLiteral(
"band = %1 min = %2 max = %3" ).arg( band ).arg( min ).arg( max ), 4 );
920 generateLookupTableFlag,
928 bool generateLookupTableFlag,
932 if ( !rasterRenderer || !mDataProvider )
938 QList<QgsContrastEnhancement *> myEnhancements;
944 QString rendererType = rasterRenderer->
type();
945 if ( rendererType == QLatin1String(
"singlebandgray" ) )
948 if ( !myGrayRenderer )
952 myBands << myGrayRenderer->
grayBand();
953 myRasterRenderer = myGrayRenderer;
956 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
959 if ( !myMultiBandRenderer )
964 myRasterRenderer = myMultiBandRenderer;
967 else if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
970 if ( !myPseudoColorRenderer )
974 myBands << myPseudoColorRenderer->
band();
975 myRasterRenderer = myPseudoColorRenderer;
983 const auto constMyBands = myBands;
984 for (
int myBand : constMyBands )
989 std::unique_ptr<QgsContrastEnhancement> myEnhancement(
new QgsContrastEnhancement( static_cast< Qgis::DataType >( myType ) ) );
990 myEnhancement->setContrastEnhancementAlgorithm(
algorithm, generateLookupTableFlag );
994 computeMinMax( myBand, myMinMaxOrigin, limits, extent, sampleSize, min, max );
996 if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
1000 if ( myPseudoColorRenderer->
shader() )
1003 if ( colorRampShader )
1011 myEnhancement->setMinimumValue( min );
1012 myEnhancement->setMaximumValue( max );
1013 myEnhancements.append( myEnhancement.release() );
1018 myEnhancements.append(
nullptr );
1022 if ( rendererType == QLatin1String(
"singlebandgray" ) )
1026 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
1034 qDeleteAll( myEnhancements );
1042 if ( myRasterRenderer )
1047 if ( rasterRenderer ==
renderer() )
1060 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) ) )
1064 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) ) )
1099 if ( !( mDataProvider &&
1100 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded != extent &&
1109 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>( rasterRenderer ) ) )
1113 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>( rasterRenderer ) ) )
1117 else if ( ( sbpcr = dynamic_cast<QgsSingleBandPseudoColorRenderer *>( rasterRenderer ) ) )
1119 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1122 computeMinMax( sbpcr->
band(),
1132 if ( colorRampShader )
1145 if ( colorRampShader )
1160 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1170 if ( singleBandRenderer )
1172 else if ( multiBandRenderer )
1201 QString defaultLimits;
1204 if ( dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) )
1206 key = QStringLiteral(
"singleBand" );
1212 else if ( dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) )
1216 key = QStringLiteral(
"multiBandSingleByte" );
1224 key = QStringLiteral(
"multiBandMultiByte" );
1232 if ( key.isEmpty() )
1234 QgsDebugMsg( QStringLiteral(
"No default contrast enhancement for this drawing style" ) );
1241 QString myAlgorithmString = mySettings.
value(
"/Raster/defaultContrastEnhancementAlgorithm/" + key, defaultAlg ).toString();
1246 QString myLimitsString = mySettings.
value(
"/Raster/defaultContrastEnhancementLimits/" + key, defaultLimits ).toString();
1268 if ( mDataProvider )
1270 QgsDebugMsgLevel( QStringLiteral(
"About to mDataProvider->setLayerOrder(layers)." ), 4 );
1279 if ( mDataProvider )
1281 QgsDebugMsgLevel( QStringLiteral(
"About to mDataProvider->setSubLayerVisibility(name, vis)." ), 4 );
1295 Q_UNUSED( errorMessage )
1307 QDomElement constraintElem = doc.createElement( QStringLiteral(
"sld:LayerFeatureConstraints" ) );
1308 node.appendChild( constraintElem );
1310 QDomElement featureTypeConstraintElem = doc.createElement( QStringLiteral(
"sld:FeatureTypeConstraint" ) );
1311 constraintElem.appendChild( featureTypeConstraintElem );
1313 QDomElement userStyleElem = doc.createElement( QStringLiteral(
"sld:UserStyle" ) );
1314 node.appendChild( userStyleElem );
1316 if ( !
name().isEmpty() )
1318 QDomElement nameElem = doc.createElement( QStringLiteral(
"sld:Name" ) );
1319 nameElem.appendChild( doc.createTextNode(
name() ) );
1320 userStyleElem.appendChild( nameElem );
1323 if ( !
abstract().isEmpty() )
1325 QDomElement abstractElem = doc.createElement( QStringLiteral(
"sld:Abstract" ) );
1326 abstractElem.appendChild( doc.createTextNode(
abstract() ) );
1327 userStyleElem.appendChild( abstractElem );
1330 if ( !
title().isEmpty() )
1332 QDomElement titleElem = doc.createElement( QStringLiteral(
"sld:Title" ) );
1333 titleElem.appendChild( doc.createTextNode(
title() ) );
1334 userStyleElem.appendChild( titleElem );
1337 QDomElement featureTypeStyleElem = doc.createElement( QStringLiteral(
"sld:FeatureTypeStyle" ) );
1338 userStyleElem.appendChild( featureTypeStyleElem );
1348 QDomElement typeStyleNameElem = doc.createElement( QStringLiteral(
"sld:Name" ) );
1349 featureTypeStyleElem.appendChild( typeStyleNameElem );
1352 QDomElement typeStyleRuleElem = doc.createElement( QStringLiteral(
"sld:Rule" ) );
1353 featureTypeStyleElem.appendChild( typeStyleRuleElem );
1361 QDomElement minScaleElem = doc.createElement( QStringLiteral(
"sld:MinScaleDenominator" ) );
1362 minScaleElem.appendChild( doc.createTextNode( QString::number(
maximumScale() ) ) );
1363 typeStyleRuleElem.appendChild( minScaleElem );
1366 QDomElement maxScaleElem = doc.createElement( QStringLiteral(
"sld:MaxScaleDenominator" ) );
1367 maxScaleElem.appendChild( doc.createTextNode( QString::number(
minimumScale() ) ) );
1368 typeStyleRuleElem.appendChild( maxScaleElem );
1372 mPipe.
renderer()->
toSld( doc, typeStyleRuleElem, localProps );
1377 QDomNodeList elements = typeStyleRuleElem.elementsByTagName( QStringLiteral(
"sld:RasterSymbolizer" ) );
1378 if ( elements.size() != 0 )
1381 QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();
1384 auto vendorOptionWriter = [&]( QString
name, QString value )
1386 QDomElement vendorOptionElem = doc.createElement( QStringLiteral(
"sld:VendorOption" ) );
1387 vendorOptionElem.setAttribute( QStringLiteral(
"name" ), name );
1388 vendorOptionElem.appendChild( doc.createTextNode( value ) );
1389 rasterSymbolizerElem.appendChild( vendorOptionElem );
1399 property = QStringLiteral(
"lightness" );
1402 property = QStringLiteral(
"luminosity" );
1405 property = QStringLiteral(
"average" );
1411 if ( !property.isEmpty() )
1412 vendorOptionWriter( QStringLiteral(
"grayScale" ), property );
1418 vendorOptionWriter( QStringLiteral(
"colorizeOn" ), QString::number(
hueSaturationFilter()->colorizeOn() ) );
1419 vendorOptionWriter( QStringLiteral(
"colorizeRed" ), QString::number(
hueSaturationFilter()->colorizeColor().red() ) );
1420 vendorOptionWriter( QStringLiteral(
"colorizeGreen" ), QString::number(
hueSaturationFilter()->colorizeColor().green() ) );
1421 vendorOptionWriter( QStringLiteral(
"colorizeBlue" ), QString::number(
hueSaturationFilter()->colorizeColor().blue() ) );
1423 vendorOptionWriter( QStringLiteral(
"colorizeStrength" ), QString::number(
hueSaturationFilter()->colorizeStrength() / 100.0 ) );
1424 vendorOptionWriter( QStringLiteral(
"saturation" ), QString::number(
hueSaturationFilter()->colorizeColor().saturationF() ) );
1433 double sF = ( s - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1434 vendorOptionWriter( QStringLiteral(
"saturation" ), QString::number( sF ) );
1443 double bF = ( b - ( -255.0 ) ) / ( 255.0 - ( -255.0 ) );
1444 vendorOptionWriter( QStringLiteral(
"brightness" ), QString::number( bF ) );
1452 double cF = ( c - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1453 vendorOptionWriter( QStringLiteral(
"contrast" ), QString::number( cF ) );
1467 if ( newProps.contains( QStringLiteral(
"contrast" ) ) )
1470 double contrast = newProps[ QStringLiteral(
"contrast" ) ].toDouble();
1471 double percentage = ( contrast - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
1472 if ( percentage <= 0.5 )
1475 gamma = percentage / 0.5;
1482 QDomElement globalContrastEnhancementElem = doc.createElement( QStringLiteral(
"sld:ContrastEnhancement" ) );
1483 rasterSymolizerElem.appendChild( globalContrastEnhancementElem );
1485 QDomElement gammaValueElem = doc.createElement( QStringLiteral(
"sld:GammaValue" ) );
1486 gammaValueElem.appendChild( doc.createTextNode( QString::number( gamma ) ) );
1487 globalContrastEnhancementElem.appendChild( gammaValueElem );
1504 mPipe.
set( renderer );
1520 if ( mDataProvider )
1533 QImage myQImage( size, format );
1538 myQImage.setColor( 0, bgColor.rgba() );
1544 double myMapUnitsPerPixel;
1548 if ( myExtent.
width() / myExtent.
height() >=
static_cast< double >( myQImage.width() ) / myQImage.height() )
1550 myMapUnitsPerPixel = myExtent.
width() / myQImage.width();
1551 myY = ( myQImage.height() - myExtent.
height() / myMapUnitsPerPixel ) / 2;
1555 myMapUnitsPerPixel = myExtent.
height() / myQImage.height();
1556 myX = ( myQImage.width() - myExtent.
width() / myMapUnitsPerPixel ) / 2;
1559 double myPixelWidth = myExtent.
width() / myMapUnitsPerPixel;
1560 double myPixelHeight = myExtent.
height() / myMapUnitsPerPixel;
1564 myRasterViewPort->
mWidth = myQImage.width();
1565 myRasterViewPort->
mHeight = myQImage.height();
1573 QPainter *myQPainter =
new QPainter( &myQImage );
1574 draw( myQPainter, myRasterViewPort, myMapToPixel );
1575 delete myRasterViewPort;
1576 delete myMapToPixel;
1596 Q_UNUSED( errorMessage )
1599 QDomElement rasterRendererElem;
1601 QDomElement layerElement = layer_node.toElement();
1608 QDomNode pipeNode = layer_node.firstChildElement( QStringLiteral(
"pipe" ) );
1609 if ( pipeNode.isNull() )
1611 pipeNode = layer_node;
1615 if ( !layer_node.firstChildElement( QStringLiteral(
"rasterproperties" ) ).isNull() )
1618 QDomNode layerNodeCopy = layer_node.cloneNode();
1619 QDomDocument doc = layerNodeCopy.ownerDocument();
1620 QDomElement rasterPropertiesElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterproperties" ) );
1623 rasterRendererElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1628 rasterRendererElem = pipeNode.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1631 if ( !rasterRendererElem.isNull() )
1633 QString rendererType = rasterRendererElem.attribute( QStringLiteral(
"type" ) );
1638 mPipe.
set( renderer );
1644 mPipe.
set( brightnessFilter );
1647 QDomElement brightnessElem = pipeNode.firstChildElement( QStringLiteral(
"brightnesscontrast" ) );
1648 if ( !brightnessElem.isNull() )
1650 brightnessFilter->
readXml( brightnessElem );
1655 mPipe.
set( hueSaturationFilter );
1658 QDomElement hueSaturationElem = pipeNode.firstChildElement( QStringLiteral(
"huesaturation" ) );
1659 if ( !hueSaturationElem.isNull() )
1661 hueSaturationFilter->
readXml( hueSaturationElem );
1666 mPipe.
set( resampleFilter );
1669 QDomElement resampleElem = pipeNode.firstChildElement( QStringLiteral(
"rasterresampler" ) );
1670 if ( !resampleElem.isNull() )
1672 resampleFilter->
readXml( resampleElem );
1676 QDomNode blendModeNode = layer_node.namedItem( QStringLiteral(
"blendMode" ) );
1677 if ( !blendModeNode.isNull() )
1679 QDomElement e = blendModeNode.toElement();
1690 return readSymbology( node, errorMessage, context, categories );
1699 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
1701 if ( pkeyNode.isNull() )
1707 QDomElement pkeyElt = pkeyNode.toElement();
1721 QDomNode rpNode = layer_node.namedItem( QStringLiteral(
"rasterproperties" ) );
1727 if ( !
mDataSource.contains( QLatin1String(
"crs=" ) ) && !
mDataSource.contains( QLatin1String(
"format=" ) ) )
1729 QgsDebugMsgLevel( QStringLiteral(
"Old WMS URI format detected -> adding params" ), 4 );
1732 QDomElement layerElement = rpNode.firstChildElement( QStringLiteral(
"wmsSublayer" ) );
1733 while ( !layerElement.isNull() )
1738 uri.
setParam( QStringLiteral(
"layers" ), layerElement.namedItem( QStringLiteral(
"name" ) ).toElement().text() );
1741 uri.
setParam( QStringLiteral(
"styles" ), layerElement.namedItem( QStringLiteral(
"style" ) ).toElement().text() );
1743 layerElement = layerElement.nextSiblingElement( QStringLiteral(
"wmsSublayer" ) );
1747 QDomNode formatNode = rpNode.namedItem( QStringLiteral(
"wmsFormat" ) );
1748 uri.
setParam( QStringLiteral(
"format" ), rpNode.namedItem( QStringLiteral(
"wmsFormat" ) ).toElement().text() );
1752 uri.
setParam( QStringLiteral(
"crs" ),
crs().authid() );
1761 if ( ! mDataProvider )
1782 QDomNode stampNode = layer_node.namedItem(
"timestamp" );
1783 if ( !stampNode.isNull() )
1785 QDateTime stamp = QDateTime::fromString( stampNode.toElement().text(), Qt::ISODate );
1787 if ( stamp < mDataProvider->dataTimestamp() )
1789 QgsDebugMsg( QStringLiteral(
"data changed, reload provider" ) );
1790 closeDataProvider();
1793 if ( !
mValid )
return false;
1799 QDomElement noDataElement = layer_node.firstChildElement( QStringLiteral(
"noData" ) );
1801 QDomNodeList noDataBandList = noDataElement.elementsByTagName( QStringLiteral(
"noDataList" ) );
1803 for (
int i = 0; i < noDataBandList.size(); ++i )
1805 QDomElement bandElement = noDataBandList.at( i ).toElement();
1807 int bandNo = bandElement.attribute( QStringLiteral(
"bandNo" ) ).toInt( &ok );
1809 if ( ok && ( bandNo > 0 ) && ( bandNo <= mDataProvider->
bandCount() ) )
1811 mDataProvider->
setUseSourceNoDataValue( bandNo, bandElement.attribute( QStringLiteral(
"useSrcNoData" ) ).toInt() );
1814 QDomNodeList rangeList = bandElement.elementsByTagName( QStringLiteral(
"noDataRange" ) );
1816 myNoDataRangeList.reserve( rangeList.size() );
1817 for (
int j = 0; j < rangeList.size(); ++j )
1819 QDomElement rangeElement = rangeList.at( j ).toElement();
1820 QgsRasterRange myNoDataRange( rangeElement.attribute( QStringLiteral(
"min" ) ).toDouble(),
1821 rangeElement.attribute( QStringLiteral(
"max" ) ).toDouble() );
1822 QgsDebugMsgLevel( QStringLiteral(
"min = %1 %2" ).arg( rangeElement.attribute(
"min" ) ).arg( myNoDataRange.min() ), 4 );
1823 myNoDataRangeList << myNoDataRange;
1843 Q_UNUSED( errorMessage )
1846 QDomElement layerElement = layer_node.toElement();
1851 QDomElement pipeElement = document.createElement( QStringLiteral(
"pipe" ) );
1853 for (
int i = 1; i < mPipe.
size(); i++ )
1856 if ( !interface )
continue;
1857 interface->writeXml( document, pipeElement );
1860 layer_node.appendChild( pipeElement );
1863 QDomElement blendModeElement = document.createElement( QStringLiteral(
"blendMode" ) );
1865 blendModeElement.appendChild( blendModeText );
1866 layer_node.appendChild( blendModeElement );
1874 return writeSymbology( node, doc, errorMessage, context, categories );
1882 QDomDocument &document,
1887 QDomElement mapLayerNode = layer_node.toElement();
1889 if ( mapLayerNode.isNull() ||
"maplayer" != mapLayerNode.nodeName() )
1895 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"raster" ) );
1899 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
1900 QDomText providerText = document.createTextNode(
mProviderKey );
1901 provider.appendChild( providerText );
1902 layer_node.appendChild( provider );
1905 QDomElement noData = document.createElement( QStringLiteral(
"noData" ) );
1907 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
1909 QDomElement noDataRangeList = document.createElement( QStringLiteral(
"noDataList" ) );
1910 noDataRangeList.setAttribute( QStringLiteral(
"bandNo" ), bandNo );
1911 noDataRangeList.setAttribute( QStringLiteral(
"useSrcNoData" ), mDataProvider->
useSourceNoDataValue( bandNo ) );
1913 const auto constUserNoDataValues = mDataProvider->
userNoDataValues( bandNo );
1916 QDomElement noDataRange = document.createElement( QStringLiteral(
"noDataRange" ) );
1920 noDataRangeList.appendChild( noDataRange );
1923 noData.appendChild( noDataRangeList );
1926 if ( noData.hasChildNodes() )
1928 layer_node.appendChild( noData );
1935 return writeSymbology( layer_node, document, errorMsg, context );
1939 static bool _parseGpkgColons(
const QString &src, QString &filename, QString &tablename )
1944 QStringList lst = src.split(
':' );
1945 if ( lst.count() != 3 && lst.count() != 4 )
1948 tablename = lst.last();
1949 if ( lst.count() == 3 )
1954 else if ( lst.count() == 4 && lst[1].count() == 1 && ( lst[2][0] ==
'/' || lst[2][0] ==
'\\' ) )
1957 filename = lst[1] +
":" + lst[2];
1966 QString src( source );
1967 bool handled =
false;
1972 if ( src.startsWith( QLatin1String(
"NETCDF:" ) ) )
1976 QRegExp r(
"NETCDF:(.+):([^:]+)" );
1977 if ( r.exactMatch( src ) )
1979 QString filename = r.cap( 1 );
1980 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
1981 filename = filename.mid( 1, filename.length() - 2 );
1986 else if ( src.startsWith( QLatin1String(
"GPKG:" ) ) )
1989 QString filename, tablename;
1990 if ( _parseGpkgColons( src, filename, tablename ) )
1993 src = QStringLiteral(
"GPKG:%1:%2" ).arg( filename, tablename );
1997 else if ( src.startsWith( QLatin1String(
"HDF4_SDS:" ) ) )
2001 QRegExp r(
"HDF4_SDS:([^:]+):(.+):([^:]+)" );
2002 if ( r.exactMatch( src ) )
2004 QString filename = r.cap( 2 );
2005 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2006 filename = filename.mid( 1, filename.length() - 2 );
2007 src =
"HDF4_SDS:" + r.cap( 1 ) +
":\"" + context.
pathResolver().
writePath( filename ) +
"\":" + r.cap( 3 );
2011 else if ( src.startsWith( QLatin1String(
"HDF5:" ) ) )
2015 QRegExp r(
"HDF5:(.+):([^:]+)" );
2016 if ( r.exactMatch( src ) )
2018 QString filename = r.cap( 1 );
2019 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2020 filename = filename.mid( 1, filename.length() - 2 );
2025 else if ( src.contains( QRegExp(
"^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2029 QRegExp r(
"([^:]+):([^:]+):(.+)" );
2030 if ( r.exactMatch( src ) )
2042 QUrl srcUrl( uri.
param( QStringLiteral(
"url" ) ) );
2043 if ( srcUrl.isLocalFile() )
2048 uri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
2062 QString src( source );
2064 if ( provider == QLatin1String(
"wms" ) )
2078 if ( !src.contains( QLatin1String(
"type=" ) ) &&
2079 !src.contains( QLatin1String(
"crs=" ) ) && !src.contains( QLatin1String(
"format=" ) ) )
2081 QgsDebugMsg( QStringLiteral(
"Old WMS URI format detected -> converting to new format" ) );
2083 if ( !src.startsWith( QLatin1String(
"http:" ) ) )
2085 QStringList parts = src.split(
',' );
2086 QStringListIterator iter( parts );
2087 while ( iter.hasNext() )
2089 QString item = iter.next();
2090 if ( item.startsWith( QLatin1String(
"username=" ) ) )
2092 uri.
setParam( QStringLiteral(
"username" ), item.mid( 9 ) );
2094 else if ( item.startsWith( QLatin1String(
"password=" ) ) )
2096 uri.
setParam( QStringLiteral(
"password" ), item.mid( 9 ) );
2098 else if ( item.startsWith( QLatin1String(
"tiled=" ) ) )
2104 QStringList params = item.mid( 6 ).split(
';' );
2106 if ( params.size() == 2 )
2108 uri.
setParam( QStringLiteral(
"maxWidth" ), params.takeFirst() );
2109 uri.
setParam( QStringLiteral(
"maxHeight" ), params.takeFirst() );
2111 else if ( params.size() > 2 )
2115 uri.
setParam( QStringLiteral(
"tileMatrixSet" ), QString() );
2118 else if ( item.startsWith( QLatin1String(
"featureCount=" ) ) )
2120 uri.
setParam( QStringLiteral(
"featureCount" ), item.mid( 13 ) );
2122 else if ( item.startsWith( QLatin1String(
"url=" ) ) )
2124 uri.
setParam( QStringLiteral(
"url" ), item.mid( 4 ) );
2126 else if ( item.startsWith( QLatin1String(
"ignoreUrl=" ) ) )
2128 uri.
setParam( QStringLiteral(
"ignoreUrl" ), item.mid( 10 ).split(
';' ) );
2134 uri.
setParam( QStringLiteral(
"url" ), src );
2145 QUrl srcUrl( uri.
param( QStringLiteral(
"url" ) ) );
2146 if ( srcUrl.isLocalFile() )
2150 uri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
2157 bool handled =
false;
2159 if ( provider == QLatin1String(
"gdal" ) )
2161 if ( src.startsWith( QLatin1String(
"NETCDF:" ) ) )
2165 QRegExp r(
"NETCDF:(.+):([^:]+)" );
2166 if ( r.exactMatch( src ) )
2168 QString filename = r.cap( 1 );
2169 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2170 filename = filename.mid( 1, filename.length() - 2 );
2175 else if ( src.startsWith( QLatin1String(
"GPKG:" ) ) )
2178 QString filename, tablename;
2179 if ( _parseGpkgColons( src, filename, tablename ) )
2182 src = QStringLiteral(
"GPKG:%1:%2" ).arg( filename, tablename );
2186 else if ( src.startsWith( QLatin1String(
"HDF4_SDS:" ) ) )
2190 QRegExp r(
"HDF4_SDS:([^:]+):(.+):([^:]+)" );
2191 if ( r.exactMatch( src ) )
2193 QString filename = r.cap( 2 );
2194 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2195 filename = filename.mid( 1, filename.length() - 2 );
2196 src =
"HDF4_SDS:" + r.cap( 1 ) +
":\"" + context.
pathResolver().
readPath( filename ) +
"\":" + r.cap( 3 );
2200 else if ( src.startsWith( QLatin1String(
"HDF5:" ) ) )
2204 QRegExp r(
"HDF5:(.+):([^:]+)" );
2205 if ( r.exactMatch( src ) )
2207 QString filename = r.cap( 1 );
2208 if ( filename.startsWith(
'"' ) && filename.endsWith(
'"' ) )
2209 filename = filename.mid( 1, filename.length() - 2 );
2214 else if ( src.contains( QRegExp(
"^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
2218 QRegExp r(
"([^:]+):([^:]+):(.+)" );
2219 if ( r.exactMatch( src ) )
2236 if ( !mDataProvider )
return 0;
2237 return mDataProvider->
xSize();
2242 if ( !mDataProvider )
return 0;
2243 return mDataProvider->
ySize();
2251 bool QgsRasterLayer::update()
2258 closeDataProvider();
static void mergeScaleDependencies(double mScaleMinDenom, double mScaleMaxDenom, QgsStringMap &props)
Merges the local scale limits, if any, with the ones already in the map, if any.
QgsDataProvider * classFactoryFunction_t(const QString *, const QgsDataProvider::ProviderOptions &options)
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
int width() const
Returns the width of the (unclipped) raster.
QgsRasterMinMaxOrigin::Limits limits() const
Returns the raster limits.
bool shade(double value, int *returnRedValue, int *returnGreenValue, int *returnBlueValue, int *returnAlphaValue) const override
Generates and new RGB value based on one input value.
virtual int bandCount() const =0
Gets number of bands.
QgsRasterMinMaxOrigin::Extent extent() const
Returns the raster extent.
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
Base class for all map layer types.
Thirty two bit signed integer (qint32)
Interface for all raster shaders.
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &list)
Sets a custom colormap.
QgsRasterLayer * clone() const override
Returns a new instance equivalent to this one.
QStringList subLayers() const override
Returns the sublayers of this layer.
static const QString QGIS_VERSION
Version string.
static QString printValue(double value)
Print double value with all necessary significant digits.
void refreshContrastEnhancement(const QgsRectangle &extent)
Refresh contrast enhancement with new extent.
virtual void setUseSourceNoDataValue(int bandNo, bool use)
Sets the source nodata value usage.
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag=false) override
Updates the data source of the layer.
const QgsContrastEnhancement * blueContrastEnhancement() const
QgsMapLayerType type() const
Returns the type of the layer.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
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.
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.
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
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 nullptr.
This class describes the origin of min/max values.
The RasterBandStats struct is a container for statistics about a single raster band.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
static bool isValidRasterFileName(const QString &fileNameQString, QString &retError)
This helper checks to see whether the file name appears to be a valid raster file name...
double mean
The mean cell value for the band. NO_DATA values are excluded.
Continuous palette, QGIS addition, GRASS.
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props=QgsStringMap()) const
Writes the symbology of the layer into the document provided in SLD 1.0.0 format. ...
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
void setRedContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
int removeParam(const QString &key)
Removes a generic parameter by key.
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
Returns true if the rectangle is empty.
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
QgsPointXY mBottomRightPoint
Coordinate (in output device coordinate system) of bottom right corner of the part of the raster that...
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
QgsRectangle extent() const override=0
Returns the extent of the layer.
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for single band raster.
bool loadDefaultStyle
Sets to true if the default layer style should be loaded.
QgsRasterInterface * at(int idx) const
QString providerType() const
[ data provider interface ] Which provider is being used for this Raster Layer?
double width() const
Returns the width of the rectangle.
QgsRasterShaderFunction * rasterShaderFunction()
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
double cumulativeCutUpper() const
Returns the upper bound of cumulative cut method (between 0 and 1).
QString bandName(int bandNoInt) const
Returns the name of a band given its number.
Constantly updated extent of the canvas is used to compute statistics.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
virtual bool hasStatistics(int bandNo, int stats=QgsRasterBandStats::All, const QgsRectangle &extent=QgsRectangle(), int sampleSize=0)
Returns true if histogram is available (cached, already calculated).
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
Raster renderer pipe for single band pseudocolor.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
void setRasterShaderFunction(QgsRasterShaderFunction *function)
A public method that allows the user to set their own shader function.
Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ].
static QString contrastEnhancementAlgorithmString(ContrastEnhancementAlgorithm algorithm)
Returns a string to serialize ContrastEnhancementAlgorithm.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
bool defaultContrastEnhancementSettings(QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, QgsRasterMinMaxOrigin::Limits &myLimits) const
Returns default contrast enhancement settings for that type of raster.
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
void draw(QPainter *theQPainter, QgsRasterViewPort *myRasterViewPort, const QgsMapToPixel *qgsMapToPixel=nullptr)
This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPix...
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
Raster renderer pipe for single band gray.
static int typeSize(int dataType)
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Sixteen bit unsigned integer (quint16)
virtual void setLayerOrder(const QStringList &layers)
Reorder the list of layer names to be rendered by this provider (in order from bottom to top) ...
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
void rendererChanged()
Signal emitted when renderer is changed.
double minimumScale() const
Returns the minimum map scale (i.e.
Contains information about the context in which a coordinate transform is executed.
void setAlphaBand(int band)
double maximumScale() const
Returns the maximum map scale (i.e.
bool mValid
Indicates if the layer is valid and can be drawn.
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
void setName(const QString &name)
Set the display name of the layer.
Q_DECL_DEPRECATED void setDataProvider(const QString &provider)
Set the data provider.
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]...
Base class for processing filters like renderers, reprojector, resampler etc.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
static QString limitsString(Limits limits)
Returns a string to serialize Limits.
void setSubLayerVisibility(const QString &name, bool vis) override
Set the visibility of the given sublayer name.
virtual QString htmlMetadata()=0
Returns metadata in a format suitable for feeding directly into a subset of the GUI raster properties...
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
static ContrastEnhancementAlgorithm contrastEnhancementAlgorithmFromString(const QString &contrastEnhancementString)
Deserialize ContrastEnhancementAlgorithm.
void classifyColorRamp(int classes=0, int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
Classify color ramp shader.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void setMinMaxOrigin(const QgsRasterMinMaxOrigin &origin)
Sets origin of min/max values.
Limits
This enumerator describes the limits used to compute min/max values.
QgsCoordinateReferenceSystem mSrcCRS
Source coordinate system.
void setLimits(QgsRasterMinMaxOrigin::Limits limits)
Sets the limits.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
bool writeSymbology(QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const override
bool set(QgsRasterInterface *interface)
Insert a new known interface in default place or replace interface of the same role if it already exi...
Registry for raster renderer entries.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
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.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
QgsCoordinateTransformContext mTransformContext
Coordinate transform context.
QString source() const
Returns the source for the layer.
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) override
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
Whole raster is used to compute statistics.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
virtual void reloadData()
Reloads the data from the source.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
int mHeight
Distance in map units from bottom edge to top edge for the part of the raster that is to be rendered...
Brightness/contrast filter pipe for rasters.
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.
QgsMapLayerType
Types of layers that can be added to a map.
void refreshRendererIfNeeded(QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
Refresh renderer with new extent, if needed.
~QgsRasterLayer() override
This class provides details of the viewable area that a raster will be rendered into.
QDateTime dataTimestamp() const override
Current time stamp of data source.
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
Assigns the color of the higher class for every pixel between two class breaks.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
virtual void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
Gets symbology items if provided by renderer.
virtual QString generateBandName(int bandNumber) const
helper function to create zero padded band names
void reload() override
Synchronises with changes in the datasource.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
Class for storing the component parts of a RDBMS data source URI (e.g.
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
QgsLegendColorList legendSymbologyItems() const
Returns a list with classification items (Text and color)
virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
double stdDevFactor() const
Returns the factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ]...
virtual int xSize() const
Gets raster size.
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers...
Raster renderer pipe that applies colors to a raster.
QgsRasterRendererCreateFunc rendererCreateFunction
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM
Default enhancement algorithm for multiple band raster of type Byte.
void setError(const QgsError &error)
Sets error message.
QString authid() const
Returns the authority identifier for the CRS.
Eight bit unsigned integer (quint8)
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
Setting options for loading raster layers.
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS
Default enhancement limits for multiple band raster of type different from Byte.
int band() const
Returns the band used by the renderer.
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
double height() const
Returns the height of the rectangle.
Q_DECL_DEPRECATED void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.
virtual int colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
QgsRectangle mDrawnExtent
Intersection of current map extent and layer extent.
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.