56 #include <QApplication> 58 #include <QDomElement> 63 #include <QFontMetrics> 70 #include <QMessageBox> 80 #define ERR(message) QGS_ERROR_MESSAGE(message,"Raster layer") 100 , QSTRING_NOT_SET( QStringLiteral(
"Not Set" ) )
101 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
109 const QString &baseName,
110 const QString &providerKey,
114 , QSTRING_NOT_SET( QStringLiteral(
"Not Set" ) )
115 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
116 , mProviderKey( providerKey )
124 bool defaultLoadedFlag =
false;
129 if ( !defaultLoadedFlag )
153 for (
int i = 1; i < mPipe.
size(); i++ )
176 QgsDebugMsg(
"Could not resolve isValidRasterFileName in gdal provider library" );
180 bool myIsValid = pValid( fileNameQString, retErrMsg );
195 QFileInfo fi( name );
201 t = fi.lastModified();
219 if ( !mDataProvider )
return 0;
238 return mDataProvider;
246 return mDataProvider;
289 drawer.draw( theQPainter, rasterViewPort, qgsMapToPixel );
291 QgsDebugMsgLevel( QString(
"total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
296 QList< QPair< QString, QColor > > symbolList;
308 QString myMetadata = QStringLiteral(
"<html>\n<body>\n" );
311 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Information from provider" ) + QStringLiteral(
"</h1>\n<hr>\n" );
312 myMetadata += QLatin1String(
"<table class=\"list-view\">\n" );
315 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Original" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
318 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Name" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
321 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>" ) +
publicSource() + QStringLiteral(
"</td></tr>\n" );
324 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Provider" ) + QStringLiteral(
"</td><td>" ) +
providerType() + QStringLiteral(
"</td></tr>\n" );
327 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"CRS" ) + QStringLiteral(
"</td><td>" );
330 myMetadata +=
crs().
authid() + QStringLiteral(
" - " );
332 if (
crs().isGeographic() )
333 myMetadata += tr(
"Geographic" );
335 myMetadata += tr(
"Projected" );
337 myMetadata += QLatin1String(
"</td></tr>\n" );
340 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Extent" ) + QStringLiteral(
"</td><td>" ) +
extent().
toString() + QStringLiteral(
"</td></tr>\n" );
343 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Unit" ) + QStringLiteral(
"</td><td>" ) +
QgsUnitTypes::toString(
crs().mapUnits() ) + QStringLiteral(
"</td></tr>\n" );
346 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Width" ) + QStringLiteral(
"</td><td>" );
348 myMetadata += QString::number(
width() );
350 myMetadata += tr(
"n/a" );
351 myMetadata += QLatin1String(
"</td></tr>\n" );
354 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Height" ) + QStringLiteral(
"</td><td>" );
356 myMetadata += QString::number(
height() );
358 myMetadata += tr(
"n/a" );
359 myMetadata += QLatin1String(
"</td></tr>\n" );
362 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Data type" ) + QStringLiteral(
"</td><td>" );
367 myMetadata += tr(
"Byte - Eight bit unsigned integer" );
370 myMetadata += tr(
"UInt16 - Sixteen bit unsigned integer " );
373 myMetadata += tr(
"Int16 - Sixteen bit signed integer " );
376 myMetadata += tr(
"UInt32 - Thirty two bit unsigned integer " );
379 myMetadata += tr(
"Int32 - Thirty two bit signed integer " );
382 myMetadata += tr(
"Float32 - Thirty two bit floating point " );
385 myMetadata += tr(
"Float64 - Sixty four bit floating point " );
388 myMetadata += tr(
"CInt16 - Complex Int16 " );
391 myMetadata += tr(
"CInt32 - Complex Int32 " );
394 myMetadata += tr(
"CFloat32 - Complex Float32 " );
397 myMetadata += tr(
"CFloat64 - Complex Float64 " );
400 myMetadata += tr(
"Could not determine raster data type." );
402 myMetadata += QLatin1String(
"</td></tr>\n" );
408 myMetadata += QLatin1String(
"</table>\n<br><br>" );
411 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Identification" ) + QStringLiteral(
"</h1>\n<hr>\n" );
413 myMetadata += QLatin1String(
"<br><br>\n" );
416 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Extent" ) + QStringLiteral(
"</h1>\n<hr>\n" );
418 myMetadata += QLatin1String(
"<br><br>\n" );
421 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Access" ) + QStringLiteral(
"</h1>\n<hr>\n" );
423 myMetadata += QLatin1String(
"<br><br>\n" );
426 myMetadata += QStringLiteral(
"</table>\n<br><br><h1>" ) + tr(
"Bands" ) + QStringLiteral(
"</h1>\n<hr>\n<table class=\"list-view\">\n" );
429 myMetadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Band count" ) + QStringLiteral(
"</td><td>" ) + QString::number(
bandCount() ) + QStringLiteral(
"</td></tr>\n" );
432 myMetadata += QLatin1String(
"</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
433 myMetadata +=
"<tr><th>" + tr(
"Number" ) +
"</th><th>" + tr(
"Band" ) +
"</th><th>" + tr(
"No-Data" ) +
"</th><th>" + tr(
"Min" ) +
"</th><th>" + tr(
"Max" ) +
"</th></tr>\n";
440 rowClass = QStringLiteral(
"class=\"odd-row\"" );
441 myMetadata +=
"<tr " + rowClass +
"><td>" + QString::number( i ) +
"</td><td>" +
bandName( i ) +
"</td><td>";
444 myMetadata += QString::number(
dataProvider()->sourceNoDataValue( i ) );
446 myMetadata += tr(
"n/a" );
447 myMetadata += QLatin1String(
"</td>" );
452 myMetadata +=
"<td>" + QString::number( myRasterBandStats.
minimumValue,
'f', 10 ) +
"</td>";
453 myMetadata +=
"<td>" + QString::number( myRasterBandStats.
maximumValue,
'f', 10 ) +
"</td>";
457 myMetadata +=
"<td>" + tr(
"n/a" ) +
"</td><td>" + tr(
"n/a" ) +
"</td>";
460 myMetadata += QLatin1String(
"</tr>\n" );
464 myMetadata += QLatin1String(
"</table>\n<br><br>" );
467 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"Contacts" ) + QStringLiteral(
"</h1>\n<hr>\n" );
469 myMetadata += QLatin1String(
"<br><br>\n" );
472 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"References" ) + QStringLiteral(
"</h1>\n<hr>\n" );
474 myMetadata += QLatin1String(
"<br><br>\n" );
477 myMetadata += QStringLiteral(
"<h1>" ) + tr(
"History" ) + QStringLiteral(
"</h1>\n<hr>\n" );
479 myMetadata += QLatin1String(
"<br><br>\n" );
481 myMetadata += QStringLiteral(
"\n</body>\n</html>\n" );
501 QList<QgsColorRampShader::ColorRampItem> myColorRampItemList = mDataProvider->
colorTable( bandNumber );
502 if ( !myColorRampItemList.isEmpty() )
509 QPixmap myPalettePixmap( mySize, mySize );
510 QPainter myQPainter( &myPalettePixmap );
512 QImage myQImage = QImage( mySize, mySize, QImage::Format_RGB32 );
514 myPalettePixmap.fill();
516 double myStep = (
static_cast< double >( myColorRampItemList.size() ) - 1 ) /
static_cast< double >( mySize * mySize );
517 double myValue = 0.0;
518 for (
int myRow = 0; myRow < mySize; myRow++ )
520 QRgb *myLineBuffer =
reinterpret_cast< QRgb *
>( myQImage.scanLine( myRow ) );
521 for (
int myCol = 0; myCol < mySize; myCol++ )
523 myValue = myStep *
static_cast< double >( myCol + myRow * mySize );
525 myShader.
shade( myValue, &c1, &c2, &c3, &c4 );
526 myLineBuffer[ myCol ] = qRgba( c1, c2, c3, c4 );
530 myQPainter.drawImage( 0, 0, myQImage );
531 return myPalettePixmap;
533 QPixmap myNullPixmap;
539 QPixmap myNullPixmap;
576 void QgsRasterLayer::init()
594 mPipe.
remove( mDataProvider );
595 mDataProvider =
nullptr;
600 mProviderKey = provider;
610 if ( !mDataProvider )
613 appendError(
ERR( tr(
"Cannot instantiate the '%1' data provider" ).arg( mProviderKey ) ) );
617 mDataProvider->setParent(
this );
620 mPipe.
set( mDataProvider );
621 if ( !mDataProvider->
isValid() )
631 QgsDebugMsgLevel( QString(
"Set Data provider QgsLayerMetadata identifier[%1]" ).arg(
metadata().identifier() ), 4 );
634 if ( provider == QLatin1String(
"gdal" ) )
666 if ( ( mDataProvider->
bandCount() > 1 ) )
714 QList<QgsColorRampShader::ColorRampItem> colorTable = mDataProvider->
colorTable( 1 );
737 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
751 mPipe.
set( brightnessFilter );
755 mPipe.
set( hueSaturationFilter );
759 mPipe.
set( resampleFilter );
763 mPipe.
set( projector );
800 void QgsRasterLayer::closeDataProvider()
803 mPipe.
remove( mDataProvider );
804 mDataProvider =
nullptr;
807 void QgsRasterLayer::computeMinMax(
int band,
812 double &min,
double &max )
815 min = std::numeric_limits<double>::quiet_NaN();
816 max = std::numeric_limits<double>::quiet_NaN();
834 QgsDebugMsgLevel( QString(
"myLower = %1 myUpper = %2" ).arg( myLower ).arg( myUpper ), 4 );
835 mDataProvider->
cumulativeCut( band, myLower, myUpper, min, max, extent, sampleSize );
837 QgsDebugMsgLevel( QString(
"band = %1 min = %2 max = %3" ).arg( band ).arg( min ).arg( max ), 4 );
848 generateLookupTableFlag,
856 bool generateLookupTableFlag,
859 QgsDebugMsgLevel( QString(
"theAlgorithm = %1 limits = %2 extent.isEmpty() = %3" ).arg( algorithm ).arg( limits ).arg( extent.
isEmpty() ), 4 );
860 if ( !rasterRenderer || !mDataProvider )
866 QList<QgsContrastEnhancement *> myEnhancements;
872 QString rendererType = rasterRenderer->
type();
873 if ( rendererType == QLatin1String(
"singlebandgray" ) )
876 if ( !myGrayRenderer )
880 myBands << myGrayRenderer->
grayBand();
881 myRasterRenderer = myGrayRenderer;
884 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
887 if ( !myMultiBandRenderer )
892 myRasterRenderer = myMultiBandRenderer;
895 else if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
898 if ( !myPseudoColorRenderer )
902 myBands << myPseudoColorRenderer->
band();
903 myRasterRenderer = myPseudoColorRenderer;
911 Q_FOREACH (
int myBand, myBands )
916 std::unique_ptr<QgsContrastEnhancement> myEnhancement(
new QgsContrastEnhancement( static_cast< Qgis::DataType >( myType ) ) );
917 myEnhancement->setContrastEnhancementAlgorithm( algorithm, generateLookupTableFlag );
921 computeMinMax( myBand, myMinMaxOrigin, limits, extent, sampleSize, min, max );
923 if ( rendererType == QLatin1String(
"singlebandpseudocolor" ) )
927 if ( myPseudoColorRenderer->
shader() )
930 if ( colorRampShader )
938 myEnhancement->setMinimumValue( min );
939 myEnhancement->setMaximumValue( max );
940 myEnhancements.append( myEnhancement.release() );
945 myEnhancements.append(
nullptr );
949 if ( rendererType == QLatin1String(
"singlebandgray" ) )
953 else if ( rendererType == QLatin1String(
"multibandcolor" ) )
961 qDeleteAll( myEnhancements );
969 if ( myRasterRenderer )
987 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) ) )
991 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) ) )
1026 if ( !( mDataProvider &&
1027 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded != extent &&
1036 if ( ( singleBandRenderer = dynamic_cast<QgsSingleBandGrayRenderer *>( rasterRenderer ) ) )
1040 else if ( ( multiBandRenderer = dynamic_cast<QgsMultiBandColorRenderer *>( rasterRenderer ) ) )
1044 else if ( ( sbpcr = dynamic_cast<QgsSingleBandPseudoColorRenderer *>( rasterRenderer ) ) )
1046 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1049 computeMinMax( sbpcr->
band(),
1059 if ( colorRampShader )
1072 if ( colorRampShader )
1087 mLastRectangleUsedByRefreshContrastEnhancementIfNeeded =
extent;
1097 if ( singleBandRenderer )
1099 else if ( multiBandRenderer )
1128 QString defaultLimits;
1131 if ( dynamic_cast<QgsSingleBandGrayRenderer *>(
renderer() ) )
1133 key = QStringLiteral(
"singleBand" );
1139 else if ( dynamic_cast<QgsMultiBandColorRenderer *>(
renderer() ) )
1143 key = QStringLiteral(
"multiBandSingleByte" );
1151 key = QStringLiteral(
"multiBandMultiByte" );
1159 if ( key.isEmpty() )
1161 QgsDebugMsg(
"No default contrast enhancement for this drawing style" );
1168 QString myAlgorithmString = mySettings.
value(
"/Raster/defaultContrastEnhancementAlgorithm/" + key, defaultAlg ).toString();
1173 QString myLimitsString = mySettings.
value(
"/Raster/defaultContrastEnhancementLimits/" + key, defaultLimits ).toString();
1195 if ( mDataProvider )
1206 if ( mDataProvider )
1208 QgsDebugMsgLevel(
"About to mDataProvider->setSubLayerVisibility(name, vis).", 4 );
1227 mPipe.
set( renderer );
1250 QImage myQImage( size, format );
1252 myQImage.setColor( 0, bgColor.rgba() );
1257 double myMapUnitsPerPixel;
1261 if ( myExtent.
width() / myExtent.
height() >=
static_cast< double >( myQImage.width() ) / myQImage.height() )
1263 myMapUnitsPerPixel = myExtent.
width() / myQImage.width();
1264 myY = ( myQImage.height() - myExtent.
height() / myMapUnitsPerPixel ) / 2;
1268 myMapUnitsPerPixel = myExtent.
height() / myQImage.height();
1269 myX = ( myQImage.width() - myExtent.
width() / myMapUnitsPerPixel ) / 2;
1272 double myPixelWidth = myExtent.
width() / myMapUnitsPerPixel;
1273 double myPixelHeight = myExtent.
height() / myMapUnitsPerPixel;
1277 myRasterViewPort->
mWidth = myQImage.width();
1278 myRasterViewPort->
mHeight = myQImage.height();
1288 QPainter *myQPainter =
new QPainter( &myQImage );
1289 draw( myQPainter, myRasterViewPort, myMapToPixel );
1290 delete myRasterViewPort;
1291 delete myMapToPixel;
1310 Q_UNUSED( errorMessage );
1311 QDomElement rasterRendererElem;
1313 QDomElement layerElement = layer_node.toElement();
1320 QDomNode pipeNode = layer_node.firstChildElement( QStringLiteral(
"pipe" ) );
1321 if ( pipeNode.isNull() )
1323 pipeNode = layer_node;
1327 if ( !layer_node.firstChildElement( QStringLiteral(
"rasterproperties" ) ).isNull() )
1330 QDomNode layerNodeCopy = layer_node.cloneNode();
1331 QDomDocument doc = layerNodeCopy.ownerDocument();
1332 QDomElement rasterPropertiesElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterproperties" ) );
1335 rasterRendererElem = layerNodeCopy.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1340 rasterRendererElem = pipeNode.firstChildElement( QStringLiteral(
"rasterrenderer" ) );
1343 if ( !rasterRendererElem.isNull() )
1345 QString rendererType = rasterRendererElem.attribute( QStringLiteral(
"type" ) );
1350 mPipe.
set( renderer );
1356 mPipe.
set( brightnessFilter );
1359 QDomElement brightnessElem = pipeNode.firstChildElement( QStringLiteral(
"brightnesscontrast" ) );
1360 if ( !brightnessElem.isNull() )
1362 brightnessFilter->
readXml( brightnessElem );
1367 mPipe.
set( hueSaturationFilter );
1370 QDomElement hueSaturationElem = pipeNode.firstChildElement( QStringLiteral(
"huesaturation" ) );
1371 if ( !hueSaturationElem.isNull() )
1373 hueSaturationFilter->
readXml( hueSaturationElem );
1378 mPipe.
set( resampleFilter );
1381 QDomElement resampleElem = pipeNode.firstChildElement( QStringLiteral(
"rasterresampler" ) );
1382 if ( !resampleElem.isNull() )
1384 resampleFilter->
readXml( resampleElem );
1388 QDomNode blendModeNode = layer_node.namedItem( QStringLiteral(
"blendMode" ) );
1389 if ( !blendModeNode.isNull() )
1391 QDomElement e = blendModeNode.toElement();
1417 QDomNode pkeyNode = layer_node.namedItem( QStringLiteral(
"provider" ) );
1419 if ( pkeyNode.isNull() )
1421 mProviderKey = QStringLiteral(
"gdal" );
1425 QDomElement pkeyElt = pkeyNode.toElement();
1426 mProviderKey = pkeyElt.text();
1427 if ( mProviderKey.isEmpty() )
1429 mProviderKey = QStringLiteral(
"gdal" );
1439 QDomNode rpNode = layer_node.namedItem( QStringLiteral(
"rasterproperties" ) );
1441 if ( mProviderKey == QLatin1String(
"wms" ) )
1445 if ( !
mDataSource.contains( QLatin1String(
"crs=" ) ) && !
mDataSource.contains( QLatin1String(
"format=" ) ) )
1450 QDomElement layerElement = rpNode.firstChildElement( QStringLiteral(
"wmsSublayer" ) );
1451 while ( !layerElement.isNull() )
1456 uri.
setParam( QStringLiteral(
"layers" ), layerElement.namedItem( QStringLiteral(
"name" ) ).toElement().text() );
1459 uri.
setParam( QStringLiteral(
"styles" ), layerElement.namedItem( QStringLiteral(
"style" ) ).toElement().text() );
1461 layerElement = layerElement.nextSiblingElement( QStringLiteral(
"wmsSublayer" ) );
1465 QDomNode formatNode = rpNode.namedItem( QStringLiteral(
"wmsFormat" ) );
1466 uri.
setParam( QStringLiteral(
"format" ), rpNode.namedItem( QStringLiteral(
"wmsFormat" ) ).toElement().text() );
1470 uri.
setParam( QStringLiteral(
"crs" ),
crs().authid() );
1477 if ( !
mValid )
return false;
1483 if ( res && mProviderKey == QLatin1String(
"wms" ) && ( !
renderer() ||
renderer()->
type() != QLatin1String(
"singlebandcolordata" ) ) )
1494 QDomNode stampNode = layer_node.namedItem(
"timestamp" );
1495 if ( !stampNode.isNull() )
1497 QDateTime stamp = QDateTime::fromString( stampNode.toElement().text(), Qt::ISODate );
1499 if ( stamp < mDataProvider->dataTimestamp() )
1502 closeDataProvider();
1505 if ( !
mValid )
return false;
1511 QDomElement noDataElement = layer_node.firstChildElement( QStringLiteral(
"noData" ) );
1513 QDomNodeList noDataBandList = noDataElement.elementsByTagName( QStringLiteral(
"noDataList" ) );
1515 for (
int i = 0; i < noDataBandList.size(); ++i )
1517 QDomElement bandElement = noDataBandList.at( i ).toElement();
1519 int bandNo = bandElement.attribute( QStringLiteral(
"bandNo" ) ).toInt( &ok );
1521 if ( ok && ( bandNo > 0 ) && ( bandNo <= mDataProvider->
bandCount() ) )
1523 mDataProvider->
setUseSourceNoDataValue( bandNo, bandElement.attribute( QStringLiteral(
"useSrcNoData" ) ).toInt() );
1526 QDomNodeList rangeList = bandElement.elementsByTagName( QStringLiteral(
"noDataRange" ) );
1528 myNoDataRangeList.reserve( rangeList.size() );
1529 for (
int j = 0; j < rangeList.size(); ++j )
1531 QDomElement rangeElement = rangeList.at( j ).toElement();
1532 QgsRasterRange myNoDataRange( rangeElement.attribute( QStringLiteral(
"min" ) ).toDouble(),
1533 rangeElement.attribute( QStringLiteral(
"max" ) ).toDouble() );
1534 QgsDebugMsgLevel( QString(
"min = %1 %2" ).arg( rangeElement.attribute(
"min" ) ).arg( myNoDataRange.min() ), 4 );
1535 myNoDataRangeList << myNoDataRange;
1554 Q_UNUSED( errorMessage );
1556 QDomElement layerElement = layer_node.toElement();
1561 QDomElement pipeElement = document.createElement( QStringLiteral(
"pipe" ) );
1563 for (
int i = 1; i < mPipe.
size(); i++ )
1566 if ( !interface )
continue;
1567 interface->writeXml( document, pipeElement );
1570 layer_node.appendChild( pipeElement );
1573 QDomElement blendModeElement = document.createElement( QStringLiteral(
"blendMode" ) );
1575 blendModeElement.appendChild( blendModeText );
1576 layer_node.appendChild( blendModeElement );
1592 QDomDocument &document,
1597 QDomElement mapLayerNode = layer_node.toElement();
1599 if ( mapLayerNode.isNull() ||
"maplayer" != mapLayerNode.nodeName() )
1605 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"raster" ) );
1609 QDomElement provider = document.createElement( QStringLiteral(
"provider" ) );
1610 QDomText providerText = document.createTextNode( mProviderKey );
1611 provider.appendChild( providerText );
1612 layer_node.appendChild( provider );
1615 QDomElement noData = document.createElement( QStringLiteral(
"noData" ) );
1617 for (
int bandNo = 1; bandNo <= mDataProvider->
bandCount(); bandNo++ )
1619 QDomElement noDataRangeList = document.createElement( QStringLiteral(
"noDataList" ) );
1620 noDataRangeList.setAttribute( QStringLiteral(
"bandNo" ), bandNo );
1621 noDataRangeList.setAttribute( QStringLiteral(
"useSrcNoData" ), mDataProvider->
useSourceNoDataValue( bandNo ) );
1625 QDomElement noDataRange = document.createElement( QStringLiteral(
"noDataRange" ) );
1629 noDataRangeList.appendChild( noDataRange );
1632 noData.appendChild( noDataRangeList );
1635 if ( noData.hasChildNodes() )
1637 layer_node.appendChild( noData );
1644 return writeSymbology( layer_node, document, errorMsg, context );
1649 if ( !mDataProvider )
return 0;
1650 return mDataProvider->
xSize();
1655 if ( !mDataProvider )
return 0;
1656 return mDataProvider->
ySize();
1664 bool QgsRasterLayer::update()
1671 closeDataProvider();
QgsDataProvider * classFactoryFunction_t(const QString *)
int width() const
Accessor that returns the width of the (unclipped) raster.
QgsRasterMinMaxOrigin::Limits limits() const
Return limits.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Write style data common to all layer types.
virtual int bandCount() const =0
Get number of bands.
QgsRasterMinMaxOrigin::Extent extent() const
Return 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)
Set custom colormap.
QgsRasterLayer * clone() const override
Returns a new instance equivalent to this one.
QStringList subLayers() const override
Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS.
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)
Set source nodata value usage.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
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
Get the number of bands in this layer.
This class is a composition of two QSettings instances:
QgsHueSaturationFilter * hueSaturationFilter() const
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
Get current status error.
QgsRasterRenderer * renderer() const
void setRenderer(QgsRasterRenderer *renderer)
Set raster renderer. Takes ownership of the renderer object.
virtual QgsError error() const
Get 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. In a world file, this is normally the first row (without the sign)
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context)
Read style data common to all layer types.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
QgsRasterPipe * pipe()
Get raster pipe.
bool writeXml(QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context) const override
Write layer specific state to project file Dom node.
A class to represent a 2D point.
void setDefaultContrastEnhancement()
Set default contrast enhancement.
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
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource)
Creates a new instance of a provider.
virtual int ySize() const
int mWidth
Width, number of columns to be rendered.
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. In a world file, this is normally the first row (without the sign)
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)
Return 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.
Resample filter pipe for rasters.
Abstract base class for spatial data provider implementations.
bool writeSymbology(QDomNode &, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const override
Write the symbology for the layer into the docment provided.
const QgsRasterMinMaxOrigin & minMaxOrigin() const
Returns const reference to origin of min/max values.
QgsRasterRenderer * renderer() const
int height() const
Accessor that 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
Return 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)
Get an 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be return...
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning)
add a message to the instance (and create it if necessary)
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)
Set extent.
QgsCoordinateReferenceSystem mDestCRS
Target coordinate system.
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
QgsBrightnessContrastFilter * brightnessFilter() const
void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
set 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
Return lower bound of cumulative cut method (between 0 and 1).
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)
Set the color ramp type.
Alpha (0=transparent, 255=opaque)
QgsRasterDataProvider * dataProvider() override
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.
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
Set 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)
Set the extent.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Get the data source specification.
double cumulativeCutUpper() const
Return upper bound of cumulative cut method (between 0 and 1).
QString bandName(int bandNoInt) const
Get 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)
Return a string to serialize ContrastEnhancementAlgorithm.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
bool defaultContrastEnhancementSettings(QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, QgsRasterMinMaxOrigin::Limits &myLimits) const
Return default contrast enhancemnt settings for that type of raster.
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
Return 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) ...
void rendererChanged()
Signal emitted when renderer is changed.
void setAlphaBand(int band)
bool mValid
Indicates if the layer is valid and can be drawn.
void setName(const QString &name)
Set the display name of the layer.
void setDataProvider(const QString &provider)
[ data provider interface ] Set the data provider
Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]...
Base class for processing filters like renderers, reprojector, resampler etc.
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS
Default enhancement limits for single band raster.
static QString limitsString(Limits limits)
Return a string to serialize Limits.
void setSubLayerVisibility(const QString &name, bool vis) override
Set the visibility of the given sublayer name.
bool shade(double value, int *returnRedValue, int *returnGreenValue, int *returnBlueValue, int *returnAlphaValue) override
Generates and new RGB value based on one input value.
virtual QString htmlMetadata()=0
Get metadata in a format suitable for feeding directly into a subset of the GUI raster properties "Me...
static ContrastEnhancementAlgorithm contrastEnhancementAlgorithmFromString(const QString &contrastEnhancementString)
Deserialize ContrastEnhancementAlgorithm.
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)
Set 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 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)
Get band statistics.
QList< QPair< QString, QColor > > QgsLegendColorList
QImage previewAsImage(QSize size, const QColor &bgColor=Qt::white, QImage::Format format=QImage::Format_ARGB32_Premultiplied)
Draws a preview of the rasterlayer into a QImage.
void setContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
ContrastEnhancementAlgorithm
This enumerator describes the types of contrast enhancement algorithms that can be used...
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
Contains information about the context of a rendering operation.
QString name() const
Returns the display name of the layer.
void setClassificationMin(double min)
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context) const override
Write the style for the layer into the docment provided.
static QgsMapLayerLegend * defaultRasterLegend(QgsRasterLayer *rl)
Create new legend implementation for raster layer.
const QgsContrastEnhancement * redContrastEnhancement() const
const QgsContrastEnhancement * greenContrastEnhancement() const
void classifyColorRamp(const int classes=0, const int band=-1, const QgsRectangle &extent=QgsRectangle(), QgsRasterInterface *input=nullptr)
Classify color ramp shader.
QgsRasterResampleFilter * resampleFilter() const
Set 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.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
Whole raster is used to compute statistics.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
virtual void reloadData()
Reloads the data from the source.
QByteArray encodedUri() const
return 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.
double minimumValue
The minimum cell value in the raster band.
Renderer for multiband images with the color components.
void dataChanged()
Data of layer changed.
void appendError(const QgsErrorMessage &error)
Add error message.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Get list of user no data value ranges.
Base class for utility classes that encapsulate information necessary for rendering of map layers...
bool readXml(const QDomNode &layer_node, const QgsReadWriteContext &context) override
Reads layer specific state from project file Dom node.
Interpolates the color between two class breaks linearly.
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
void readXml(const QDomElement &filterElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
bool readSymbology(const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context) override
Read the symbology for the current layer from the Dom node supplied.
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
Get 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
Get symbology items if provided by renderer.
bool readStyle(const QDomNode &node, QString &errorMessage, const QgsReadWriteContext &context) override
Read the style information for the current layer from the Dom node supplied.
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
Return factor f so that the min/max range is [ mean - f * stddev , mean + f * stddev ]...
virtual int xSize() const
Get 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)
Set 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.
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.