26 #include <QCryptographicHash> 34 mTabStyle =
"border-spacing: 0px; border-width: 1px 1px 0 0; border-style: solid;";
35 mCellStyle =
"border-width: 0 0 1px 1px; border-style: solid; font-size: smaller; text-align: center;";
36 mOkStyle =
"background: #00ff00;";
37 mErrStyle =
"background: #ff0000;";
38 mErrMsgStyle =
"color: #ff0000;";
49 if ( !verifiedProvider || !verifiedProvider->
isValid() )
51 error(
QString(
"Cannot load provider %1 with URI: %2" ).arg( theVerifiedKey, theVerifiedUri ), mReport );
57 if ( !expectedProvider || !expectedProvider->
isValid() )
59 error(
QString(
"Cannot load provider %1 with URI: %2" ).arg( theExpectedKey, theExpectedUri ), mReport );
63 if ( !ok )
return false;
65 mReport +=
QString(
"Verified URI: %1<br>" ).
arg( theVerifiedUri.
replace(
'&',
"&" ) );
66 mReport +=
QString(
"Expected URI: %1<br>" ).
arg( theExpectedUri.
replace(
'&',
"&" ) );
69 mReport +=
QString(
"<table style='%1'>\n" ).
arg( mTabStyle );
70 mReport += compareHead();
72 compare(
"Band count", verifiedProvider->
bandCount(), expectedProvider->
bandCount(), mReport, ok );
74 compare(
"Width", verifiedProvider->
xSize(), expectedProvider->
xSize(), mReport, ok );
75 compare(
"Height", verifiedProvider->
ySize(), expectedProvider->
ySize(), mReport, ok );
79 if ( verifiedProvider->
extent() != expectedProvider->
extent() ) ok =
false;
82 mReport +=
"</table>\n";
84 if ( !ok )
return false;
87 for (
int band = 1; band <= expectedProvider->
bandCount(); band++ )
89 mReport +=
QString(
"<h3>Band %1</h3>\n" ).
arg( band );
90 mReport +=
QString(
"<table style='%1'>\n" ).
arg( mTabStyle );
91 mReport += compareHead();
95 compare(
"Source data type", verifiedProvider->
srcDataType( band ), expectedProvider->
srcDataType( band ), mReport, typesOk );
96 compare(
"Data type", verifiedProvider->
dataType( band ), expectedProvider->
dataType( band ), mReport, typesOk );
115 tol = tolerance( expectedStats.
mean );
116 compare(
"Mean", verifiedStats.
mean, expectedStats.
mean, mReport, statsOk, tol );
119 tol = tolerance( expectedStats.
stdDev, 1 );
120 compare(
"Standard deviation", verifiedStats.
stdDev, expectedStats.
stdDev, mReport, statsOk, tol );
122 mReport +=
"</table>";
125 if ( !statsOk || !typesOk )
131 mReport +=
"<table><tr>";
132 mReport +=
"<td>Data comparison</td>";
133 mReport +=
QString(
"<td style='%1 %2 border: 1px solid'>correct value</td>" ).
arg( mCellStyle, mOkStyle );
134 mReport +=
"<td></td>";
135 mReport +=
QString(
"<td style='%1 %2 border: 1px solid'>wrong value<br>expected value</td></tr>" ).
arg( mCellStyle, mErrStyle );
136 mReport +=
"</tr></table>";
139 int width = expectedProvider->
xSize();
140 int height = expectedProvider->
ySize();
144 if ( !expectedBlock || !expectedBlock->
isValid() ||
145 !verifiedBlock || !verifiedBlock->
isValid() )
148 mReport +=
"cannot read raster block";
154 for (
int row = 0; row < height; row ++ )
157 for (
int col = 0; col < width; col ++ )
160 double verifiedVal = verifiedBlock->
value( row, col );
161 double expectedVal = expectedBlock->
value( row, col );
164 if ( compare( verifiedVal, expectedVal, 0 ) )
172 valStr =
QString(
"%1<br>%2" ).
arg( verifiedVal ).
arg( expectedVal );
174 htmlTable +=
QString(
"<td style='%1 %2'>%3</td>" ).
arg( mCellStyle, cellOk ? mOkStyle : mErrStyle, valStr );
176 htmlTable +=
"</tr>";
178 htmlTable +=
"</table>";
180 mReport += htmlTable;
182 delete expectedBlock;
183 delete verifiedBlock;
185 delete verifiedProvider;
186 delete expectedProvider;
190 void QgsRasterChecker::error(
const QString& theMessage,
QString &theReport )
192 theReport +=
QString(
"<font style='%1'>Error: " ).
arg( mErrMsgStyle );
193 theReport += theMessage;
194 theReport +=
"</font>";
197 double QgsRasterChecker::tolerance(
double val,
int places )
201 return 1. * qPow( 10, qRound( log10( qAbs( val ) ) - places ) );
204 QString QgsRasterChecker::compareHead()
207 html +=
QString(
"<tr><th style='%1'>Param name</th><th style='%1'>Verified value</th><th style='%1'>Expected value</th><th style='%1'>Difference</th><th style='%1'>Tolerance</th></tr>" ).
arg( mCellStyle );
211 void QgsRasterChecker::compare(
const QString& theParamName,
int verifiedVal,
int expectedVal,
QString &theReport,
bool &theOk )
213 bool ok = verifiedVal == expectedVal;
215 if ( !ok ) theOk =
false;
218 bool QgsRasterChecker::compare(
double verifiedVal,
double expectedVal,
double theTolerance )
221 return ( qIsNaN( verifiedVal ) && qIsNaN( expectedVal ) ) || ( qAbs( verifiedVal - expectedVal ) <= theTolerance );
224 void QgsRasterChecker::compare(
const QString& theParamName,
double verifiedVal,
double expectedVal,
QString &theReport,
bool &theOk,
double theTolerance )
226 bool ok = compare( verifiedVal, expectedVal, theTolerance );
228 if ( !ok ) theOk =
false;
231 void QgsRasterChecker::compareRow(
const QString& theParamName,
const QString& verifiedVal,
const QString& expectedVal,
QString &theReport,
bool theOk,
const QString& theDifference,
const QString& theTolerance )
233 theReport +=
"<tr>\n";
234 theReport +=
QString(
"<td style='%1'>%2</td><td style='%1 %3'>%4</td><td style='%1'>%5</td>\n" ).
arg( mCellStyle, theParamName, theOk ? mOkStyle : mErrStyle, verifiedVal, expectedVal );
235 theReport +=
QString(
"<td style='%1'>%2</td>\n" ).
arg( mCellStyle, theDifference );
236 theReport +=
QString(
"<td style='%1'>%2</td>\n" ).
arg( mCellStyle, theTolerance );
237 theReport +=
"</tr>";
virtual int bandCount() const =0
Get number of bands.
static QgsProviderRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
bool isValid() const
Returns true if the block is valid (correctly filled with data).
double maximumValue
The maximum cell value in the raster band.
virtual int ySize() const
virtual QgsRasterBandStats bandStatistics(int theBandNo, int theStats=QgsRasterBandStats::All, const QgsRectangle &theExtent=QgsRectangle(), int theSampleSize=0)
Get band statistics.
double stdDev
The standard deviation of the cell values.
QString number(int n, int base)
The RasterBandStats struct is a container for statistics about a single raster band.
double mean
The mean cell value for the band.
QgsDataProvider * provider(const QString &providerKey, const QString &dataSource)
Create an instance of the provider.
virtual QGis::DataType srcDataType(int bandNo) const override=0
Returns source data type for the band specified by number, source data type may be shorter than dataT...
double value(int row, int column) const
Read a single value if type of block is numeric.
virtual QgsRasterBlock * block(int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight) override
Read block of data using given extent and size.
virtual QgsRectangle extent() override=0
Get the extent of the data source.
virtual QGis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
QString & replace(int position, int n, QChar after)
bool runTest(const QString &theVerifiedKey, QString theVerifiedUri, const QString &theExpectedKey, QString theExpectedUri)
Test using renderer to generate the image to be compared.
virtual int xSize() const
Get raster size.
virtual bool isValid()=0
Returns true if this is a valid layer.
double minimumValue
The minimum cell value in the raster band.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Base class for raster data providers.