Skip to content

Commit bf5d8d1

Browse files
committed
WCS URI description, fixes
1 parent 09bd0f6 commit bf5d8d1

File tree

4 files changed

+94
-6
lines changed

4 files changed

+94
-6
lines changed

python/core/qgsdatasourceuri.sip

+35
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,41 @@ public:
2929

3030
//! quoted table name
3131
QString quotedTablename() const;
32+
33+
//! return complete encoded uri (generic mode)
34+
// \note added in 1.9
35+
QByteArray encodedUri() const;
36+
37+
//! set complete encoded uri (generic mode)
38+
// \note added in 1.9
39+
void setEncodedUri( const QByteArray & uri );
40+
41+
//! set complete encoded uri (generic mode)
42+
// \note added in 1.9
43+
void setEncodedUri( const QString & uri );
44+
45+
//! Set generic param (generic mode)
46+
// \note if key exists, another is inserted
47+
// \note added in 1.9
48+
void setParam( const QString &key, const QString &value );
49+
void setParam( const QString &key, const QStringList &value );
50+
51+
//! Remove generic param (generic mode)
52+
// \note remove all occurrences of key, returns number of params removed
53+
// \note added in 1.9
54+
int removeParam( const QString &key );
55+
56+
//! Get generic param (generic mode)
57+
// \note added in 1.9
58+
QString param( const QString &key ) const;
59+
60+
//! Get multiple generic param (generic mode)
61+
// \note added in 1.9
62+
QStringList params( const QString &key ) const;
63+
64+
//! Test if param exists (generic mode)
65+
// \note added in 1.9
66+
bool hasParam( const QString &key ) const;
3267

3368
//! Set all connection related members at once
3469
//! \note This optional sslmode parameter has been added in version 1.1

src/providers/wcs/URI

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
WCS URI
2+
-------
3+
4+
Example: url=http://127.0.0.1/wcs&identifier=coverage1
5+
6+
WCS URI is composed of key=value pairs separated by '&'. It is the same format like query string in URL, encoded the same way. QgsDataSourceURI should be used to construct the URI to ensure that special characters are encoded properly.
7+
8+
Parameters:
9+
10+
* url (required) : WCS Server URL. Do not use VERSION in URL, because each version of WCS is using different parameter name for GetCapabilities version, see param version.
11+
12+
* identifier (required) : Coverage name
13+
14+
* format: (optional) : Supported format name. Default is the first supported format with tif in name or the first supported format.
15+
16+
* crs (optional) : CRS in form AUTHORITY:ID, e.g. EPSG:4326. Default is EPSG:4326 if supported or the first supported CRS.
17+
18+
* username (optional) : Username for basic authentication.
19+
20+
* password (optional) : Password for basic authentication.
21+
22+
* IgnoreGetMapUrl (optional,hack) : If specified (set to 1), ignore GetCoverage URL advertised by GetCapabilities. May be necessary if a server is not configured properly.
23+
24+
* InvertAxisOrientation (optional,hack) : If specified (set to 1), switch axis in GetCoverage request. May be necessary for geographic CRS if a server is using wrong axis order.
25+
26+
* IgnoreAxisOrientation (optional,hack) : If specified (set to 1), do not invert axis orientation according to WCS standard for geographic CRS.
27+
28+
29+
Python console example:
30+
31+
from PyQt4.QtCore import QString
32+
33+
uri = QgsDataSourceURI()
34+
uri.setParam ("url", "http://wcs.qgis.org/1.9.0/wcs" )
35+
uri.setParam ( "identifier", "band1_int16_noct_epsg4326" )
36+
37+
layer = QgsRasterLayer( QString(uri.encodedUri()), "WCS test", "wcs" )
38+
layer.isValid()
39+
40+
QgsMapLayerRegistry.instance().addMapLayer(layer)
41+

src/providers/wcs/qgswcsprovider.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
7171
: QgsRasterDataProvider( uri )
7272
, QgsGdalProviderBase()
7373
, mHttpUri( QString::null )
74-
, mCoverageCrs( DEFAULT_LATLON_CRS )
74+
, mCoverageCrs()
7575
, mCacheReply( 0 )
7676
, mCachedViewExtent( 0 )
7777
, mCoordinateTransform( 0 )
@@ -143,18 +143,27 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
143143

144144
// It could happen (usually not with current QgsWCSSourceSelect if at least
145145
// one CRS is available) that crs is not set in uri, in that case we
146-
// use the native, if available, or the first supported
146+
// use the native, if available or WGS84 or the first supported
147147
if ( mCoverageCrs.isEmpty() )
148148
{
149+
QgsDebugMsg( "nativeCrs = " + mCoverageSummary.nativeCrs );
150+
QgsDebugMsg( "supportedCrs = " + mCoverageSummary.supportedCrs.join( "," ) );
149151
if ( !mCoverageSummary.nativeCrs.isEmpty() )
150152
{
151153
setCoverageCrs( mCoverageSummary.nativeCrs );
152154
}
155+
else if ( mCoverageSummary.supportedCrs.contains( "EPSG:4326", Qt::CaseInsensitive ) )
156+
{
157+
setCoverageCrs( "EPSG:4326" );
158+
}
153159
else if ( mCoverageSummary.supportedCrs.size() > 0 )
154160
{
155161
setCoverageCrs( mCoverageSummary.supportedCrs.value( 0 ) );
156162
}
157163
}
164+
QgsDebugMsg( "mCoverageCrs = " + mCoverageCrs );
165+
// We cannot continue without CRS
166+
if ( mCoverageCrs.isEmpty() ) return;
158167

159168
mWidth = mCoverageSummary.width;
160169
mHeight = mCoverageSummary.height;
@@ -350,9 +359,10 @@ bool QgsWcsProvider::parseUri( QString uriString )
350359

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

353-
// TODO: if not defined, use the best available, probably EPSG:4326
354-
setCoverageCrs( uri.param( "crs" ) );
355-
mCrs.createFromOgcWmsCrs( uri.param( "crs" ) );
362+
if ( !uri.param( "crs" ).isEmpty() )
363+
{
364+
setCoverageCrs( uri.param( "crs" ) );
365+
}
356366

357367
return true;
358368
}
@@ -424,6 +434,8 @@ void QgsWcsProvider::setCoverageCrs( QString const & crs )
424434
mExtentDirty = true;
425435

426436
mCoverageCrs = crs;
437+
438+
mCrs.createFromOgcWmsCrs( mCoverageCrs );
427439
}
428440
}
429441

tests/src/providers/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")
2323
2424
ADD_DEFINITIONS(-DINSTALL_PREFIX="\\"${CMAKE_INSTALL_PREFIX}\\"")
2525
26-
SET(TEST_SERVER_URL "http://127.0.0.1/test/${COMPLETE_VERSION}")
26+
SET(TEST_SERVER_URL "http://wcs.qgis.org/${COMPLETE_VERSION}")
2727
ADD_DEFINITIONS(-DTEST_SERVER_URL="\\"${TEST_SERVER_URL}\\"")
2828
2929
#############################################################

0 commit comments

Comments
 (0)