Skip to content

Commit 5d84b26

Browse files
committed
wcs test unit
1 parent 37ab951 commit 5d84b26

File tree

7 files changed

+451
-11
lines changed

7 files changed

+451
-11
lines changed

src/providers/wcs/qgswcscapabilities.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ bool QgsWcsCapabilities::describeCoverage( QString const &identifier, bool force
282282
return false;
283283
}
284284

285-
QgsDebugMsg( "supportedFormat = " + coverage->supportedFormat.join( "," ) );
286-
287285
return true;
288286
}
289287

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

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

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

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

776+
// NULL / no data values
777+
// TODO: handle multiple range sets
778+
foreach( QString text, domElementsTexts( coverageOfferingElement, "rangeSet.RangeSet.nullValue.singleValue" ) )
779+
{
780+
bool ok;
781+
double val = text.toDouble( &ok );
782+
if ( ok )
783+
{
784+
coverage->nullValues.append( val );
785+
}
786+
}
787+
778788
coverage->described = true;
779789

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

861+
// NULL / no data values
862+
// TODO: handle multiple fields / ranges (?)
863+
foreach( QString text, domElementsTexts( docElem, "CoverageDescription.Range.Field.NullValue" ) )
864+
{
865+
bool ok;
866+
double val = text.toDouble( &ok );
867+
if ( ok )
868+
{
869+
coverage->nullValues.append( val );
870+
}
871+
}
872+
851873
coverage->described = true;
852874

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

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

10041025
QgsWcsCoverageSummary c;
10051026
initCoverageSummary( c );
1006-
QgsDebugMsg( "supportedFormat = " + c.supportedFormat.join( "," ) );
10071027
return c;
10081028
}
10091029

src/providers/wcs/qgswcscapabilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct QgsWcsCoverageSummary
4343
QString abstract;
4444
QStringList supportedCrs;
4545
QStringList supportedFormat;
46+
QList<double> nullValues;
4647
QgsRectangle wgs84BoundingBox; // almost useless, we need the native
4748
QString nativeCrs;
4849
// Map of bounding boxes, key is CRS name (srsName), e.g. EPSG:4326

src/providers/wcs/qgswcsprovider.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
9494

9595
mValid = false;
9696

97-
parseUri( uri );
97+
if ( !parseUri( uri ) ) return;
9898

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

128+
// It may happen that format is empty (e.g. uri created in python script),
129+
// in that casei select one from available formats
130+
if ( mFormat.isEmpty() )
131+
{
132+
// TIFF is known by GDAL
133+
mFormat = mCoverageSummary.supportedFormat.filter( "tif", Qt::CaseInsensitive ).value( 0 );
134+
}
135+
if ( mFormat.isEmpty() )
136+
{
137+
// Take the first if TIFF was not found
138+
mFormat = mCoverageSummary.supportedFormat.value( 0 );
139+
}
140+
141+
// We cannot continue without format, it is required
142+
if ( mFormat.isEmpty() ) return;
143+
128144
// It could happen (usually not with current QgsWCSSourceSelect if at least
129145
// one CRS is available) that crs is not set in uri, in that case we
130146
// use the native, if available, or the first supported
@@ -218,6 +234,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
218234
GDALRasterBandH gdalBand = GDALGetRasterBand( mCachedGdalDataset, i );
219235
GDALDataType myGdalDataType = GDALGetRasterDataType( gdalBand );
220236

237+
QgsDebugMsg( QString( "myGdalDataType[%1] = %2" ).arg( i - 1 ).arg( myGdalDataType ) );
221238
mSrcGdalDataType.append( myGdalDataType );
222239
// TODO: This could be shared with GDAL provider
223240
int isValid = false;
@@ -269,6 +286,13 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
269286
}
270287
}
271288
mNoDataValue.append( myNoDataValue );
289+
290+
// TODO: what to do if null values from DescribeCoverage differ?
291+
if ( !mCoverageSummary.nullValues.contains( myNoDataValue ) )
292+
{
293+
QgsDebugMsg( QString( "noDataValue %1 is missing in nullValues from CoverageDescription" ).arg( myNoDataValue ) );
294+
}
295+
272296
mValidNoDataValue = true;
273297

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

301-
void QgsWcsProvider::parseUri( QString uriString )
325+
bool QgsWcsProvider::parseUri( QString uriString )
302326
{
303327

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

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

353+
// TODO: if not defined, use the best available, probably EPSG:4326
329354
setCoverageCrs( uri.param( "crs" ) );
330355
mCrs.createFromOgcWmsCrs( uri.param( "crs" ) );
356+
357+
return true;
331358
}
332359

333360
QString QgsWcsProvider::prepareUri( QString uri ) const

src/providers/wcs/qgswcsprovider.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,9 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
214214
*
215215
* \param uri uri to check
216216
*
217-
* \note added in 1.1
218217
*/
219218

220-
void parseUri( QString uri );
219+
bool parseUri( QString uri );
221220

222221
/**
223222
* \brief Prepare the URI so that we can later simply append param=value

tests/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ IF (ENABLE_TESTS)
22
ADD_SUBDIRECTORY(core)
33
ADD_SUBDIRECTORY(gui)
44
ADD_SUBDIRECTORY(analysis)
5+
ADD_SUBDIRECTORY(providers)
56
ENDIF (ENABLE_TESTS)

tests/src/providers/CMakeLists.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Standard includes and utils to compile into all tests.
2+
3+
#####################################################
4+
# Don't forget to include output directory, otherwise
5+
# the UI file won't be wrapped!
6+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
7+
${CMAKE_CURRENT_BINARY_DIR}
8+
${CMAKE_SOURCE_DIR}/src/core
9+
${CMAKE_SOURCE_DIR}/src/core/raster
10+
${QT_INCLUDE_DIR}
11+
${GDAL_INCLUDE_DIR}
12+
${PROJ_INCLUDE_DIR}
13+
${GEOS_INCLUDE_DIR}
14+
)
15+
16+
#############################################################
17+
# Compiler defines
18+
19+
# This define is used for tests that need to locate the test
20+
# data under tests/testdata in the qgis source tree.
21+
# the TEST_DATA_DIR variable is set in the top level CMakeLists.txt
22+
ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")
23+
24+
ADD_DEFINITIONS(-DINSTALL_PREFIX="\\"${CMAKE_INSTALL_PREFIX}\\"")
25+
#############################################################
26+
# libraries
27+
28+
# because of htonl
29+
IF (WIN32)
30+
SET(PLATFORM_LIBRARIES wsock32)
31+
ENDIF (WIN32)
32+
33+
# Since the tests are not actually installed, but rather
34+
# run directly from the build/src/tests dir we need to
35+
# ensure the qgis libs can be found.
36+
IF (APPLE)
37+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
38+
SET (CMAKE_INSTALL_NAME_DIR @executable_path/../../../src/core)
39+
ENDIF (APPLE)
40+
41+
#note for tests we should not include the moc of our
42+
#qtests in the executable file list as the moc is
43+
#directly included in the sources
44+
#and should not be compiled twice. Trying to include
45+
#them in will cause an error at build time
46+
47+
#No relinking and full RPATH for the install tree
48+
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree
49+
50+
MACRO (ADD_QGIS_TEST testname testsrc)
51+
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
52+
SET(qgis_${testname}_MOC_CPPS ${testsrc})
53+
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
54+
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
55+
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
56+
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
57+
TARGET_LINK_LIBRARIES(qgis_${testname}
58+
${QT_QTXML_LIBRARY}
59+
${QT_QTCORE_LIBRARY}
60+
${QT_QTSVG_LIBRARY}
61+
${QT_QTTEST_LIBRARY}
62+
${PROJ_LIBRARY}
63+
${GEOS_LIBRARY}
64+
${GDAL_LIBRARY}
65+
qgis_core)
66+
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
67+
ENDMACRO (ADD_QGIS_TEST)
68+
69+
#############################################################
70+
# Tests:
71+
72+
ADD_QGIS_TEST(wcsprovidertest testqgswcsprovider.cpp)

0 commit comments

Comments
 (0)