Skip to content
Permalink
Browse files

wcs test unit

  • Loading branch information
blazek committed Jul 18, 2012
1 parent 37ab951 commit 5d84b260066542a71ac62d959a930d1fe20ba4ff
@@ -282,8 +282,6 @@ bool QgsWcsCapabilities::describeCoverage( QString const &identifier, bool force
return false;
}

QgsDebugMsg( "supportedFormat = " + coverage->supportedFormat.join( "," ) );

return true;
}

@@ -696,13 +694,13 @@ bool QgsWcsCapabilities::parseDescribeCoverageDom10( QByteArray const &xml, QgsW
// requestResponseCRSs and requestCRSs + responseCRSs are alternatives
coverage->supportedCrs = domElementsTexts( coverageOfferingElement, "supportedCRSs.requestResponseCRSs" );
// TODO: requestCRSs, responseCRSs - must be then implemented also in provider
QgsDebugMsg( "supportedCrs = " + coverage->supportedCrs.join( "," ) );
//QgsDebugMsg( "supportedCrs = " + coverage->supportedCrs.join( "," ) );

coverage->nativeCrs = domElementText( coverageOfferingElement, "supportedCRSs.nativeCRSs" );

// may be GTiff, GeoTIFF, TIFF, GIF, ....
coverage->supportedFormat = domElementsTexts( coverageOfferingElement, "supportedFormats.formats" );
QgsDebugMsg( "supportedFormat = " + coverage->supportedFormat.join( "," ) );
//QgsDebugMsg( "supportedFormat = " + coverage->supportedFormat.join( "," ) );

// spatialDomain and Grid/RectifiedGrid are optional according to specificationi.
// If missing, we cannot get native resolution and size.
@@ -775,6 +773,18 @@ bool QgsWcsCapabilities::parseDescribeCoverageDom10( QByteArray const &xml, QgsW
}
}

// NULL / no data values
// TODO: handle multiple range sets
foreach( QString text, domElementsTexts( coverageOfferingElement, "rangeSet.RangeSet.nullValue.singleValue" ) )
{
bool ok;
double val = text.toDouble( &ok );
if ( ok )
{
coverage->nullValues.append( val );
}
}

coverage->described = true;

return true;
@@ -848,6 +858,18 @@ bool QgsWcsCapabilities::parseDescribeCoverageDom11( QByteArray const &xml, QgsW
// if urn:ogc:def:crs:OGC::imageCRS BoundingBox was not found
}

// NULL / no data values
// TODO: handle multiple fields / ranges (?)
foreach( QString text, domElementsTexts( docElem, "CoverageDescription.Range.Field.NullValue" ) )
{
bool ok;
double val = text.toDouble( &ok );
if ( ok )
{
coverage->nullValues.append( val );
}
}

coverage->described = true;

return true;
@@ -894,7 +916,7 @@ void QgsWcsCapabilities::parseCoverageSummary( QDomElement const & e, QgsWcsCove
}
n1 = n1.nextSibling();
}
QgsDebugMsg( "supportedFormat = " + coverageSummary.supportedFormat.join( "," ) );
//QgsDebugMsg( "supportedFormat = " + coverageSummary.supportedFormat.join( "," ) );

// We collected params to be inherited, do children
n1 = e.firstChild();
@@ -998,12 +1020,10 @@ void QgsWcsCapabilities::showMessageBox( const QString& title, const QString& te
QgsWcsCoverageSummary QgsWcsCapabilities::coverage( QString const & theIdentifier )
{
QgsWcsCoverageSummary * cp = coverageSummary( theIdentifier );
QgsDebugMsg( "supportedFormat = " + ( *cp ).supportedFormat.join( "," ) );
if ( cp ) return *cp;

QgsWcsCoverageSummary c;
initCoverageSummary( c );
QgsDebugMsg( "supportedFormat = " + c.supportedFormat.join( "," ) );
return c;
}

@@ -43,6 +43,7 @@ struct QgsWcsCoverageSummary
QString abstract;
QStringList supportedCrs;
QStringList supportedFormat;
QList<double> nullValues;
QgsRectangle wgs84BoundingBox; // almost useless, we need the native
QString nativeCrs;
// Map of bounding boxes, key is CRS name (srsName), e.g. EPSG:4326
@@ -94,7 +94,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )

mValid = false;

parseUri( uri );
if ( !parseUri( uri ) ) return;

// GetCapabilities and DescribeCoverage
// TODO(?): do only DescribeCoverage to avoid one request
@@ -125,6 +125,22 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
return;
}

// It may happen that format is empty (e.g. uri created in python script),
// in that casei select one from available formats
if ( mFormat.isEmpty() )
{
// TIFF is known by GDAL
mFormat = mCoverageSummary.supportedFormat.filter( "tif", Qt::CaseInsensitive ).value( 0 );
}
if ( mFormat.isEmpty() )
{
// Take the first if TIFF was not found
mFormat = mCoverageSummary.supportedFormat.value( 0 );
}

// We cannot continue without format, it is required
if ( mFormat.isEmpty() ) return;

// It could happen (usually not with current QgsWCSSourceSelect if at least
// one CRS is available) that crs is not set in uri, in that case we
// use the native, if available, or the first supported
@@ -218,6 +234,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
GDALRasterBandH gdalBand = GDALGetRasterBand( mCachedGdalDataset, i );
GDALDataType myGdalDataType = GDALGetRasterDataType( gdalBand );

QgsDebugMsg( QString( "myGdalDataType[%1] = %2" ).arg( i - 1 ).arg( myGdalDataType ) );
mSrcGdalDataType.append( myGdalDataType );
// TODO: This could be shared with GDAL provider
int isValid = false;
@@ -269,6 +286,13 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
}
}
mNoDataValue.append( myNoDataValue );

// TODO: what to do if null values from DescribeCoverage differ?
if ( !mCoverageSummary.nullValues.contains( myNoDataValue ) )
{
QgsDebugMsg( QString( "noDataValue %1 is missing in nullValues from CoverageDescription" ).arg( myNoDataValue ) );
}

mValidNoDataValue = true;

QgsDebugMsg( QString( "mSrcGdalDataType[%1] = %2" ).arg( i - 1 ).arg( mSrcGdalDataType[i-1] ) );
@@ -298,7 +322,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
QgsDebugMsg( "Constructed ok, provider valid." );
}

void QgsWcsProvider::parseUri( QString uriString )
bool QgsWcsProvider::parseUri( QString uriString )
{

QgsDebugMsg( "uriString = " + uriString );
@@ -326,8 +350,11 @@ void QgsWcsProvider::parseUri( QString uriString )

setFormat( uri.param( "format" ) );

// TODO: if not defined, use the best available, probably EPSG:4326
setCoverageCrs( uri.param( "crs" ) );
mCrs.createFromOgcWmsCrs( uri.param( "crs" ) );

return true;
}

QString QgsWcsProvider::prepareUri( QString uri ) const
@@ -214,10 +214,9 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
*
* \param uri uri to check
*
* \note added in 1.1
*/

void parseUri( QString uri );
bool parseUri( QString uri );

/**
* \brief Prepare the URI so that we can later simply append param=value
@@ -2,4 +2,5 @@ IF (ENABLE_TESTS)
ADD_SUBDIRECTORY(core)
ADD_SUBDIRECTORY(gui)
ADD_SUBDIRECTORY(analysis)
ADD_SUBDIRECTORY(providers)
ENDIF (ENABLE_TESTS)
@@ -0,0 +1,72 @@
# Standard includes and utils to compile into all tests.

#####################################################
# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/raster
${QT_INCLUDE_DIR}
${GDAL_INCLUDE_DIR}
${PROJ_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
)

#############################################################
# Compiler defines

# This define is used for tests that need to locate the test
# data under tests/testdata in the qgis source tree.
# the TEST_DATA_DIR variable is set in the top level CMakeLists.txt
ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")

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

# because of htonl
IF (WIN32)
SET(PLATFORM_LIBRARIES wsock32)
ENDIF (WIN32)

# Since the tests are not actually installed, but rather
# run directly from the build/src/tests dir we need to
# ensure the qgis libs can be found.
IF (APPLE)
# For Mac OS X, the executable must be at the root of the bundle's executable folder
SET (CMAKE_INSTALL_NAME_DIR @executable_path/../../../src/core)
ENDIF (APPLE)

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time

#No relinking and full RPATH for the install tree
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree

MACRO (ADD_QGIS_TEST testname testsrc)
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
SET(qgis_${testname}_MOC_CPPS ${testsrc})
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
TARGET_LINK_LIBRARIES(qgis_${testname}
${QT_QTXML_LIBRARY}
${QT_QTCORE_LIBRARY}
${QT_QTSVG_LIBRARY}
${QT_QTTEST_LIBRARY}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
qgis_core)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
ENDMACRO (ADD_QGIS_TEST)

#############################################################
# Tests:

ADD_QGIS_TEST(wcsprovidertest testqgswcsprovider.cpp)

0 comments on commit 5d84b26

Please sign in to comment.
You can’t perform that action at this time.