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;";
42 QString theExpectedKey, QString theExpectedUri )
49 if ( !verifiedProvider || !verifiedProvider->
isValid() )
51 error( QString(
"Cannot load provider %1 with URI: %2" ).arg( theVerifiedKey ).arg( theVerifiedUri ),
mReport );
57 if ( !expectedProvider || !expectedProvider->
isValid() )
59 error( QString(
"Cannot load provider %1 with URI: %2" ).arg( theExpectedKey ).arg( 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(
"&",
"&" ) );
79 if ( verifiedProvider->
extent() != expectedProvider->
extent() ) ok =
false;
84 if ( !ok )
return false;
87 for (
int band = 1; band <= expectedProvider->
bandCount(); band++ )
90 mReport += QString(
"<h3>Band %1</h3>\n" ).arg( band );
132 if ( !statsOk || !typesOk )
139 mReport +=
"<td>Data comparison</td>";
142 mReport += QString(
"<td style='%1 %2 border: 1px solid'>wrong value<br>expected value</td></tr>" ).arg(
mCellStyle ).arg(
mErrStyle );
146 int width = expectedProvider->
xSize();
147 int height = expectedProvider->
ySize();
151 if ( !expectedBlock || !expectedBlock->
isValid() ||
152 !verifiedBlock || !verifiedBlock->
isValid() )
155 mReport +=
"cannot read raster block";
160 QString htmlTable = QString(
"<table style='%1'>" ).arg(
mTabStyle );
161 for (
int row = 0; row < height; row ++ )
164 for (
int col = 0; col < width; col ++ )
167 double verifiedVal = verifiedBlock->
value( row, col );
168 double expectedVal = expectedBlock->
value( row, col );
171 if (
compare( verifiedVal, expectedVal, 0 ) )
173 valStr = QString(
"%1" ).arg( verifiedVal );
179 valStr = QString(
"%1<br>%2" ).arg( verifiedVal ).arg( expectedVal );
183 htmlTable +=
"</tr>";
185 htmlTable +=
"</table>";
189 delete expectedBlock;
190 delete verifiedBlock;
192 delete verifiedProvider;
193 delete expectedProvider;
199 theReport += QString(
"<font style='%1'>Error: " ).arg(
mErrMsgStyle );
200 theReport += theMessage;
201 theReport +=
"</font>";
208 return 1. * qPow( 10, qRound( log10( qAbs( val ) ) - places ) );
214 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 );
220 bool ok = verifiedVal == expectedVal;
221 compareRow( theParamName, QString::number( verifiedVal ), QString::number( expectedVal ), theReport, ok, QString::number( verifiedVal - expectedVal ) );
222 if ( !ok ) theOk =
false;
228 return ( qIsNaN( verifiedVal ) && qIsNaN( expectedVal ) ) || ( qAbs( verifiedVal - expectedVal ) <= theTolerance );
231 void QgsRasterChecker::compare( QString theParamName,
double verifiedVal,
double expectedVal, QString &theReport,
bool &theOk,
double theTolerance )
233 bool ok =
compare( verifiedVal, expectedVal, theTolerance );
234 compareRow( theParamName, QString::number( verifiedVal ), QString::number( expectedVal ), theReport, ok, QString::number( verifiedVal - expectedVal ), QString::number( theTolerance ) );
235 if ( !ok ) theOk =
false;
238 void QgsRasterChecker::compareRow( QString theParamName, QString verifiedVal, QString expectedVal, QString &theReport,
bool theOk, QString theDifference, QString theTolerance )
240 theReport +=
"<tr>\n";
241 theReport += QString(
"<td style='%1'>%2</td><td style='%1 %3'>%4</td><td style='%1'>%5</td>\n" ).arg(
mCellStyle ).arg( theParamName ).arg( theOk ?
mOkStyle :
mErrStyle ).arg( verifiedVal ).arg( expectedVal );
242 theReport += QString(
"<td style='%1'>%2</td>\n" ).arg(
mCellStyle ).arg( theDifference );
243 theReport += QString(
"<td style='%1'>%2</td>\n" ).arg(
mCellStyle ).arg( theTolerance );
244 theReport +=
"</tr>";
virtual int bandCount() const =0
Get number of bands.
bool isValid() const
Returns true if the block is valid (correctly filled with data).
virtual QgsRasterBlock * block(int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight)
Read block of data using given extent and size.
static QgsProviderRegistry * instance(QString pluginPath=QString::null)
means of accessing canonical single instance
double maximumValue
The maximum cell value in the raster band.
bool compare(double verifiedVal, double expectedVal, double theTolerance)
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.
The RasterBandStats struct is a container for statistics about a single raster band.
double mean
The mean cell value for the band.
void compareRow(QString theParamName, QString verifiedVal, QString expectedVal, QString &theReport, bool theOk, QString theDifference="", QString theTolerance="")
QgsDataProvider * provider(const QString &providerKey, const QString &dataSource)
Create an instance of the provider.
double value(int row, int column) const
Read a single value if type of block is numeric.
virtual QGis::DataType srcDataType(int bandNo) const =0
Returns source data type for the band specified by number, source data type may be shorter than dataT...
virtual QgsRectangle extent()=0
Get the extent of the data source.
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
bool runTest(QString theVerifiedKey, QString theVerifiedUri, QString theExpectedKey, QString theExpectedUri)
Test using renderer to generate the image to be compared.
void error(QString theMessage, QString &theReport)
double tolerance(double val, int places=6)
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
Base class for raster data providers.