32 #include "gdalwarper.h"
43 #include <QApplication>
45 #include <QDomElement>
50 #include <QFontMetrics>
56 #include <QMessageBox>
81 #define TINY_VALUE std::numeric_limits<double>::epsilon() * 20
86 QString
const & baseName,
87 bool loadDefaultStyleFlag )
90 , QSTRING_NOT_SET(
"Not Set" )
91 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
92 , mStandardDeviations( 0 )
94 , mWidth( std::numeric_limits<int>::
max() )
95 , mHeight( std::numeric_limits<int>::
max() )
96 , mInvertColor( false )
102 setDataProvider(
"gdal", QStringList(), QStringList(), QString(), QString(), loadDefaultStyleFlag );
104 if (
mValid && loadDefaultStyleFlag )
106 bool defaultLoadedFlag =
false;
125 QString
const & rasterLayerPath,
126 QString
const & baseName,
127 QString
const & providerKey,
128 QStringList
const & layers,
129 QStringList
const & styles,
130 QString
const & format,
131 QString
const & crs )
132 :
QgsMapLayer( RasterLayer, baseName, rasterLayerPath )
133 , mStandardDeviations( 0 )
136 , mWidth( std::numeric_limits<int>::
max() )
137 , mHeight( std::numeric_limits<int>::
max() )
138 , mInvertColor( false )
140 , mProviderKey( providerKey )
146 QgsDebugMsg(
"(8 arguments) starting. with layer list of " +
147 layers.join(
", " ) +
" and style list of " + styles.join(
", " ) +
" and format of " +
148 format +
" and CRS of " +
crs );
153 bool loadDefaultStyleFlag = false ;
154 setDataProvider( providerKey, layers, styles, format, crs, loadDefaultStyleFlag );
201 QgsDebugMsg(
"Could not load gdal provider library" );
207 QgsDebugMsg(
"Could not resolve buildSupportedRasterFileFilter in gdal provider library" );
211 pBuild( theFileFiltersString );
224 QgsDebugMsg(
"Could not load gdal provider library" );
230 QgsDebugMsg(
"Could not resolve isValidRasterFileName in gdal provider library" );
234 bool myIsValid = pValid( theFileNameQString, retErrMsg );
250 QFileInfo fi( name );
253 if ( !fi.exists() )
return t;
255 t = fi.lastModified();
285 return QString(
"" );
291 for (
int myIterator = 0; myIterator <
mRasterStatsList.size(); ++myIterator )
295 QgsDebugMsg(
"myRasterBandStats.bandName: " + myRasterBandStats.
bandName +
" :: theBandName: "
298 if ( myRasterBandStats.
bandName == theBandName )
301 " was found in bandNumber " + theBandName );
306 QgsDebugMsg(
"********** no band was found in bandNumber " + theBandName );
332 QgsDebugMsg(
"theBandNo = " + QString::number( theBandNo ) );
338 return myNullReturnStats;
345 return myNullReturnStats;
351 return myNullReturnStats;
358 return myNullReturnStats;
367 return myRasterBandStats;
371 QgsDebugMsg(
"adding stats to stats collection at position " + QString::number( theBandNo - 1 ) );
375 QgsDebugMsg(
"Stats collection completed returning" );
376 return myRasterBandStats;
383 qApp->processEvents();
391 if ( myRasterBandStats.
bandName == theBandName )
393 return myRasterBandStats;
402 QString
const & theResamplingMethod,
bool theTryInternalFlag )
418 return QString(
"PseudoColorShader" );
421 return QString(
"FreakOutShader" );
424 return QString(
"ColorRampShader" );
427 return QString(
"UserDefinedShader" );
433 return QString(
"UndefinedShader" );
442 if ( 0 == theMinMax ) {
return; }
444 if ( 0 < theBand && theBand <= (
int )
bandCount() )
464 theMin = theMinMax[0];
465 theMax = theMinMax[1];
474 if ( 0 == theMinMax ) {
return; }
480 if ( myScanData == NULL )
485 if ( 0 < theBand && theBand <= (
int )
bandCount() )
492 double myValue = 0.0;
502 myMin = qMin( myMin, myValue );
503 myMax = qMax( myMax, myValue );
506 theMinMax[0] = myMin;
507 theMinMax[1] = myMax;
524 theMin = theMinMax[0];
525 theMax = theMinMax[1];
534 if ( 0 < theBand && theBand <=
bandCount() )
547 return QString(
"NoEnhancement" );
550 return QString(
"StretchToMinimumMaximum" );
553 return QString(
"StretchAndClipToMinimumMaximum" );
556 return QString(
"ClipToMinimumMaximum" );
559 return QString(
"UserDefined" );
563 return QString(
"NoEnhancement" );
573 if ( theOther.
type() < 0 )
636 QgsDebugMsg(
"coordinateTransform set -> project extents." );
638 rendererContext.
extent() );
645 myProjectedViewExtent = rendererContext.
extent();
649 QPainter* theQPainter = rendererContext.
painter();
659 if ( myRasterExtent.
isEmpty() )
661 QgsDebugMsg(
"draw request outside view extent." );
680 myRasterViewPort->mDrawnExtent = myRasterExtent;
683 myRasterViewPort->mSrcCRS =
crs();
704 myRasterViewPort->topLeftPoint.
setX( floor( myRasterViewPort->topLeftPoint.x() ) );
705 myRasterViewPort->topLeftPoint.setY( floor( myRasterViewPort->topLeftPoint.y() ) );
706 myRasterViewPort->bottomRightPoint.setX( ceil( myRasterViewPort->bottomRightPoint.x() ) );
707 myRasterViewPort->bottomRightPoint.setY( ceil( myRasterViewPort->bottomRightPoint.y() ) );
711 myRasterViewPort->bottomRightPoint.y() ),
713 myRasterViewPort->topLeftPoint.y() )
718 myRasterViewPort->drawableAreaXDim =
static_cast<int>( qAbs(( myRasterExtent.
width() / theQgsMapToPixel.
mapUnitsPerPixel() ) ) );
719 myRasterViewPort->drawableAreaYDim =
static_cast<int>( qAbs(( myRasterExtent.
height() / theQgsMapToPixel.
mapUnitsPerPixel() ) ) );
725 if ( 2 >= myRasterViewPort->clippedWidth && 2 >= myRasterViewPort->clippedHeight )
727 myRasterViewPort->drawableAreaXDim = myRasterViewPort->clippedWidth;
728 myRasterViewPort->drawableAreaYDim = myRasterViewPort->clippedHeight;
740 QgsDebugMsgLevel( QString(
"topLeftPoint.x() = %1" ).arg( myRasterViewPort->topLeftPoint.x() ), 3 );
741 QgsDebugMsgLevel( QString(
"bottomRightPoint.x() = %1" ).arg( myRasterViewPort->bottomRightPoint.x() ), 3 );
742 QgsDebugMsgLevel( QString(
"topLeftPoint.y() = %1" ).arg( myRasterViewPort->topLeftPoint.y() ), 3 );
743 QgsDebugMsgLevel( QString(
"bottomRightPoint.y() = %1" ).arg( myRasterViewPort->bottomRightPoint.y() ), 3 );
745 QgsDebugMsgLevel( QString(
"drawableAreaXDim = %1" ).arg( myRasterViewPort->drawableAreaXDim ), 3 );
746 QgsDebugMsgLevel( QString(
"drawableAreaYDim = %1" ).arg( myRasterViewPort->drawableAreaYDim ), 3 );
761 draw( theQPainter, myRasterViewPort, &theQgsMapToPixel );
763 delete myRasterViewPort;
822 QgsDebugMsg(
"PalettedColor drawing type detected..." );
837 QgsDebugMsg(
"PalettedSingleBandGray drawing type detected..." );
841 theQgsMapToPixel, myBandNo );
857 theQgsMapToPixel, myBandNo );
863 theQgsMapToPixel, 1 );
867 QgsDebugMsg(
"MultiBandSingleBandGray drawing type detected..." );
929 QgsDebugMsg( QString(
"raster draw time (ms): %1" ).arg( time.elapsed() ) );
937 return QString(
"SingleBandGray" );
940 return QString(
"SingleBandPseudoColor" );
943 return QString(
"PalettedColor" );
946 return QString(
"PalettedSingleBandGray" );
949 return QString(
"PalettedSingleBandPseudoColor" );
952 return QString(
"PalettedMultiBandColor" );
955 return QString(
"MultiBandSingleBandGray" );
958 return QString(
"MultiBandSingleBandPseudoColor" );
961 return QString(
"MultiBandColor" );
964 return QString(
"SingleBandColorDataStyle" );
970 return QString(
"UndefinedDrawingStyle" );
981 if ( theOther.
type() < 0 )
1088 QPixmap myLegendQPixmap;
1089 QPainter myQPainter;
1095 myLegendQPixmap = QPixmap( 3, 1 );
1096 myQPainter.begin( &myLegendQPixmap );
1098 myQPainter.setPen( QPen( QColor( 255, 0, 0 ), 0 ) );
1099 myQPainter.drawPoint( 0, 0 );
1101 myQPainter.setPen( QPen( QColor( 0, 255, 0 ), 0 ) );
1102 myQPainter.drawPoint( 1, 0 );
1104 myQPainter.setPen( QPen( QColor( 0, 0, 255 ), 0 ) );
1105 myQPainter.drawPoint( 2, 0 );
1123 myLegendQPixmap = QPixmap( 100, 1 );
1124 myQPainter.begin( &myLegendQPixmap );
1126 for (
double my = 0; my < 255; my += 2.55 )
1131 int myGray = static_cast <
int >( my );
1132 myQPainter.setPen( QPen( QColor( myGray, myGray, myGray ), 0 ) );
1137 int myGray = 255 - static_cast <
int >( my );
1138 myQPainter.setPen( QPen( QColor( myGray, myGray, myGray ), 0 ) );
1140 myQPainter.drawPoint( myPos++, 0 );
1148 double myRangeSize = 90;
1149 double myBreakSize = myRangeSize / 3;
1150 double myClassBreakMin1 = 0;
1151 double myClassBreakMax1 = myClassBreakMin1 + myBreakSize;
1152 double myClassBreakMin2 = myClassBreakMax1;
1153 double myClassBreakMax2 = myClassBreakMin2 + myBreakSize;
1154 double myClassBreakMin3 = myClassBreakMax2;
1159 myLegendQPixmap = QPixmap( 100, 1 );
1160 myQPainter.begin( &myLegendQPixmap );
1162 for (
double my = 0; my < myRangeSize; my += myRangeSize / 100.0 )
1168 if (( my >= myClassBreakMin1 ) && ( my < myClassBreakMax1 ) )
1172 int myGreen = static_cast <
int >((( 255 / myRangeSize ) * ( my - myClassBreakMin1 ) ) * 3 );
1176 myRed = 255 - myGreen;
1178 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1181 else if (( my >= myClassBreakMin2 ) && ( my < myClassBreakMax2 ) )
1183 int myRed = static_cast <
int >((( 255 / myRangeSize ) * (( my - myClassBreakMin2 ) / 1 ) ) * 3 );
1184 int myBlue = static_cast <
int >( 255 - ((( 255 / myRangeSize ) * (( my - myClassBreakMin2 ) / 1 ) ) * 3 ) );
1191 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1198 int myGreen = static_cast <
int >( 255 - ((( 255 / myRangeSize ) * (( my - myClassBreakMin3 ) / 1 ) * 3 ) ) );
1203 myGreen = 255 - myGreen;
1205 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1211 if (( my >= myClassBreakMin1 ) && ( my < myClassBreakMax1 ) )
1215 int myGreen = static_cast <
int >((( 255 / myRangeSize ) * (( my - myClassBreakMin1 ) / 1 ) * 3 ) );
1219 myRed = 255 - myGreen;
1221 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1224 else if (( my >= myClassBreakMin2 ) && ( my < myClassBreakMax2 ) )
1226 int myRed = static_cast <
int >( 255 - ((( 255 / myRangeSize ) * (( my - myClassBreakMin2 ) / 1 ) ) * 3 ) );
1227 int myBlue = static_cast <
int >((( 255 / myRangeSize ) * (( my - myClassBreakMin2 ) / 1 ) ) * 3 );
1234 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1241 int myGreen = static_cast <
int >( 255 - ((( 255 / myRangeSize ) * ( my - myClassBreakMin3 ) ) * 3 ) );
1245 myRed = 255 - myGreen;
1247 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1251 myQPainter.drawPoint( myPos++, 0 );
1261 myLegendQPixmap = QPixmap( 3, 1 );
1262 myQPainter.begin( &myLegendQPixmap );
1264 myQPainter.setPen( QPen( QColor( 224, 103, 103 ), 0 ) );
1265 myQPainter.drawPoint( 0, 0 );
1267 myQPainter.setPen( QPen( QColor( 132, 224, 127 ), 0 ) );
1268 myQPainter.drawPoint( 1, 0 );
1270 myQPainter.setPen( QPen( QColor( 127, 160, 224 ), 0 ) );
1271 myQPainter.drawPoint( 2, 0 );
1279 if ( theWithNameFlag )
1281 QFont myQFont(
"arial", 10, QFont::Normal );
1282 QFontMetrics myQFontMetrics( myQFont );
1284 int myHeight = ( myQFontMetrics.height() + 10 > 35 ) ? myQFontMetrics.height() + 10 : 35;
1293 if ( myLegendQPixmap.width() == 3 )
1296 myQWMatrix.scale( 60, myHeight );
1301 myQWMatrix.scale( 1.8, myHeight );
1304 QPixmap myQPixmap2 = myLegendQPixmap.transformed( myQWMatrix );
1305 QPainter myQPainter( &myQPixmap2 );
1309 QPixmap myPyramidPixmap( myThemePath +
"/mIconPyramid.png" );
1310 QPixmap myNoPyramidPixmap( myThemePath +
"/mIconNoPyramid.png" );
1317 myQPainter.drawPixmap( 0, myHeight - myPyramidPixmap.height(), myPyramidPixmap );
1321 myQPainter.drawPixmap( 0, myHeight - myNoPyramidPixmap.height(), myNoPyramidPixmap );
1328 myQPainter.setPen( Qt::white );
1332 myQPainter.setPen( Qt::black );
1334 myQPainter.setFont( myQFont );
1335 myQPainter.drawText( 25, myHeight - 10,
name() );
1339 myLegendQPixmap = myQPixmap2;
1344 return myLegendQPixmap;
1355 QFont myQFont(
"arial", 10, QFont::Normal );
1356 QFontMetrics myQFontMetrics( myQFont );
1358 int myFontHeight = ( myQFontMetrics.height() );
1359 const int myerLabelSpacing = 5;
1360 int myImageHeight = (( myFontHeight + ( myerLabelSpacing * 2 ) ) * theLabelCount );
1364 const int myColorBarWidth = 10;
1369 QPixmap myLegendQPixmap;
1370 QPainter myQPainter;
1377 myLegendQPixmap = QPixmap( 1, myImageHeight );
1378 const double myIncrement =
static_cast<double>( myImageHeight ) / 255.0;
1379 myQPainter.begin( &myLegendQPixmap );
1381 for (
double my = 0; my < 255; my += myIncrement )
1386 int myGray = static_cast <
int >( my );
1387 myQPainter.setPen( QPen( QColor( myGray, myGray, myGray ), 0 ) );
1392 int myGray = 255 - static_cast <
int >( my );
1393 myQPainter.setPen( QPen( QColor( myGray, myGray, myGray ), 0 ) );
1395 myQPainter.drawPoint( 0, myPos++ );
1403 double myRangeSize = 90;
1404 double myBreakSize = myRangeSize / 3;
1405 double myClassBreakMin1 = 0;
1406 double myClassBreakMax1 = myClassBreakMin1 + myBreakSize;
1407 double myClassBreakMin2 = myClassBreakMax1;
1408 double myClassBreakMax2 = myClassBreakMin2 + myBreakSize;
1409 double myClassBreakMin3 = myClassBreakMax2;
1414 myLegendQPixmap = QPixmap( 1, myImageHeight );
1415 const double myIncrement = myImageHeight / myRangeSize;
1416 myQPainter.begin( &myLegendQPixmap );
1418 for (
double my = 0; my < 255; my += myIncrement )
1419 for (
double my = 0; my < myRangeSize; my += myIncrement )
1425 if (( my >= myClassBreakMin1 ) && ( my < myClassBreakMax1 ) )
1429 int myGreen = static_cast <
int >((( 255 / myRangeSize ) * ( my - myClassBreakMin1 ) ) * 3 );
1433 myRed = 255 - myGreen;
1435 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1438 else if (( my >= myClassBreakMin2 ) && ( my < myClassBreakMax2 ) )
1440 int myRed = static_cast <
int >((( 255 / myRangeSize ) * (( my - myClassBreakMin2 ) / 1 ) ) * 3 );
1441 int myBlue = static_cast <
int >( 255 - ((( 255 / myRangeSize ) * (( my - myClassBreakMin2 ) / 1 ) ) * 3 ) );
1448 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1455 int myGreen = static_cast <
int >( 255 - ((( 255 / myRangeSize ) * (( my - myClassBreakMin3 ) / 1 ) * 3 ) ) );
1460 myGreen = 255 - myGreen;
1462 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1468 if (( my >= myClassBreakMin1 ) && ( my < myClassBreakMax1 ) )
1472 int myGreen = static_cast <
int >((( 255 / myRangeSize ) * (( my - myClassBreakMin1 ) / 1 ) * 3 ) );
1476 myRed = 255 - myGreen;
1478 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1481 else if (( my >= myClassBreakMin2 ) && ( my < myClassBreakMax2 ) )
1483 int myRed = static_cast <
int >( 255 - ((( 255 / myRangeSize ) * (( my - myClassBreakMin2 ) / 1 ) ) * 3 ) );
1484 int myBlue = static_cast <
int >((( 255 / myRangeSize ) * (( my - myClassBreakMin2 ) / 1 ) ) * 3 );
1491 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1498 int myGreen = static_cast <
int >( 255 - ((( 255 / myRangeSize ) * ( my - myClassBreakMin3 ) ) * 3 ) );
1502 myRed = 255 - myGreen;
1504 myQPainter.setPen( QPen( QColor( myRed, myGreen, myBlue ), 0 ) );
1508 myQPainter.drawPoint( 0, myPos++ );
1518 myLegendQPixmap = QPixmap( 1, 3 );
1519 myQPainter.begin( &myLegendQPixmap );
1521 myQPainter.setPen( QPen( QColor( 224, 103, 103 ), 0 ) );
1522 myQPainter.drawPoint( 0, 0 );
1524 myQPainter.setPen( QPen( QColor( 132, 224, 127 ), 0 ) );
1525 myQPainter.drawPoint( 0, 1 );
1527 myQPainter.setPen( QPen( QColor( 127, 160, 224 ), 0 ) );
1528 myQPainter.drawPoint( 0, 2 );
1543 if ( myLegendQPixmap.height() == 3 )
1545 myQWMatrix.scale( myColorBarWidth, 2 );
1549 myQWMatrix.scale( myColorBarWidth, 2 );
1552 QPixmap myQPixmap2 = myLegendQPixmap.transformed( myQWMatrix );
1553 QPainter myQPainter2( &myQPixmap2 );
1559 myQPainter2.setPen( Qt::white );
1563 myQPainter2.setPen( Qt::black );
1565 myQPainter2.setFont( myQFont );
1566 myQPainter2.drawText( 25, myImageHeight - 10,
name() );
1570 myLegendQPixmap = myQPixmap2;
1574 return myLegendQPixmap;
1584 if ( 0 < theBand && theBand <=
bandCount() )
1598 if ( theBand != tr(
"Not Set" ) )
1609 QString myMetadata ;
1610 myMetadata +=
"<p class=\"glossy\">" + tr(
"Driver:" ) +
"</p>\n";
1611 myMetadata +=
"<p>";
1613 myMetadata +=
"</p>\n";
1621 myMetadata +=
"<p class=\"glossy\">";
1622 myMetadata += tr(
"No Data Value" );
1623 myMetadata +=
"</p>\n";
1624 myMetadata +=
"<p>";
1631 myMetadata +=
"*" + tr(
"NoDataValue not set" ) +
"*";
1633 myMetadata +=
"</p>\n";
1635 myMetadata +=
"</p>\n";
1636 myMetadata +=
"<p class=\"glossy\">";
1637 myMetadata += tr(
"Data Type:" );
1638 myMetadata +=
"</p>\n";
1639 myMetadata +=
"<p>";
1644 myMetadata += tr(
"GDT_Byte - Eight bit unsigned integer" );
1647 myMetadata += tr(
"GDT_UInt16 - Sixteen bit unsigned integer " );
1650 myMetadata += tr(
"GDT_Int16 - Sixteen bit signed integer " );
1653 myMetadata += tr(
"GDT_UInt32 - Thirty two bit unsigned integer " );
1656 myMetadata += tr(
"GDT_Int32 - Thirty two bit signed integer " );
1659 myMetadata += tr(
"GDT_Float32 - Thirty two bit floating point " );
1662 myMetadata += tr(
"GDT_Float64 - Sixty four bit floating point " );
1665 myMetadata += tr(
"GDT_CInt16 - Complex Int16 " );
1668 myMetadata += tr(
"GDT_CInt32 - Complex Int32 " );
1671 myMetadata += tr(
"GDT_CFloat32 - Complex Float32 " );
1674 myMetadata += tr(
"GDT_CFloat64 - Complex Float64 " );
1677 myMetadata += tr(
"Could not determine raster data type." );
1679 myMetadata +=
"</p>\n";
1681 myMetadata +=
"<p class=\"glossy\">";
1682 myMetadata += tr(
"Pyramid overviews:" );
1683 myMetadata +=
"</p>\n";
1684 myMetadata +=
"<p>";
1686 myMetadata +=
"<p class=\"glossy\">";
1687 myMetadata += tr(
"Layer Spatial Reference System: " );
1688 myMetadata +=
"</p>\n";
1689 myMetadata +=
"<p>";
1691 myMetadata +=
"</p>\n";
1693 myMetadata +=
"<p class=\"glossy\">";
1694 myMetadata += tr(
"Layer Extent (layer original source projection): " );
1695 myMetadata +=
"</p>\n";
1696 myMetadata +=
"<p>";
1698 myMetadata +=
"</p>\n";
1703 myMetadata +=
"<tr><td class=\"glossy\">";
1704 myMetadata += tr(
"Project Spatial Reference System: " );
1705 myMetadata +=
"</p>\n";
1706 myMetadata +=
"<p>";
1707 myMetadata += mCoordinateTransform->destCRS().toProj4();
1708 myMetadata +=
"</p>\n";
1715 for (
int myIteratorInt = 1; myIteratorInt <= myBandCountInt; ++myIteratorInt )
1717 QgsDebugMsg(
"Raster properties : checking if band " + QString::number( myIteratorInt ) +
" has stats? " );
1719 myMetadata +=
"<p class=\"glossy\">\n";
1720 myMetadata += tr(
"Band" );
1721 myMetadata +=
"</p>\n";
1722 myMetadata +=
"<p>";
1723 myMetadata +=
bandName( myIteratorInt );
1724 myMetadata +=
"</p>\n";
1726 myMetadata +=
"<p>";
1727 myMetadata += tr(
"Band No" );
1728 myMetadata +=
"</p>\n";
1729 myMetadata +=
"<p>\n";
1730 myMetadata += QString::number( myIteratorInt );
1731 myMetadata +=
"</p>\n";
1738 myMetadata +=
"<p>";
1739 myMetadata += tr(
"No Stats" );
1740 myMetadata +=
"</p>\n";
1741 myMetadata +=
"<p>\n";
1742 myMetadata += tr(
"No stats collected yet" );
1743 myMetadata +=
"</p>\n";
1751 myMetadata +=
"<p>";
1752 myMetadata += tr(
"Min Val" );
1753 myMetadata +=
"</p>\n";
1754 myMetadata +=
"<p>\n";
1755 myMetadata += QString::number( myRasterBandStats.
minimumValue,
'f', 10 );
1756 myMetadata +=
"</p>\n";
1759 myMetadata +=
"<p>";
1760 myMetadata += tr(
"Max Val" );
1761 myMetadata +=
"</p>\n";
1762 myMetadata +=
"<p>\n";
1763 myMetadata += QString::number( myRasterBandStats.
maximumValue,
'f', 10 );
1764 myMetadata +=
"</p>\n";
1767 myMetadata +=
"<p>";
1768 myMetadata += tr(
"Range" );
1769 myMetadata +=
"</p>\n";
1770 myMetadata +=
"<p>\n";
1771 myMetadata += QString::number( myRasterBandStats.
range,
'f', 10 );
1772 myMetadata +=
"</p>\n";
1775 myMetadata +=
"<p>";
1776 myMetadata += tr(
"Mean" );
1777 myMetadata +=
"</p>\n";
1778 myMetadata +=
"<p>\n";
1779 myMetadata += QString::number( myRasterBandStats.
mean,
'f', 10 );
1780 myMetadata +=
"</p>\n";
1783 myMetadata +=
"<p>";
1784 myMetadata += tr(
"Sum of squares" );
1785 myMetadata +=
"</p>\n";
1786 myMetadata +=
"<p>\n";
1787 myMetadata += QString::number( myRasterBandStats.
sumOfSquares,
'f', 10 );
1788 myMetadata +=
"</p>\n";
1791 myMetadata +=
"<p>";
1792 myMetadata += tr(
"Standard Deviation" );
1793 myMetadata +=
"</p>\n";
1794 myMetadata +=
"<p>\n";
1795 myMetadata += QString::number( myRasterBandStats.
stdDev,
'f', 10 );
1796 myMetadata +=
"</p>\n";
1799 myMetadata +=
"<p>";
1800 myMetadata += tr(
"Sum of all cells" );
1801 myMetadata +=
"</p>\n";
1802 myMetadata +=
"<p>\n";
1803 myMetadata += QString::number( myRasterBandStats.
sum,
'f', 10 );
1804 myMetadata +=
"</p>\n";
1807 myMetadata +=
"<p>";
1808 myMetadata += tr(
"Cell Count" );
1809 myMetadata +=
"</p>\n";
1810 myMetadata +=
"<p>\n";
1811 myMetadata += QString::number( myRasterBandStats.
elementCount );
1812 myMetadata +=
"</p>\n";
1826 if ( 0 < theBand && theBand <=
bandCount() )
1863 if ( myColorRampItemList.size() > 0 )
1870 QPixmap myPalettePixmap( mySize, mySize );
1871 QPainter myQPainter( &myPalettePixmap );
1873 QImage myQImage = QImage( mySize, mySize, QImage::Format_RGB32 );
1875 myPalettePixmap.fill();
1877 double myStep = (( double )myColorRampItemList.size() - 1 ) / (
double )( mySize * mySize );
1878 double myValue = 0.0;
1879 for (
int myRow = 0; myRow < mySize; myRow++ )
1881 QRgb* myLineBuffer = ( QRgb* )myQImage.scanLine( myRow );
1882 for (
int myCol = 0; myCol < mySize; myCol++ )
1884 myValue = myStep * ( double )( myCol + myRow * mySize );
1886 myShader.
shade( myValue, &c1, &c2, &c3 );
1887 myLineBuffer[ myCol ] = qRgb( c1, c2, c3 );
1891 myQPainter.drawImage( 0, 0, myQImage );
1892 return myPalettePixmap;
1894 QPixmap myNullPixmap;
1895 return myNullPixmap;
1900 QPixmap myNullPixmap;
1901 return myNullPixmap;
1961 if ( 0 != myRequestValid )
2025 QgsDebugMsg(
"theProviderKey = " + theProviderKey );
2028 QString myLibPath = pReg->
library( theProviderKey );
2031 #ifdef TESTPROVIDERLIB
2032 const char *cOgrLib = (
const char * ) myLibPath;
2035 void *handle = dlopen( cOgrLib, RTLD_LAZY | RTLD_GLOBAL );
2049 QLibrary* myLib =
new QLibrary( myLibPath );
2051 QgsDebugMsg(
"Library name is " + myLib->fileName() );
2052 bool loaded = myLib->load();
2075 QgsDebugMsg(
"Attempting to resolve the classFactory function" );
2078 if ( !classFactory )
2080 QgsLogger::warning(
"QgsRasterLayer::loadProvider: Cannot resolve the classFactory function" );
2083 QgsDebugMsg(
"Getting pointer to a mDataProvider object from the library" );
2092 if ( !myDataProvider )
2094 QgsLogger::warning(
"QgsRasterLayer::loadProvider: Unable to instantiate the data provider plugin" );
2098 return myDataProvider;
2102 QStringList
const & layers,
2103 QStringList
const & styles,
2104 QString
const & format,
2105 QString
const & crs )
2114 QStringList
const & layers,
2115 QStringList
const & styles,
2116 QString
const & format,
2117 QString
const & crs,
2118 bool loadDefaultStyleFlag )
2143 QgsDebugMsg(
"Instantiated the data provider plugin"
2144 + QString(
" with layer list of " ) + layers.join(
", " )
2145 +
" and style list of " + styles.join(
", " )
2146 +
" and format of " + format +
" and CRS of " +
crs );
2212 QList<QgsColorRampShader::ColorRampItem> ct;
2227 QSettings myQSettings;
2302 if ( mGreenBandName.isEmpty() )
2376 this, SLOT(
onProgress(
int,
double, QString ) )
2408 QgsDebugMsg(
"called with [" + QString::number( theShadingAlgorithm ) +
"]" );
2416 switch ( theShadingAlgorithm )
2438 QgsDebugMsg(
"mColorShadingAlgorithm = " + QString::number( theShadingAlgorithm ) );
2443 QgsDebugMsg(
"called with [" + theShaderAlgorithm +
"]" );
2445 if ( theShaderAlgorithm ==
"PseudoColorShader" )
2447 else if ( theShaderAlgorithm ==
"FreakOutShader" )
2449 else if ( theShaderAlgorithm ==
"ColorRampShader" )
2451 else if ( theShaderAlgorithm ==
"UserDefinedShader" )
2462 ( *myIterator ).setContrastEnhancementAlgorithm( theAlgorithm, theGenerateLookupTableFlag );
2470 QgsDebugMsg(
"called with [" + theAlgorithm +
"] and flag=" + QString::number((
int )theGenerateLookupTableFlag ) );
2472 if ( theAlgorithm ==
"NoEnhancement" )
2476 else if ( theAlgorithm ==
"StretchToMinimumMaximum" )
2480 else if ( theAlgorithm ==
"StretchAndClipToMinimumMaximum" )
2484 else if ( theAlgorithm ==
"ClipToMinimumMaximum" )
2488 else if ( theAlgorithm ==
"UserDefined" )
2505 ( *myIterator ).setContrastEnhancementFunction( theFunction );
2518 QgsDebugMsg(
"DrawingStyle = " + theDrawingStyleQString );
2519 if ( theDrawingStyleQString ==
"SingleBandGray" )
2523 else if ( theDrawingStyleQString ==
"SingleBandPseudoColor" )
2527 else if ( theDrawingStyleQString ==
"PalettedColor" )
2531 else if ( theDrawingStyleQString ==
"PalettedSingleBandGray" )
2535 else if ( theDrawingStyleQString ==
"PalettedSingleBandPseudoColor" )
2539 else if ( theDrawingStyleQString ==
"PalettedMultiBandColor" )
2543 else if ( theDrawingStyleQString ==
"MultiBandSingleBandGray" )
2547 else if ( theDrawingStyleQString ==
"MultiBandSingleBandPseudoColor" )
2551 else if ( theDrawingStyleQString ==
"MultiBandColor" )
2555 else if ( theDrawingStyleQString ==
"SingleBandColorDataStyle" )
2583 QgsDebugMsg(
"About to mDataProvider->setLayerOrder(layers)." );
2591 QgsDebugMsg(
"setMaximumValue theValue = " + QString::number( theValue ) );
2592 if ( 0 < theBand && theBand <=
bandCount() )
2600 if ( theBand != tr(
"Not Set" ) )
2672 QgsDebugMsg(
"setMinimumValue theValue = " + QString::number( theValue ) );
2673 if ( 0 < theBand && theBand <=
bandCount() )
2681 if ( theBand != tr(
"Not Set" ) )
2698 ( *myIterator ).statsGathered =
false;
2730 QgsDebugMsg(
"About to mDataProvider->setSubLayerVisibility(name, vis)." );
2766 if ( 0 == theQPixmap ) {
return; }
2768 theQPixmap->fill( );
2772 double myMapUnitsPerPixel;
2776 if ( myExtent.
width() / myExtent.
height() >= theQPixmap->width() / theQPixmap->height() )
2778 myMapUnitsPerPixel = myExtent.
width() / theQPixmap->width();
2779 myY = ( theQPixmap->height() - myExtent.
height() / myMapUnitsPerPixel ) / 2;
2783 myMapUnitsPerPixel = myExtent.
height() / theQPixmap->height();
2784 myX = ( theQPixmap->width() - myExtent.
width() / myMapUnitsPerPixel ) / 2;
2787 double myPixelWidth = myExtent.
width() / myMapUnitsPerPixel;
2788 double myPixelHeight = myExtent.
height() / myMapUnitsPerPixel;
2807 QPainter * myQPainter =
new QPainter( theQPixmap );
2808 draw( myQPainter, myRasterViewPort, myMapToPixel );
2809 delete myRasterViewPort;
2810 delete myMapToPixel;
2818 if ( 0 == thepImage ) {
return; }
2820 thepImage->fill( Qt::white );
2831 QPainter * myQPainter =
new QPainter( thepImage );
2832 draw( myQPainter, myRasterViewPort );
2833 delete myRasterViewPort;
2853 QgsDebugMsg( QString(
"theProgress = %1" ).arg( theProgress ) );
2869 QDomNode mnl = layer_node.namedItem(
"rasterproperties" );
2870 QDomNode snode = mnl.namedItem(
"mDrawingStyle" );
2871 QDomElement myElement = snode.toElement();
2874 snode = mnl.namedItem(
"mColorShadingAlgorithm" );
2875 myElement = snode.toElement();
2878 snode = mnl.namedItem(
"mInvertColor" );
2879 myElement = snode.toElement();
2880 QVariant myVariant = ( QVariant ) myElement.attribute(
"boolean" );
2883 snode = mnl.namedItem(
"mRedBandName" );
2884 myElement = snode.toElement();
2887 snode = mnl.namedItem(
"mGreenBandName" );
2888 myElement = snode.toElement();
2891 snode = mnl.namedItem(
"mBlueBandName" );
2892 myElement = snode.toElement();
2895 snode = mnl.namedItem(
"mGrayBandName" );
2896 myElement = snode.toElement();
2897 QgsDebugMsg( QString(
" Setting gray band to : " ) + myElement.text() );
2900 snode = mnl.namedItem(
"mStandardDeviations" );
2901 myElement = snode.toElement();
2904 snode = mnl.namedItem(
"mUserDefinedRGBMinimumMaximum" );
2905 myElement = snode.toElement();
2906 myVariant = ( QVariant ) myElement.attribute(
"boolean" );
2909 snode = mnl.namedItem(
"mRGBMinimumMaximumEstimated" );
2910 myElement = snode.toElement();
2911 myVariant = ( QVariant ) myElement.attribute(
"boolean" );
2914 snode = mnl.namedItem(
"mUserDefinedGrayMinimumMaximum" );
2915 myElement = snode.toElement();
2916 myVariant = ( QVariant ) myElement.attribute(
"boolean" );
2919 snode = mnl.namedItem(
"mGrayMinimumMaximumEstimated" );
2920 myElement = snode.toElement();
2921 myVariant = ( QVariant ) myElement.attribute(
"boolean" );
2924 snode = mnl.namedItem(
"mContrastEnhancementAlgorithm" );
2925 myElement = snode.toElement();
2928 QDomNode contrastEnhancementMinMaxValues = mnl.namedItem(
"contrastEnhancementMinMaxValues" );
2929 QDomNodeList minMaxValueList = contrastEnhancementMinMaxValues.toElement().elementsByTagName(
"minMaxEntry" );
2930 for (
int i = 0; i < minMaxValueList.size(); ++i )
2932 QDomNode minMaxEntry = minMaxValueList.at( i ).toElement();
2933 if ( minMaxEntry.isNull() )
2937 QDomNode minEntry = minMaxEntry.namedItem(
"min" );
2938 QDomNode maxEntry = minMaxEntry.namedItem(
"max" );
2940 setMinimumValue( i + 1, minEntry.toElement().text().toDouble(), false );
2941 setMaximumValue( i + 1, maxEntry.toElement().text().toDouble(), false );
2952 snode = mnl.namedItem(
"mNoDataValue" );
2953 myElement = snode.toElement();
2954 QgsDebugMsg(
"ReadXml: mNoDataValue = " + myElement.text() );
2957 if ( myElement.attribute(
"mValidNoDataValue",
"false" ).compare(
"true" ) )
2963 QDomNode singleValuePixelListNode = mnl.namedItem(
"singleValuePixelList" );
2964 if ( !singleValuePixelListNode.isNull() )
2966 QList<QgsRasterTransparency::TransparentSingleValuePixel> newSingleValuePixelList;
2969 QDomNodeList singleValuePixelList = singleValuePixelListNode.toElement().elementsByTagName(
"pixelListEntry" );
2970 for (
int i = 0; i < singleValuePixelList.size(); ++i )
2973 QDomElement singleValuePixelListElement = singleValuePixelList.at( i ).toElement();
2974 if ( singleValuePixelListElement.isNull() )
2979 myNewItem.
pixelValue = singleValuePixelListElement.attribute(
"pixelValue" ).toDouble();
2980 myNewItem.
percentTransparent = singleValuePixelListElement.attribute(
"percentTransparent" ).toDouble();
2982 newSingleValuePixelList.push_back( myNewItem );
2987 QDomNode threeValuePixelListNode = mnl.namedItem(
"threeValuePixelList" );
2988 if ( !threeValuePixelListNode.isNull() )
2990 QList<QgsRasterTransparency::TransparentThreeValuePixel> newThreeValuePixelList;
2993 QDomNodeList threeValuePixelList = threeValuePixelListNode.toElement().elementsByTagName(
"pixelListEntry" );
2994 for (
int i = 0; i < threeValuePixelList.size(); ++i )
2997 QDomElement threeValuePixelListElement = threeValuePixelList.at( i ).toElement();
2998 if ( threeValuePixelListElement.isNull() )
3003 myNewItem.
red = threeValuePixelListElement.attribute(
"red" ).toDouble();
3004 myNewItem.
green = threeValuePixelListElement.attribute(
"green" ).toDouble();
3005 myNewItem.
blue = threeValuePixelListElement.attribute(
"blue" ).toDouble();
3006 myNewItem.
percentTransparent = threeValuePixelListElement.attribute(
"percentTransparent" ).toDouble();
3008 newThreeValuePixelList.push_back( myNewItem );
3017 QDomNode customColorRampNode = mnl.namedItem(
"customColorRamp" );
3018 if ( !customColorRampNode.isNull() )
3023 QDomNode customColorRampTypeNode = customColorRampNode.namedItem(
"customColorRampType" );
3024 QDomNode colorRampTypeNode = customColorRampNode.namedItem(
"colorRampType" );
3025 QString myRampType =
"";
3026 if (
"" == customColorRampTypeNode.toElement().text() )
3028 myRampType = colorRampTypeNode.toElement().text();
3032 myRampType = customColorRampTypeNode.toElement().text();
3038 QList<QgsColorRampShader::ColorRampItem> myColorRampItemList;
3039 QDomNodeList colorRampEntryList = customColorRampNode.toElement().elementsByTagName(
"colorRampEntry" );
3040 for (
int i = 0; i < colorRampEntryList.size(); ++i )
3043 QDomElement colorRampEntryElement = colorRampEntryList.at( i ).toElement();
3044 if ( colorRampEntryElement.isNull() )
3049 myNewItem.
color = QColor( colorRampEntryElement.attribute(
"red" ).toInt(), colorRampEntryElement.attribute(
"green" ).toInt(), colorRampEntryElement.attribute(
"blue" ).toInt() );
3050 myNewItem.
label = colorRampEntryElement.attribute(
"label" );
3051 myNewItem.
value = colorRampEntryElement.attribute(
"value" ).toDouble();
3053 myColorRampItemList.push_back( myNewItem );
3089 QDomNode pkeyNode = layer_node.namedItem(
"provider" );
3091 if ( pkeyNode.isNull() )
3097 QDomElement pkeyElt = pkeyNode.toElement();
3111 QDomNode rpNode = layer_node.namedItem(
"rasterproperties" );
3119 QDomElement layerElement = rpNode.firstChildElement(
"wmsSublayer" );
3120 while ( !layerElement.isNull() )
3125 mLayers += layerElement.namedItem(
"name" ).toElement().text();
3128 mStyles += layerElement.namedItem(
"style" ).toElement().text();
3130 layerElement = layerElement.nextSiblingElement(
"wmsSublayer" );
3134 mFormat = rpNode.namedItem(
"wmsFormat" ).toElement().text();
3157 QDomNode stampNode = layer_node.namedItem(
"timestamp" );
3158 if ( !stampNode.isNull() )
3160 QDateTime stamp = QDateTime::fromString( stampNode.toElement().text(), Qt::ISODate );
3162 if ( stamp < mDataProvider->dataTimestamp() )
3183 QDomElement rasterPropertiesElement = document.createElement(
"rasterproperties" );
3184 layer_node.appendChild( rasterPropertiesElement );
3189 QStringList::const_iterator layerStyle = sls.begin();
3194 for ( QStringList::const_iterator layerName = sl.begin();
3195 layerName != sl.end();
3199 QgsDebugMsg( QString(
"<rasterproperties><wmsSublayer> %1" ).arg( layerName->toLocal8Bit().data() ) );
3201 QDomElement sublayerElement = document.createElement(
"wmsSublayer" );
3206 QDomElement sublayerNameElement = document.createElement(
"name" );
3207 QDomText sublayerNameText = document.createTextNode( *layerName );
3208 sublayerNameElement.appendChild( sublayerNameText );
3209 sublayerElement.appendChild( sublayerNameElement );
3212 QDomElement sublayerStyleElement = document.createElement(
"style" );
3213 QDomText sublayerStyleText = document.createTextNode( *layerStyle );
3214 sublayerStyleElement.appendChild( sublayerStyleText );
3215 sublayerElement.appendChild( sublayerStyleElement );
3217 rasterPropertiesElement.appendChild( sublayerElement );
3224 QDomElement formatElement = document.createElement(
"wmsFormat" );
3225 QDomText formatText =
3227 formatElement.appendChild( formatText );
3228 rasterPropertiesElement.appendChild( formatElement );
3232 QDomElement drawStyleElement = document.createElement(
"mDrawingStyle" );
3235 drawStyleElement.appendChild( drawStyleText );
3237 rasterPropertiesElement.appendChild( drawStyleElement );
3240 QDomElement colorShadingAlgorithmElement = document.createElement(
"mColorShadingAlgorithm" );
3243 colorShadingAlgorithmElement.appendChild( colorShadingAlgorithmText );
3245 rasterPropertiesElement.appendChild( colorShadingAlgorithmElement );
3248 QDomElement mInvertColorElement = document.createElement(
"mInvertColor" );
3252 mInvertColorElement.setAttribute(
"boolean",
"true" );
3256 mInvertColorElement.setAttribute(
"boolean",
"false" );
3259 rasterPropertiesElement.appendChild( mInvertColorElement );
3262 QDomElement mRedBandNameElement = document.createElement(
"mRedBandName" );
3269 QDomText mRedBandNameText = document.createTextNode( writtenRedBandName );
3271 mRedBandNameElement.appendChild( mRedBandNameText );
3273 rasterPropertiesElement.appendChild( mRedBandNameElement );
3277 QDomElement mGreenBandNameElement = document.createElement(
"mGreenBandName" );
3284 QDomText mGreenBandNameText = document.createTextNode( writtenGreenBandName );
3286 mGreenBandNameElement.appendChild( mGreenBandNameText );
3288 rasterPropertiesElement.appendChild( mGreenBandNameElement );
3291 QDomElement mBlueBandNameElement = document.createElement(
"mBlueBandName" );
3298 QDomText mBlueBandNameText = document.createTextNode( writtenBlueBandName );
3300 mBlueBandNameElement.appendChild( mBlueBandNameText );
3302 rasterPropertiesElement.appendChild( mBlueBandNameElement );
3305 QDomElement mGrayBandNameElement = document.createElement(
"mGrayBandName" );
3312 QDomText mGrayBandNameText = document.createTextNode( writtenGrayBandName );
3314 mGrayBandNameElement.appendChild( mGrayBandNameText );
3315 rasterPropertiesElement.appendChild( mGrayBandNameElement );
3318 QDomElement mStandardDeviationsElement = document.createElement(
"mStandardDeviations" );
3319 QDomText mStandardDeviationsText = document.createTextNode( QString::number(
standardDeviations() ) );
3321 mStandardDeviationsElement.appendChild( mStandardDeviationsText );
3323 rasterPropertiesElement.appendChild( mStandardDeviationsElement );
3326 QDomElement userDefinedRGBMinMaxFlag = document.createElement(
"mUserDefinedRGBMinimumMaximum" );
3330 userDefinedRGBMinMaxFlag.setAttribute(
"boolean",
"true" );
3334 userDefinedRGBMinMaxFlag.setAttribute(
"boolean",
"false" );
3337 rasterPropertiesElement.appendChild( userDefinedRGBMinMaxFlag );
3340 QDomElement RGBMinimumMaximumEstimated = document.createElement(
"mRGBMinimumMaximumEstimated" );
3344 RGBMinimumMaximumEstimated.setAttribute(
"boolean",
"true" );
3348 RGBMinimumMaximumEstimated.setAttribute(
"boolean",
"false" );
3351 rasterPropertiesElement.appendChild( RGBMinimumMaximumEstimated );
3354 QDomElement userDefinedGrayMinMaxFlag = document.createElement(
"mUserDefinedGrayMinimumMaximum" );
3358 userDefinedGrayMinMaxFlag.setAttribute(
"boolean",
"true" );
3362 userDefinedGrayMinMaxFlag.setAttribute(
"boolean",
"false" );
3365 rasterPropertiesElement.appendChild( userDefinedGrayMinMaxFlag );
3368 QDomElement GrayMinimumMaximumEstimated = document.createElement(
"mGrayMinimumMaximumEstimated" );
3372 GrayMinimumMaximumEstimated.setAttribute(
"boolean",
"true" );
3376 GrayMinimumMaximumEstimated.setAttribute(
"boolean",
"false" );
3379 rasterPropertiesElement.appendChild( GrayMinimumMaximumEstimated );
3382 QDomElement contrastEnhancementAlgorithmElement = document.createElement(
"mContrastEnhancementAlgorithm" );
3385 contrastEnhancementAlgorithmElement.appendChild( contrastEnhancementAlgorithmText );
3387 rasterPropertiesElement.appendChild( contrastEnhancementAlgorithmElement );
3390 QList<QgsContrastEnhancement>::const_iterator it;
3391 QDomElement contrastEnhancementMinMaxValuesElement = document.createElement(
"contrastEnhancementMinMaxValues" );
3394 QDomElement minMaxEntry = document.createElement(
"minMaxEntry" );
3395 QDomElement minEntry = document.createElement(
"min" );
3396 QDomElement maxEntry = document.createElement(
"max" );
3398 QDomText minEntryText = document.createTextNode( QString::number( it->minimumValue() ) );
3399 minEntry.appendChild( minEntryText );
3401 QDomText maxEntryText = document.createTextNode( QString::number( it->maximumValue() ) );
3402 maxEntry.appendChild( maxEntryText );
3404 minMaxEntry.appendChild( minEntry );
3405 minMaxEntry.appendChild( maxEntry );
3407 contrastEnhancementMinMaxValuesElement.appendChild( minMaxEntry );
3410 rasterPropertiesElement.appendChild( contrastEnhancementMinMaxValuesElement );
3416 QDomElement mNoDataValueElement = document.createElement(
"mNoDataValue" );
3417 QDomText mNoDataValueText = document.createTextNode( QString::number(
mNoDataValue,
'f' ) );
3420 mNoDataValueElement.setAttribute(
"mValidNoDataValue",
"true" );
3424 mNoDataValueElement.setAttribute(
"mValidNoDataValue",
"false" );
3427 mNoDataValueElement.appendChild( mNoDataValueText );
3429 rasterPropertiesElement.appendChild( mNoDataValueElement );
3434 QDomElement singleValuePixelListElement = document.createElement(
"singleValuePixelList" );
3437 QList<QgsRasterTransparency::TransparentSingleValuePixel>::iterator it;
3438 for ( it = myPixelList.begin(); it != myPixelList.end(); ++it )
3440 QDomElement pixelListElement = document.createElement(
"pixelListEntry" );
3441 pixelListElement.setAttribute(
"pixelValue", QString::number( it->pixelValue,
'f' ) );
3442 pixelListElement.setAttribute(
"percentTransparent", QString::number( it->percentTransparent ) );
3444 singleValuePixelListElement.appendChild( pixelListElement );
3447 rasterPropertiesElement.appendChild( singleValuePixelListElement );
3452 QDomElement threeValuePixelListElement = document.createElement(
"threeValuePixelList" );
3455 QList<QgsRasterTransparency::TransparentThreeValuePixel>::iterator it;
3456 for ( it = myPixelList.begin(); it != myPixelList.end(); ++it )
3458 QDomElement pixelListElement = document.createElement(
"pixelListEntry" );
3459 pixelListElement.setAttribute(
"red", QString::number( it->red,
'f' ) );
3460 pixelListElement.setAttribute(
"green", QString::number( it->green,
'f' ) );
3461 pixelListElement.setAttribute(
"blue", QString::number( it->blue,
'f' ) );
3462 pixelListElement.setAttribute(
"percentTransparent", QString::number( it->percentTransparent ) );
3464 threeValuePixelListElement.appendChild( pixelListElement );
3467 rasterPropertiesElement.appendChild( threeValuePixelListElement );
3475 QDomElement customColorRampElement = document.createElement(
"customColorRamp" );
3477 QDomElement customColorRampType = document.createElement(
"colorRampType" );
3479 customColorRampType.appendChild( customColorRampTypeText );
3480 customColorRampElement.appendChild( customColorRampType );
3483 QList<QgsColorRampShader::ColorRampItem>::iterator it;
3484 for ( it = myColorRampItemList.begin(); it != myColorRampItemList.end(); ++it )
3486 QDomElement colorRampEntryElement = document.createElement(
"colorRampEntry" );
3487 colorRampEntryElement.setAttribute(
"red", QString::number( it->color.red() ) );
3488 colorRampEntryElement.setAttribute(
"green", QString::number( it->color.green() ) );
3489 colorRampEntryElement.setAttribute(
"blue", QString::number( it->color.blue() ) );
3490 colorRampEntryElement.setAttribute(
"value", QString::number( it->value,
'f' ) );
3491 colorRampEntryElement.setAttribute(
"label", it->label );
3493 customColorRampElement.appendChild( colorRampEntryElement );
3496 rasterPropertiesElement.appendChild( customColorRampElement );
3507 QDomDocument & document )
3511 QDomElement mapLayerNode = layer_node.toElement();
3513 if ( mapLayerNode.isNull() || (
"maplayer" != mapLayerNode.nodeName() ) )
3519 mapLayerNode.setAttribute(
"type",
"raster" );
3523 QDomElement provider = document.createElement(
"provider" );
3524 QDomText providerText = document.createTextNode(
mProviderKey );
3525 provider.appendChild( providerText );
3526 layer_node.appendChild( provider );
3544 imageBuffer.
reset();
3546 QRgb* imageScanLine = 0;
3547 void* rasterScanLine = 0;
3549 while ( imageBuffer.
nextScanLine( &imageScanLine, &rasterScanLine ) )
3554 memcpy( imageScanLine, rasterScanLine, size );
3558 uint *p = ( uint* ) rasterScanLine;
3563 imageScanLine[ i ] = qRgba( qRed( c ), qGreen( c ), qBlue( c ), qAlpha( c ) *
mTransparencyLevel / 255 );
3575 if ( 0 >= myRedBandNo )
3582 if ( 0 >= myGreenBandNo )
3589 if ( 0 >= myBlueBandNo )
3595 bool hasTransparencyBand = 0 < myTransparencyBandNo;
3602 QRgb* redImageScanLine = 0;
3603 void* redRasterScanLine = 0;
3604 QRgb* greenImageScanLine = 0;
3605 void* greenRasterScanLine = 0;
3606 QRgb* blueImageScanLine = 0;
3607 void* blueRasterScanLine = 0;
3608 QRgb* transparencyImageScanLine = 0;
3609 void* transparencyRasterScanLine = 0;
3611 QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
3652 double myRedValue = 0.0;
3653 double myGreenValue = 0.0;
3654 double myBlueValue = 0.0;
3655 int myTransparencyValue = 0;
3657 int myStretchedRedValue = 0;
3658 int myStretchedGreenValue = 0;
3659 int myStretchedBlueValue = 0;
3660 int myAlphaValue = 0;
3666 redImageBuffer.
reset();
3669 greenImageBuffer.
reset();
3672 blueImageBuffer.
reset();
3675 if ( hasTransparencyBand )
3679 transparencyImageBuffer->
reset();
3682 while ( redImageBuffer.
nextScanLine( &redImageScanLine, &redRasterScanLine )
3683 && greenImageBuffer.
nextScanLine( &greenImageScanLine, &greenRasterScanLine )
3684 && blueImageBuffer.
nextScanLine( &blueImageScanLine, &blueRasterScanLine )
3685 && ( !transparencyImageBuffer || transparencyImageBuffer->
nextScanLine( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
3689 if ( transparencyImageBuffer )
3691 myTransparencyValue =
readValue( transparencyRasterScanLine, myTransparencyType, i );
3692 if ( 0 == myTransparencyValue )
3694 redImageScanLine[ i ] = myDefaultColor;
3699 myRedValue =
readValue( redRasterScanLine, myRedType, i );
3700 myGreenValue =
readValue( greenRasterScanLine, myGreenType, i );
3701 myBlueValue =
readValue( blueRasterScanLine, myBlueType, i );
3711 redImageScanLine[ i ] = myDefaultColor;
3720 redImageScanLine[ i ] = myDefaultColor;
3725 if ( 0 == myAlphaValue )
3727 redImageScanLine[ i ] = myDefaultColor;
3733 myStretchedRedValue = myRedValue;
3734 myStretchedGreenValue = myGreenValue;
3735 myStretchedBlueValue = myBlueValue;
3739 myStretchedRedValue = myRedContrastEnhancement->
enhanceContrast( myRedValue );
3740 myStretchedGreenValue = myGreenContrastEnhancement->
enhanceContrast( myGreenValue );
3741 myStretchedBlueValue = myBlueContrastEnhancement->
enhanceContrast( myBlueValue );
3746 myStretchedRedValue = 255 - myStretchedRedValue;
3747 myStretchedGreenValue = 255 - myStretchedGreenValue;
3748 myStretchedBlueValue = 255 - myStretchedBlueValue;
3751 if ( myTransparencyValue )
3752 myAlphaValue *= myTransparencyValue / 255.0;
3754 redImageScanLine[ i ] = qRgba( myStretchedRedValue, myStretchedGreenValue, myStretchedBlueValue, myAlphaValue );
3758 if ( transparencyImageBuffer )
3759 delete transparencyImageBuffer;
3788 if ( 0 >= theBandNo )
3794 bool hasTransparencyBand = 0 < myTransparencyBandNo;
3805 imageBuffer.
reset();
3808 if ( hasTransparencyBand )
3812 transparencyImageBuffer->
reset();
3815 QRgb* imageScanLine = 0;
3816 void* rasterScanLine = 0;
3817 QRgb* transparencyImageScanLine = 0;
3818 void* transparencyRasterScanLine = 0;
3820 QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
3821 double myPixelValue = 0.0;
3823 int myGreenValue = 0;
3824 int myBlueValue = 0;
3825 int myTransparencyValue = 0;
3826 int myAlphaValue = 0;
3828 while ( imageBuffer.
nextScanLine( &imageScanLine, &rasterScanLine )
3829 && ( !transparencyImageBuffer || transparencyImageBuffer->
nextScanLine( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
3833 if ( transparencyImageBuffer )
3835 myTransparencyValue =
readValue( transparencyRasterScanLine, myTransparencyType, i );
3836 if ( 0 == myTransparencyValue )
3838 imageScanLine[ i ] = myDefaultColor;
3847 myPixelValue =
readValue( rasterScanLine, myDataType, i );
3851 imageScanLine[ i ] = myDefaultColor;
3856 if ( 0 == myAlphaValue )
3858 imageScanLine[ i ] = myDefaultColor;
3862 if ( !
mRasterShader->
shade( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
3864 imageScanLine[ i ] = myDefaultColor;
3868 if ( myTransparencyValue )
3869 myAlphaValue *= myTransparencyValue / 255.0;
3874 imageScanLine[ i ] = qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
3879 imageScanLine[ i ] = qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
3884 if ( transparencyImageBuffer )
3885 delete transparencyImageBuffer;
3900 if ( 0 >= theBandNo )
3906 bool hasTransparencyBand = 0 < myTransparencyBandNo;
3917 imageBuffer.
reset();
3920 if ( hasTransparencyBand )
3924 transparencyImageBuffer->
reset();
3927 QRgb* imageScanLine = 0;
3928 void* rasterScanLine = 0;
3929 QRgb* transparencyImageScanLine = 0;
3930 void* transparencyRasterScanLine = 0;
3932 QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
3933 double myPixelValue = 0.0;
3935 int myGreenValue = 0;
3936 int myBlueValue = 0;
3937 int myTransparencyValue = 0;
3938 int myAlphaValue = 0;
3940 while ( imageBuffer.
nextScanLine( &imageScanLine, &rasterScanLine )
3941 && ( !transparencyImageBuffer || transparencyImageBuffer->
nextScanLine( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
3945 if ( transparencyImageBuffer )
3947 myTransparencyValue =
readValue( transparencyRasterScanLine, myTransparencyType, i );
3948 if ( 0 == myTransparencyValue )
3950 imageScanLine[ i ] = myDefaultColor;
3959 myPixelValue =
readValue( rasterScanLine, myDataType, i );
3963 imageScanLine[ i ] = myDefaultColor;
3968 if ( 0 == myAlphaValue )
3970 imageScanLine[ i ] = myDefaultColor;
3974 if ( !
mRasterShader->
shade( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
3976 imageScanLine[ i ] = myDefaultColor;
3980 if ( myTransparencyValue )
3981 myAlphaValue *= myTransparencyValue / 255.0;
3986 double myGrayValue = ( 0.3 * ( double )myRedValue ) + ( 0.59 * ( double )myGreenValue ) + ( 0.11 * ( double )myBlueValue );
3987 imageScanLine[ i ] = qRgba((
int )myGrayValue, (
int )myGrayValue, (
int )myGrayValue, myAlphaValue );
3992 double myGrayValue = ( 0.3 * ( double )myBlueValue ) + ( 0.59 * ( double )myGreenValue ) + ( 0.11 * ( double )myRedValue );
3993 imageScanLine[ i ] = qRgba((
int )myGrayValue, (
int )myGrayValue, (
int )myGrayValue, myAlphaValue );
3998 if ( transparencyImageBuffer )
3999 delete transparencyImageBuffer;
4015 if ( 0 >= theBandNo )
4021 bool hasTransparencyBand = 0 < myTransparencyBandNo;
4033 imageBuffer.
reset();
4036 if ( hasTransparencyBand )
4040 transparencyImageBuffer->
reset();
4043 QRgb* imageScanLine = 0;
4044 void* rasterScanLine = 0;
4045 QRgb* transparencyImageScanLine = 0;
4046 void* transparencyRasterScanLine = 0;
4048 QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
4049 double myMinimumValue = 0.0;
4050 double myMaximumValue = 0.0;
4066 double myPixelValue = 0.0;
4068 int myGreenValue = 0;
4069 int myBlueValue = 0;
4070 int myTransparencyValue = 0;
4071 int myAlphaValue = 0;
4073 while ( imageBuffer.
nextScanLine( &imageScanLine, &rasterScanLine )
4074 && ( !transparencyImageBuffer || transparencyImageBuffer->
nextScanLine( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
4078 if ( transparencyImageBuffer )
4080 myTransparencyValue =
readValue( transparencyRasterScanLine, myTransparencyType, i );
4081 if ( 0 == myTransparencyValue )
4083 imageScanLine[ i ] = myDefaultColor;
4088 myPixelValue =
readValue( rasterScanLine, myDataType, i );
4092 imageScanLine[ i ] = myDefaultColor;
4097 if ( 0 == myAlphaValue )
4099 imageScanLine[ i ] = myDefaultColor;
4103 if ( !
mRasterShader->
shade( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
4105 imageScanLine[ i ] = myDefaultColor;
4109 if ( myTransparencyValue )
4110 myAlphaValue *= myTransparencyValue / 255.0;
4115 imageScanLine[ i ] = qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
4120 imageScanLine[ i ] = qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
4125 if ( transparencyImageBuffer )
4126 delete transparencyImageBuffer;
4146 QgsDebugMsg(
"layer=" + QString::number( theBandNo ) );
4148 if ( 0 >= theBandNo )
4154 bool hasTransparencyBand = 0 < myTransparencyBandNo;
4157 QgsDebugMsg(
"myDataType = " + QString::number( myDataType ) );
4161 imageBuffer.
reset();
4164 if ( hasTransparencyBand )
4168 transparencyImageBuffer->
reset();
4171 QRgb* imageScanLine = 0;
4172 void* rasterScanLine = 0;
4173 QRgb* transparencyImageScanLine = 0;
4174 void* transparencyRasterScanLine = 0;
4176 QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
4177 double myGrayValue = 0.0;
4179 int myTransparencyValue = 0;
4180 int myAlphaValue = 0;
4202 while ( imageBuffer.
nextScanLine( &imageScanLine, &rasterScanLine )
4203 && ( !transparencyImageBuffer || transparencyImageBuffer->
nextScanLine( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
4208 if ( transparencyImageBuffer )
4210 myTransparencyValue =
readValue( transparencyRasterScanLine, myTransparencyType, i );
4211 if ( 0 == myTransparencyValue )
4213 imageScanLine[ i ] = myDefaultColor;
4218 myGrayValue =
readValue( rasterScanLine, myDataType, i );
4226 imageScanLine[ i ] = myDefaultColor;
4232 imageScanLine[ i ] = myDefaultColor;
4237 if ( 0 == myAlphaValue )
4239 imageScanLine[ i ] = myDefaultColor;
4248 myGrayVal = 255 - myGrayVal;
4251 if ( myTransparencyValue )
4252 myAlphaValue *= myTransparencyValue / 255.0;
4255 imageScanLine[ i ] = qRgba( myGrayVal, myGrayVal, myGrayVal, myAlphaValue );
4259 if ( transparencyImageBuffer )
4260 delete transparencyImageBuffer;
4268 if ( 0 >= theBandNo )
4274 bool hasTransparencyBand = 0 < myTransparencyBandNo;
4286 imageBuffer.
reset();
4289 if ( hasTransparencyBand )
4293 transparencyImageBuffer->
reset();
4296 QRgb* imageScanLine = 0;
4297 void* rasterScanLine = 0;
4298 QRgb* transparencyImageScanLine = 0;
4299 void* transparencyRasterScanLine = 0;
4301 QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
4303 double myMinimumValue = 0.0;
4304 double myMaximumValue = 0.0;
4320 int myRedValue = 255;
4321 int myGreenValue = 255;
4322 int myBlueValue = 255;
4323 int myTransparencyValue = 0;
4325 double myPixelValue = 0.0;
4326 int myAlphaValue = 0;
4328 while ( imageBuffer.
nextScanLine( &imageScanLine, &rasterScanLine )
4329 && ( !transparencyImageBuffer || transparencyImageBuffer->
nextScanLine( &transparencyImageScanLine, &transparencyRasterScanLine ) ) )
4333 if ( transparencyImageBuffer )
4335 myTransparencyValue =
readValue( transparencyRasterScanLine, myTransparencyType, i );
4336 if ( 0 == myTransparencyValue )
4338 imageScanLine[ i ] = myDefaultColor;
4343 myPixelValue =
readValue( rasterScanLine, myDataType, i );
4347 imageScanLine[ i ] = myDefaultColor;
4352 if ( 0 == myAlphaValue )
4354 imageScanLine[ i ] = myDefaultColor;
4358 if ( !
mRasterShader->
shade( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue ) )
4360 imageScanLine[ i ] = myDefaultColor;
4364 if ( myTransparencyValue )
4365 myAlphaValue *= myTransparencyValue / 255.0;
4370 imageScanLine[ i ] = qRgba( myBlueValue, myGreenValue, myRedValue, myAlphaValue );
4375 imageScanLine[ i ] = qRgba( myRedValue, myGreenValue, myBlueValue, myAlphaValue );
4381 if ( transparencyImageBuffer )
4382 delete transparencyImageBuffer;
4388 return tr(
"Band" ) + QString(
" %1" ) .arg( theBandNumber, 1 + (
int ) log10((
float )
bandCount() ), 10, QChar(
'0' ) );
4399 QgsDebugMsg(
"Looking for band : " + theBandName );
4408 if ( myColorQString == theBandName )
4417 QgsDebugMsgLevel(
"Found unmatched band : " + QString::number( i ) +
" " + myColorQString, 2 );
4438 QString(
", source NW corner: " ) + QString::number( viewPort->rectXOffset ) +
4439 ", " + QString::number( viewPort->rectYOffset ) +
4440 ", source size: " + QString::number( viewPort->clippedWidth ) +
4441 ", " + QString::number( viewPort->clippedHeight ) +
4450 QgsDebugMsg(
"Layer " +
name() +
" couldn't allocate enough memory. Ignoring" );
4489 return (
double )(( GByte * )data )[index];
4492 return (
double )(( GUInt16 * )data )[index];
4495 return (
double )(( GInt16 * )data )[index];
4498 return (
double )(( GUInt32 * )data )[index];
4501 return (
double )(( GInt32 * )data )[index];
4504 return (
double )((
float * )data )[index];
4507 return (
double )((
double * )data )[index];
4548 QgsDebugMsg(
"Looking through raster band stats for matching band name" );
4549 for (
int myIterator = 0; myIterator <
mRasterStatsList.size(); ++myIterator )
4558 QgsDebugMsg(
"No matching band name found in raster band stats" );
4560 QgsDebugMsg(
"Testing for non zero-buffered names" );
4562 QStringList myBandNameComponents = theBandName.split(
" " );
4563 if ( myBandNameComponents.size() == 2 )
4565 int myBandNumber = myBandNameComponents.at( 1 ).toInt();
4566 if ( myBandNumber > 0 )
4569 for (
int myIterator = 0; myIterator <
mRasterStatsList.size(); ++myIterator )
4584 myBandNameComponents.clear();
4585 if ( theBandName.contains(
':' ) )
4587 myBandNameComponents = theBandName.split(
":" );
4588 if ( myBandNameComponents.size() == 2 )
4590 int myBandNumber = myBandNameComponents.at( 0 ).toInt();
4591 if ( myBandNumber > 0 )
4593 QgsDebugMsg(
"Transformed older name format to current format" );
4594 return "Band " + QString::number( myBandNumber );
4605 mDataProvider( dataProvider ), mBandNo( bandNo ), mPainter( p ), mViewPort( viewPort ), mMapToPixel( mapToPixel ), mGeoTransform( geoTransform ), mValid( false ), mWritingEnabled( true ), mDrawPixelRect( false ), mCurrentImage( 0 ), mCurrentGDALData( 0 )
4717 QgsDebugMsg( QString(
"imageX = %1 imageY = %2" ).arg( imageX ).arg( imageY ) );
4718 mPainter->drawImage( QPointF( imageX, imageY ),
4749 int overlapRows = 0;
4761 QgsDebugMsg(
"rasterYSize = " + QString::number( rasterYSize ) );
4778 QgsDebugMsg( QString(
"xSize = %1 ySize = %2" ).arg( xSize ).arg( ySize ) );
4779 if ( ySize < 1 || xSize < 1 )
4784 QgsDebugMsg(
"alloc " + QString::number( size * xSize * rasterYSize ) );
4793 QgsDebugMsg(
"myPartExtent is " + myPartExtent.toString() );
4799 mCurrentImage =
new QImage( xSize, ySize, QImage::Format_ARGB32 );
4818 int paintXoffset = 0;
4819 int paintYoffset = 0;
4823 paintXoffset =
static_cast<int>(
4830 paintYoffset =
static_cast<int>(
4851 QBrush( myColor ) );
4856 int myPixelBoundaryX = 0;
4857 int myPixelBoundaryY = 0;
4872 static_cast<int>( myPixelBoundaryY ),
4873 QBrush( myColor ) );
4877 static_cast<int>( myPixelBoundaryY ),
4880 QBrush( myColor ) );
4891 static_cast<int>( myPixelBoundaryX ),
4893 QBrush( myColor ) );
4896 mPainter->fillRect( static_cast<int>( myPixelBoundaryX ),
4900 QBrush( myColor ) );
4909 static_cast<int>( myPixelBoundaryX ),
4910 static_cast<int>( myPixelBoundaryY ),
4911 QBrush( myColor ) );
4914 mPainter->fillRect( static_cast<int>( myPixelBoundaryX ),
4917 static_cast<int>( myPixelBoundaryY ),
4918 QBrush( myColor ) );
4922 static_cast<int>( myPixelBoundaryY ),
4923 static_cast<int>( myPixelBoundaryX ),
4925 QBrush( myColor ) );
4928 mPainter->fillRect( static_cast<int>( myPixelBoundaryX ),
4929 static_cast<int>( myPixelBoundaryY ),
4932 QBrush( myColor ) );
4942 if ( GDALGetDriverCount() == 0 )
4951 if ( myColorRampItemList.size() == 0 )
4955 *theList = myColorRampItemList;