Skip to content

Commit

Permalink
wcs test unit data
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 18, 2012
1 parent 5d84b26 commit d1e7242
Show file tree
Hide file tree
Showing 19 changed files with 433 additions and 28 deletions.
18 changes: 11 additions & 7 deletions src/core/qgsrasterdataprovider.cpp
Expand Up @@ -279,6 +279,7 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )

int myBandXSize = xSize();
int myBandYSize = ySize();
int maxCount = xSize() * ySize();
for ( int iYBlock = 0; iYBlock < myNYBlocks; iYBlock++ )
{
for ( int iXBlock = 0; iXBlock < myNXBlocks; iXBlock++ )
Expand Down Expand Up @@ -306,12 +307,15 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
double myValue = readValue( myData, myDataType, iX + ( iY * myXBlockSize ) );
QgsDebugMsgLevel( QString( "%1 %2 value %3" ).arg( iX ).arg( iY ).arg( myValue ), 10 );

if ( mValidNoDataValue && ( qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) )
if ( mValidNoDataValue &&
( ( std::isnan( myNoDataValue ) && std::isnan( myValue ) ) || qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) )
{
continue; // NULL
}

myRasterBandStats.sum += myValue;
// sum can easily run out of limits
myRasterBandStats.mean += myValue / maxCount;
++myRasterBandStats.elementCount;
//only use this element if we have a non null element
if ( myFirstIterationFlag )
Expand Down Expand Up @@ -342,7 +346,8 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
//end of first pass through data now calculate the range
myRasterBandStats.range = myRasterBandStats.maximumValue - myRasterBandStats.minimumValue;
//calculate the mean
myRasterBandStats.mean = myRasterBandStats.sum / myRasterBandStats.elementCount;
//myRasterBandStats.mean = myRasterBandStats.sum / myRasterBandStats.elementCount;
myRasterBandStats.mean = maxCount * ( myRasterBandStats.mean / myRasterBandStats.elementCount );

//for the second pass we will get the sum of the squares / mean
for ( int iYBlock = 0; iYBlock < myNYBlocks; iYBlock++ )
Expand Down Expand Up @@ -373,21 +378,20 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
double myValue = readValue( myData, myDataType, iX + ( iY * myXBlockSize ) );
//QgsDebugMsg ( "myValue = " + QString::number(myValue) );

if ( mValidNoDataValue && ( qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) )
if ( mValidNoDataValue &&
( ( std::isnan( myNoDataValue ) && std::isnan( myValue ) ) || qAbs( myValue - myNoDataValue ) <= TINY_VALUE ) )
{
continue; // NULL
}

myRasterBandStats.sumOfSquares += static_cast < double >
( pow( myValue - myRasterBandStats.mean, 2 ) );
myRasterBandStats.sumOfSquares += static_cast < double >( pow( myValue - myRasterBandStats.mean, 2 ) );
}
}
} //end of column wise loop
} //end of row wise loop

//divide result by sample size - 1 and get square root to get stdev
myRasterBandStats.stdDev = static_cast < double >( sqrt( myRasterBandStats.sumOfSquares /
( myRasterBandStats.elementCount - 1 ) ) );
myRasterBandStats.stdDev = static_cast < double >( sqrt( myRasterBandStats.sumOfSquares / ( myRasterBandStats.elementCount - 1 ) ) );

#ifdef QGISDEBUG
QgsDebugMsg( "************ STATS **************" );
Expand Down
24 changes: 21 additions & 3 deletions src/providers/wcs/qgswcscapabilities.cpp
Expand Up @@ -192,9 +192,27 @@ bool QgsWcsCapabilities::retrieveServerCapabilities( )
clear();
QStringList versions;

// 1.0.0 - VERSION
// 1.1.0 - AcceptedVersions (not supported by UMN Mapserver 6.0.3 - defaults to 1.1.1
versions << "AcceptVersions=1.1.0,1.0.0" << "VERSION=1.0.0";
QString preferredVersion = mUri.param( "version" );

if ( !preferredVersion.isEmpty() )
{
// This is not
if ( preferredVersion.startsWith ( "1.0" ) )
{
versions << "VERSION=" + preferredVersion;
}
else if ( preferredVersion.startsWith ( "1.1" ) )
{
// Ignored by UMN Mapserver 6.0.3, see below
versions << "AcceptVersions=" + preferredVersion;
}
}
else
{
// 1.0.0 - VERSION
// 1.1.0 - AcceptVersions (not supported by UMN Mapserver 6.0.3 - defaults to latest 1.1
versions << "AcceptVersions=1.1,1.0" << "VERSION=1.0";
}

foreach( QString v, versions )
{
Expand Down
4 changes: 4 additions & 0 deletions tests/src/providers/CMakeLists.txt
Expand Up @@ -22,6 +22,10 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")

ADD_DEFINITIONS(-DINSTALL_PREFIX="\\"${CMAKE_INSTALL_PREFIX}\\"")

SET(TEST_SERVER_URL "http://127.0.0.1/test/${COMPLETE_VERSION}")
ADD_DEFINITIONS(-DTEST_SERVER_URL="\\"${TEST_SERVER_URL}\\"")

#############################################################
# libraries

Expand Down
55 changes: 37 additions & 18 deletions tests/src/providers/testqgswcsprovider.cpp
Expand Up @@ -43,11 +43,12 @@ class TestQgsWcsProvider: public QObject

void read();
private:
bool read( QString identifier, QString theFilePath, QString & theReport );
bool read( QString theIdentifier, QString theWcsUri, QString theFilePath, QString & theReport );
// Log error in html
void error( QString theMessage, QString &theReport );
// compare values and add table row in html report, set ok to false if not equal
QString compareHead();
bool compare ( double wcsVal, double gdalVal, double theTolerance );
void compare( QString theParamName, int wcsVal, int gdalVal, QString &theReport, bool &theOk );
void compare( QString theParamName, double wcsVal, double gdalVal, QString &theReport, bool &theOk, double theTolerance = 0 );
void compareRow( QString theParamName, QString wcsVal, QString gdalVal, QString &theReport, bool theOk, QString theDifference = "", QString theTolerance = "" );
Expand Down Expand Up @@ -82,7 +83,7 @@ void TestQgsWcsProvider::initTestCase()
mTestDataDir = QString( TEST_DATA_DIR ) + QDir::separator() + "raster";
qDebug() << "mTestDataDir = " << mTestDataDir;

mUrl = "http://127.0.0.1//cgi-bin/wcstest";
mUrl = QString( TEST_SERVER_URL ) + QDir::separator() + "wcs";
}

//runs after all tests
Expand All @@ -102,39 +103,52 @@ void TestQgsWcsProvider::cleanupTestCase()
void TestQgsWcsProvider::read( )
{
bool ok = true;
QStringList versions;

versions << "1.0" << "1.1";

QStringList identifiers;

// identifiers in mapfile have the same name as files without .tif extension
identifiers << "band1_byte_noct_epsg4326";
identifiers << "band1_int16_noct_epsg4326";
identifiers << "band1_float32_noct_epsg4326";
identifiers << "band3_byte_noct_epsg4326";
identifiers << "band3_int16_noct_epsg4326";
identifiers << "band3_float32_noct_epsg4326";

// How to reasonably log multiple fails within this loop?
foreach( QString identifier, identifiers )
foreach( QString version, versions )
{
QString filePath = mTestDataDir + QDir::separator() + identifier + ".tif";
if ( !read( identifier, filePath, mReport ) )
foreach( QString identifier, identifiers )
{
ok = false;
QString filePath = mTestDataDir + QDir::separator() + identifier + ".tif";

QgsDataSourceURI uri;
uri.setParam( "url", mUrl );
uri.setParam( "identifier", identifier );
uri.setParam( "crs", "epsg:4326" );
uri.setParam( "version", version );

if ( !read( identifier, uri.encodedUri(), filePath, mReport ) )
{
ok = false;
}
}
}
QVERIFY2( ok, "Reading data failed. See report for details." );
}

bool TestQgsWcsProvider::read( QString theIdentifier, QString theFilePath, QString & theReport )
bool TestQgsWcsProvider::read( QString theIdentifier, QString theWcsUri, QString theFilePath, QString & theReport )
{
bool ok = true;
QgsDataSourceURI uri;
uri.setParam( "url", mUrl );
uri.setParam( "identifier", theIdentifier );
uri.setParam( "crs", "epsg:4326" );

theReport += QString( "<h2>Identifier (coverage): %1</h2>" ).arg( theIdentifier );

QgsRasterDataProvider* wcsProvider = QgsRasterLayer::loadProvider( "wcs", uri.encodedUri() );
QgsRasterDataProvider* wcsProvider = QgsRasterLayer::loadProvider( "wcs", theWcsUri );
if ( !wcsProvider || !wcsProvider->isValid() )
{
error( QString( "Cannot load WCS provider with URI: %1" ).arg( QString( uri.encodedUri() ) ), theReport );
error( QString( "Cannot load WCS provider with URI: %1" ).arg( QString( theWcsUri ) ), theReport );
ok = false;
}

Expand All @@ -147,7 +161,7 @@ bool TestQgsWcsProvider::read( QString theIdentifier, QString theFilePath, QStri

if ( !ok ) return false;

theReport += QString( "WCS URI: %1<br>" ).arg( QString( uri.encodedUri() ).replace( "&", "&amp;" ) );
theReport += QString( "WCS URI: %1<br>" ).arg( theWcsUri.replace( "&", "&amp;" ) );
theReport += QString( "GDAL URI: %1<br>" ).arg( theFilePath );

theReport += "<br>";
Expand Down Expand Up @@ -212,7 +226,7 @@ bool TestQgsWcsProvider::read( QString theIdentifier, QString theFilePath, QStri
continue;
}

if ( !statsOk || typesOk )
if ( !statsOk || !typesOk )
{
allOk = false;
// create values table anyway so that values are available
Expand Down Expand Up @@ -247,7 +261,7 @@ bool TestQgsWcsProvider::read( QString theIdentifier, QString theFilePath, QStri
double gdalVal = gdalProvider->readValue( gdalData, gdalProvider->dataType( band ), row * width + col );

QString valStr;
if ( wcsVal == gdalVal )
if ( compare ( wcsVal, gdalVal, 0 ) )
{
valStr = QString( "%1" ).arg( wcsVal );
}
Expand Down Expand Up @@ -299,10 +313,15 @@ void TestQgsWcsProvider::compare( QString theParamName, int wcsVal, int gdalVal,
if ( !ok ) theOk = false;
}

void TestQgsWcsProvider::compare( QString theParamName, double wcsVal, double gdalVal, QString &theReport, bool &theOk, double theTolerance )
bool TestQgsWcsProvider::compare ( double wcsVal, double gdalVal, double theTolerance )
{
bool ok = ( qAbs( wcsVal - gdalVal ) <= theTolerance );
// values may be nan
return ( std::isnan( wcsVal ) && std::isnan( gdalVal ) ) || ( qAbs( wcsVal - gdalVal ) <= theTolerance );
}

void TestQgsWcsProvider::compare( QString theParamName, double wcsVal, double gdalVal, QString &theReport, bool &theOk, double theTolerance )
{
bool ok = compare ( wcsVal, gdalVal, theTolerance );
compareRow( theParamName, QString::number( wcsVal ), QString::number( gdalVal ), theReport, ok, QString::number( wcsVal - gdalVal ), QString::number( theTolerance ) );
if ( !ok ) theOk = false;
}
Expand Down
Binary file added tests/testdata/raster/band1_byte_ct_epsg4326.tif
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/testdata/raster/band1_byte_ct_epsg4326.tif.aux.xml
@@ -0,0 +1,13 @@
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">2.000000e+00 1.280000e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">1.280000e+02 2.540000e+02 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">254</MDI>
<MDI key="STATISTICS_MEAN">135.53086419753</MDI>
<MDI key="STATISTICS_MINIMUM">2</MDI>
<MDI key="STATISTICS_STDDEV">73.957459647589</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/testdata/raster/band1_byte_noct_epsg4326.tif.aux.xml
@@ -0,0 +1,13 @@
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">2.000000e+00 1.280000e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">1.280000e+02 2.540000e+02 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">254</MDI>
<MDI key="STATISTICS_MEAN">135.53086419753</MDI>
<MDI key="STATISTICS_MINIMUM">2</MDI>
<MDI key="STATISTICS_STDDEV">73.957459647589</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/testdata/raster/band1_float32_noct_epsg4326.tif.aux.xml
@@ -0,0 +1,12 @@
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">0.000000e+00 0.000000e+00 255 127 0 255 127 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">1</MDI>
<MDI key="STATISTICS_MAXIMUM">3.3999999521444e+38</MDI>
<MDI key="STATISTICS_MEAN">2.4177777984595e+37</MDI>
<MDI key="STATISTICS_MINIMUM">-3.3319999287626e+38</MDI>
<MDI key="STATISTICS_STDDEV">1.9800745699579e+38</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/testdata/raster/band1_int16_noct_epsg4326.tif.aux.xml
@@ -0,0 +1,13 @@
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">-3.211166e+04 3.276700e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">3.276700e+02 3.276700e+04 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">32767</MDI>
<MDI key="STATISTICS_MEAN">2330.024691358</MDI>
<MDI key="STATISTICS_MINIMUM">-32111</MDI>
<MDI key="STATISTICS_STDDEV">19082.231766347</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
Binary file not shown.
35 changes: 35 additions & 0 deletions tests/testdata/raster/band3_byte_noct_epsg4326.tif.aux.xml
@@ -0,0 +1,35 @@
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">2.000000e+00 1.280000e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">1.280000e+02 2.540000e+02 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">254</MDI>
<MDI key="STATISTICS_MEAN">135.53086419753</MDI>
<MDI key="STATISTICS_MINIMUM">2</MDI>
<MDI key="STATISTICS_STDDEV">73.957459647589</MDI>
</Metadata>
</PAMRasterBand>
<PAMRasterBand band="2">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">2.000000e+00 1.280000e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">1.280000e+02 2.540000e+02 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">254</MDI>
<MDI key="STATISTICS_MEAN">135.53086419753</MDI>
<MDI key="STATISTICS_MINIMUM">2</MDI>
<MDI key="STATISTICS_STDDEV">73.957459647589</MDI>
</Metadata>
</PAMRasterBand>
<PAMRasterBand band="3">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">2.000000e+00 1.280000e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">1.280000e+02 2.540000e+02 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">254</MDI>
<MDI key="STATISTICS_MEAN">135.53086419753</MDI>
<MDI key="STATISTICS_MINIMUM">2</MDI>
<MDI key="STATISTICS_STDDEV">73.957459647589</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
Binary file not shown.
32 changes: 32 additions & 0 deletions tests/testdata/raster/band3_float32_noct_epsg4326.tif.aux.xml
@@ -0,0 +1,32 @@
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">0.000000e+00 0.000000e+00 255 127 0 255 127 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">1</MDI>
<MDI key="STATISTICS_MAXIMUM">3.3999999521444e+38</MDI>
<MDI key="STATISTICS_MEAN">2.4177777984595e+37</MDI>
<MDI key="STATISTICS_MINIMUM">-3.3319999287626e+38</MDI>
<MDI key="STATISTICS_STDDEV">1.9800745699579e+38</MDI>
</Metadata>
</PAMRasterBand>
<PAMRasterBand band="2">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">0.000000e+00 0.000000e+00 255 127 0 255 127 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">1</MDI>
<MDI key="STATISTICS_MAXIMUM">3.3999999521444e+38</MDI>
<MDI key="STATISTICS_MEAN">2.4177777984595e+37</MDI>
<MDI key="STATISTICS_MINIMUM">-3.3319999287626e+38</MDI>
<MDI key="STATISTICS_STDDEV">1.9800745699579e+38</MDI>
</Metadata>
</PAMRasterBand>
<PAMRasterBand band="3">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">0.000000e+00 0.000000e+00 255 127 0 255 127 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">1</MDI>
<MDI key="STATISTICS_MAXIMUM">3.3999999521444e+38</MDI>
<MDI key="STATISTICS_MEAN">2.4177777984595e+37</MDI>
<MDI key="STATISTICS_MINIMUM">-3.3319999287626e+38</MDI>
<MDI key="STATISTICS_STDDEV">1.9800745699579e+38</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>
Binary file not shown.
35 changes: 35 additions & 0 deletions tests/testdata/raster/band3_int16_noct_epsg4326.tif.aux.xml
@@ -0,0 +1,35 @@
<PAMDataset>
<PAMRasterBand band="1">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">-3.211166e+04 3.276700e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">3.276700e+02 3.276700e+04 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">32767</MDI>
<MDI key="STATISTICS_MEAN">2330.024691358</MDI>
<MDI key="STATISTICS_MINIMUM">-32111</MDI>
<MDI key="STATISTICS_STDDEV">19082.231766347</MDI>
</Metadata>
</PAMRasterBand>
<PAMRasterBand band="2">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">-3.211166e+04 3.276700e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">3.276700e+02 3.276700e+04 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">32767</MDI>
<MDI key="STATISTICS_MEAN">2330.024691358</MDI>
<MDI key="STATISTICS_MINIMUM">-32111</MDI>
<MDI key="STATISTICS_STDDEV">19082.231766347</MDI>
</Metadata>
</PAMRasterBand>
<PAMRasterBand band="3">
<Metadata>
<MDI key="COLOR_TABLE_RULE_RGB_0">-3.211166e+04 3.276700e+02 0 255 0 255 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">3.276700e+02 3.276700e+04 255 255 0 255 0 0</MDI>
<MDI key="COLOR_TABLE_RULES_COUNT">2</MDI>
<MDI key="STATISTICS_MAXIMUM">32767</MDI>
<MDI key="STATISTICS_MEAN">2330.024691358</MDI>
<MDI key="STATISTICS_MINIMUM">-32111</MDI>
<MDI key="STATISTICS_STDDEV">19082.231766347</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>

0 comments on commit d1e7242

Please sign in to comment.