Skip to content

Commit 866fa9c

Browse files
committed
WCS better version support
1 parent 58c3774 commit 866fa9c

8 files changed

+118
-394
lines changed

src/gui/qgsowssourceselect.cpp

+32-307
Large diffs are not rendered by default.

src/gui/qgsowssourceselect.h

+26-28
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
105105

106106
void on_mDialogButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
107107

108+
signals:
109+
void addRasterLayer( QString const & rasterLayerPath,
110+
QString const & baseName,
111+
QString const & providerKey );
112+
void connectionsChanged();
113+
108114
protected:
109115
/**
110116
* List of image formats (encodings) supported by provider
@@ -113,12 +119,12 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
113119
virtual QList<QgsOWSSupportedFormat> providerFormats();
114120

115121
//! List of formats supported for currently selected layer item(s)
116-
virtual QStringList serverFormats();
122+
virtual QStringList selectedLayersFormats();
117123

118124
//! Server CRS supported for currently selected layer item(s)
119-
virtual QStringList serverCRS();
125+
virtual QStringList selectedLayersCRSs();
120126

121-
virtual QStringList layerCRS( int id );
127+
//virtual QStringList layerCRS( int id );
122128

123129
//! Populate the connection list combo box
124130
void populateConnectionList();
@@ -150,25 +156,13 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
150156
//! Embedded mode, without 'Close'
151157
bool mEmbeddedMode;
152158

153-
//! Selected CRS
154-
QString mCRS;
155-
156-
//! Common CRSs for selected layers
157-
QSet<QString> mCRSs;
158-
159-
//! Supported formats
160-
QList<QgsOWSSupportedFormat> mProviderFormats;
161-
162-
//! Map mime types to supported formats
163-
QMap<QString, int> mMimeMap;
164159

165160
/**
166-
* \brief Populate the layer list - private for now.
161+
* \brief Populate the layer list.
167162
*
168-
* \retval false if the layers could not be retrieved or parsed -
169-
* see mWmsProvider->errorString() for more info
163+
* \retval false if the layers could not be retrieved or parsed
170164
*/
171-
virtual bool populateLayerList( );
165+
virtual void populateLayerList( );
172166

173167
//! create an item including possible parents
174168
QgsNumericSortTreeWidgetItem *createItem( int id,
@@ -194,26 +188,17 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
194188
void addWMSListRow( const QDomElement& item, int row );
195189
void addWMSListItem( const QDomElement& el, int row, int column );
196190

197-
void applySelectionConstraints( QTreeWidgetItem *item );
198-
void collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles );
199191
virtual void enableLayersForCrs( QTreeWidgetItem *item );
200192

201193
//! Returns currently selected format
202194
QString selectedFormat();
203195

204196
//! Returns currently selected Crs
205-
QString selectedCrs();
197+
QString selectedCRS();
206198

207199
QList<QTreeWidgetItem*> mCurrentSelection;
208200
QTableWidgetItem* mCurrentTileset;
209201

210-
signals:
211-
void addRasterLayer( QString const & rasterLayerPath,
212-
QString const & baseName,
213-
QString const & providerKey );
214-
void connectionsChanged();
215-
216-
protected:
217202
//! Name for selected connection
218203
QString mConnName;
219204

@@ -223,6 +208,19 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
223208
//! URI for selected connection
224209
QgsDataSourceURI mUri;
225210

211+
private:
212+
//! Selected CRS
213+
QString mSelectedCRS;
214+
215+
//! Common CRSs for selected layers
216+
QSet<QString> mSelectedLayersCRSs;
217+
218+
//! Supported formats
219+
QList<QgsOWSSupportedFormat> mProviderFormats;
220+
221+
//! Map mime types to supported formats
222+
QMap<QString, int> mMimeMap;
223+
226224
private slots:
227225
void on_mSearchButton_clicked();
228226
void on_mAddWMSButton_clicked();

src/providers/gdal/qgsgdalprovider.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <QFile>
4343
#include <QHash>
4444
#include <QTime>
45+
#include <QTextDocument>
4546

4647
#include "gdalwarper.h"
4748
#include "ogr_spatialref.h"
@@ -112,18 +113,21 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
112113
if ( uri.contains("url=") && uri.contains("identifier=") && !QFile::exists(uri) )
113114
{
114115
// WCS
116+
// GDAL currently (4/2012) supports WCS 1.0.0 (default) and 1.1.0
117+
//
115118
QgsDataSourceURI dsUri;
116119
dsUri.setEncodedUri( uri );
117120
gdalUri = "<WCS_GDAL>";
118121
// prepareUri adds ? or & if necessary, GDAL fails otherwise
119-
gdalUri += "<ServiceURL>" + QgsWcsCapabilities::prepareUri( dsUri.param("url") ) + "</ServiceURL>";
122+
gdalUri += "<ServiceURL>" + Qt::escape( QgsWcsCapabilities::prepareUri( dsUri.param("url") ) ) + "</ServiceURL>";
120123
gdalUri += "<CoverageName>" + dsUri.param("identifier") + "</CoverageName>";
121124
gdalUri += "<PreferredFormat>" + dsUri.param("format") + "</PreferredFormat>";
122125

123126
// TODO: There is no tag for CRS response.
124127
// There is undocumented CRS tag, but it only overrides CRS param in requests
125128
// but BBOX is left unchanged and thus results in server error (usually).
126129
gdalUri += "<GetCoverageExtra>&amp;RESPONSE_CRS=" + dsUri.param("crs") + "</GetCoverageExtra>";
130+
127131
if ( dsUri.hasParam("username") && dsUri.hasParam("password") )
128132
{
129133
gdalUri += "<UserPwd>" + dsUri.param("username") + ":" + dsUri.param("password") + "</UserPwd>";

src/providers/gdal/qgswcscapabilities.cpp

+32-7
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,17 @@ bool QgsWcsCapabilities::retrieveServerCapabilities( bool forceRefresh )
166166

167167
if ( mCapabilitiesResponse.isNull() || forceRefresh )
168168
{
169-
// TODO: version
170-
QString url = prepareUri( mUri.param("url") ) + "SERVICE=WCS&REQUEST=GetCapabilities";
169+
// Check if user tried to force version
170+
QString userVersion = QUrl( mUri.param("url") ).queryItemValue("VERSION");
171+
if ( !userVersion.isEmpty() && !userVersion.startsWith("1.1.") )
172+
{
173+
mErrorTitle = tr( "Version not supported" );
174+
mErrorFormat = "text/plain";
175+
mError = tr( "The version %1 specified in connection URL parameter VERSION is not supported by QGIS" ).arg( userVersion );
176+
return false;
177+
}
178+
179+
QString url = prepareUri( mUri.param("url") ) + "SERVICE=WCS&REQUEST=GetCapabilities&VERSION=1.1.0";
171180

172181
mError = "";
173182

@@ -213,7 +222,7 @@ bool QgsWcsCapabilities::retrieveServerCapabilities( bool forceRefresh )
213222
if ( !domOK )
214223
{
215224
// We had an Dom exception -
216-
// mErrorCaption and mError are pre-filled by parseCapabilitiesDom
225+
// mErrorTitle and mError are pre-filled by parseCapabilitiesDom
217226

218227
mError += tr( "\nTried URL: %1" ).arg( url );
219228

@@ -305,7 +314,7 @@ bool QgsWcsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapa
305314

306315
if ( !contentSuccess )
307316
{
308-
mErrorCaption = tr( "Dom Exception" );
317+
mErrorTitle = tr( "Dom Exception" );
309318
mErrorFormat = "text/plain";
310319
mError = tr( "Could not get WCS capabilities: %1 at line %2 column %3\nThis is probably due to an incorrect WMS Server URL.\nResponse was:\n\n%4" )
311320
.arg( errorMsg )
@@ -324,10 +333,12 @@ bool QgsWcsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapa
324333
QgsDebugMsg( "testing tagName " + docElem.tagName() );
325334

326335
if (
327-
docElem.tagName() != "Capabilities"
336+
// We don't support 1.0, but try WCS_Capabilities tag to get version
337+
docElem.tagName() != "WCS_Capabilities" && // 1.0
338+
docElem.tagName() != "Capabilities" // 1.1
328339
)
329340
{
330-
mErrorCaption = tr( "Dom Exception" );
341+
mErrorTitle = tr( "Dom Exception" );
331342
mErrorFormat = "text/plain";
332343
mError = tr( "Could not get WCS capabilities in the expected format (DTD): no %1 found.\nThis might be due to an incorrect WMS Server URL.\nTag:%3\nResponse was:\n%4" )
333344
.arg( "Capabilities" )
@@ -340,6 +351,20 @@ bool QgsWcsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapa
340351
}
341352

342353
capabilities.version = docElem.attribute( "version" );
354+
mVersion = capabilities.version;
355+
356+
if ( !mVersion.startsWith("1.1.") )
357+
{
358+
mErrorTitle = tr( "Version not supported" );
359+
mErrorFormat = "text/plain";
360+
mError = tr( "Could not get WCS capabilities in the expected version 1.1.\nResponse version was: %1" )
361+
.arg( mVersion );
362+
363+
QgsLogger::debug( "WCS version: " + mError );
364+
365+
return false;
366+
}
367+
343368

344369
// Start walking through XML.
345370
QDomNode n = docElem.firstChild();
@@ -618,7 +643,7 @@ void QgsWcsCapabilities::coverageParents( QMap<int, int> &parents, QMap<int, QSt
618643

619644
QString QgsWcsCapabilities::lastErrorTitle()
620645
{
621-
return mErrorCaption;
646+
return mErrorTitle;
622647
}
623648

624649
QString QgsWcsCapabilities::lastError()

src/providers/gdal/qgswcscapabilities.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ class QgsWcsCapabilities : public QObject
301301
//! URL part of URI (httpuri)
302302
//QString mBaseUrl;
303303

304+
//! Response capabilities version
305+
QString mVersion;
306+
304307
/**
305308
* Capabilities of the WCS Server (raw)
306309
*/
@@ -349,7 +352,7 @@ class QgsWcsCapabilities : public QObject
349352
/**
350353
* The error caption associated with the last WCS error.
351354
*/
352-
QString mErrorCaption;
355+
QString mErrorTitle;
353356

354357
/**
355358
* The error message associated with the last WCS error.

src/providers/gdal/qgswcssourceselect.cpp

+13-27
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,21 @@ QgsWCSSourceSelect::~QgsWCSSourceSelect()
5454
{
5555
}
5656

57-
bool QgsWCSSourceSelect::populateLayerList( )
57+
void QgsWCSSourceSelect::populateLayerList( )
5858
{
5959
QgsDebugMsg( "entered" );
60-
// mCRSs.clear();
61-
62-
// TODO: showError
6360

6461
mCapabilities.setUri ( mUri );
6562

63+
if ( !mCapabilities.lastError().isEmpty() )
64+
{
65+
showError( mCapabilities.lastErrorTitle(), mCapabilities.lastErrorFormat(), mCapabilities.lastError() );
66+
return;
67+
}
68+
6669
QVector<QgsWcsCoverageSummary> coverages;
6770
if ( !mCapabilities.supportedCoverages( coverages ) )
68-
return false;
71+
return;
6972

7073
QMap<int, QgsNumericSortTreeWidgetItem *> items;
7174
QMap<int, int> coverageParents;
@@ -102,8 +105,6 @@ bool QgsWCSSourceSelect::populateLayerList( )
102105
{
103106
mLayersTreeWidget->expandItem( mLayersTreeWidget->topLevelItem( 0 ) );
104107
}
105-
106-
return true;
107108
}
108109

109110
void QgsWCSSourceSelect::addClicked( )
@@ -118,7 +119,7 @@ void QgsWCSSourceSelect::addClicked( )
118119

119120
uri.setParam( "identifier", identifier );
120121

121-
uri.setParam( "crs", selectedCrs() );
122+
uri.setParam( "crs", selectedCRS() );
122123

123124
QgsDebugMsg ( "selectedFormat = " + selectedFormat() );
124125
uri.setParam( "format", selectedFormat() );
@@ -139,21 +140,20 @@ void QgsWCSSourceSelect::on_mLayersTreeWidget_itemSelectionChanged()
139140
void QgsWCSSourceSelect::updateButtons()
140141
{
141142
QgsDebugMsg ( "entered");
142-
//updateCRSWidgets();
143143

144144
if ( mLayersTreeWidget->selectedItems().isEmpty() )
145145
{
146146
showStatusMessage( tr( "Select a layer" ) );
147147
}
148148
else
149149
{
150-
if ( mCRS.isEmpty() )
150+
if ( selectedCRS().isEmpty() )
151151
{
152152
showStatusMessage( tr( "No CRS selected" ) );
153153
}
154154
}
155155

156-
mAddButton->setEnabled( !mLayersTreeWidget->selectedItems().isEmpty() && !mCRS.isEmpty() && !selectedFormat().isEmpty() );
156+
mAddButton->setEnabled( !mLayersTreeWidget->selectedItems().isEmpty() && !selectedCRS().isEmpty() && !selectedFormat().isEmpty() );
157157
}
158158

159159
QList<QgsOWSSupportedFormat> QgsWCSSourceSelect::providerFormats()
@@ -199,7 +199,7 @@ QList<QgsOWSSupportedFormat> QgsWCSSourceSelect::providerFormats()
199199
return formats;
200200
}
201201

202-
QStringList QgsWCSSourceSelect::serverFormats()
202+
QStringList QgsWCSSourceSelect::selectedLayersFormats()
203203
{
204204
QgsDebugMsg ( "entered");
205205

@@ -212,7 +212,7 @@ QStringList QgsWCSSourceSelect::serverFormats()
212212
return c.supportedFormat;
213213
}
214214

215-
QStringList QgsWCSSourceSelect::serverCRS()
215+
QStringList QgsWCSSourceSelect::selectedLayersCRSs()
216216
{
217217
QgsDebugMsg ( "entered");
218218

@@ -226,20 +226,6 @@ QStringList QgsWCSSourceSelect::serverCRS()
226226
return c.supportedCrs;
227227
}
228228

229-
QStringList QgsWCSSourceSelect::layerCRS( int id )
230-
{
231-
QVector<QgsWcsCoverageSummary> coverages;
232-
if ( !mCapabilities.supportedCoverages( coverages ) )
233-
foreach ( QgsWcsCoverageSummary c, coverages )
234-
{
235-
if ( c.orderId == id )
236-
{
237-
return c.supportedCrs;
238-
}
239-
}
240-
return QStringList();
241-
}
242-
243229
void QgsWCSSourceSelect::enableLayersForCrs( QTreeWidgetItem *item )
244230
{
245231
// TODO: I am not convinced to disable layers according to selected CRS

src/providers/gdal/qgswcssourceselect.h

+4-21
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,15 @@ class QgsWCSSourceSelect : public QgsOWSSourceSelect
6666
private:
6767
QgsWcsCapabilities mCapabilities;
6868

69-
/**
70-
* \brief Populate the layer list - private for now.
71-
*
72-
* \retval false if the layers could not be retrieved or parsed -
73-
* see mWmsProvider->errorString() for more info
74-
*/
75-
bool populateLayerList( );
76-
77-
//! Add layer
69+
// QgsWcsCapabilities virtual methods
70+
void populateLayerList( );
7871
void addClicked();
79-
80-
//! Signaled when a layer selection is changed.
8172
void on_mLayersTreeWidget_itemSelectionChanged();
82-
8373
void enableLayersForCrs( QTreeWidgetItem *item );
84-
8574
void updateButtons();
86-
8775
QList<QgsOWSSupportedFormat> providerFormats();
88-
89-
QStringList serverFormats();
90-
91-
QStringList serverCRS();
92-
93-
QStringList layerCRS( int id );
94-
76+
QStringList selectedLayersFormats();
77+
QStringList selectedLayersCRSs();
9578
};
9679
#endif // QGSWCSSOURCESELECT_H
9780

0 commit comments

Comments
 (0)