Skip to content

Commit

Permalink
WCS better version support
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Apr 26, 2012
1 parent 58c3774 commit 866fa9c
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 394 deletions.
339 changes: 32 additions & 307 deletions src/gui/qgsowssourceselect.cpp

Large diffs are not rendered by default.

54 changes: 26 additions & 28 deletions src/gui/qgsowssourceselect.h
Expand Up @@ -105,6 +105,12 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase

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

signals:
void addRasterLayer( QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey );
void connectionsChanged();

protected:
/**
* List of image formats (encodings) supported by provider
Expand All @@ -113,12 +119,12 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
virtual QList<QgsOWSSupportedFormat> providerFormats();

//! List of formats supported for currently selected layer item(s)
virtual QStringList serverFormats();
virtual QStringList selectedLayersFormats();

//! Server CRS supported for currently selected layer item(s)
virtual QStringList serverCRS();
virtual QStringList selectedLayersCRSs();

virtual QStringList layerCRS( int id );
//virtual QStringList layerCRS( int id );

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

//! Selected CRS
QString mCRS;

//! Common CRSs for selected layers
QSet<QString> mCRSs;

//! Supported formats
QList<QgsOWSSupportedFormat> mProviderFormats;

//! Map mime types to supported formats
QMap<QString, int> mMimeMap;

/**
* \brief Populate the layer list - private for now.
* \brief Populate the layer list.
*
* \retval false if the layers could not be retrieved or parsed -
* see mWmsProvider->errorString() for more info
* \retval false if the layers could not be retrieved or parsed
*/
virtual bool populateLayerList( );
virtual void populateLayerList( );

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

void applySelectionConstraints( QTreeWidgetItem *item );
void collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles );
virtual void enableLayersForCrs( QTreeWidgetItem *item );

//! Returns currently selected format
QString selectedFormat();

//! Returns currently selected Crs
QString selectedCrs();
QString selectedCRS();

QList<QTreeWidgetItem*> mCurrentSelection;
QTableWidgetItem* mCurrentTileset;

signals:
void addRasterLayer( QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey );
void connectionsChanged();

protected:
//! Name for selected connection
QString mConnName;

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

private:
//! Selected CRS
QString mSelectedCRS;

//! Common CRSs for selected layers
QSet<QString> mSelectedLayersCRSs;

//! Supported formats
QList<QgsOWSSupportedFormat> mProviderFormats;

//! Map mime types to supported formats
QMap<QString, int> mMimeMap;

private slots:
void on_mSearchButton_clicked();
void on_mAddWMSButton_clicked();
Expand Down
6 changes: 5 additions & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -42,6 +42,7 @@
#include <QFile>
#include <QHash>
#include <QTime>
#include <QTextDocument>

#include "gdalwarper.h"
#include "ogr_spatialref.h"
Expand Down Expand Up @@ -112,18 +113,21 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
if ( uri.contains("url=") && uri.contains("identifier=") && !QFile::exists(uri) )
{
// WCS
// GDAL currently (4/2012) supports WCS 1.0.0 (default) and 1.1.0
//
QgsDataSourceURI dsUri;
dsUri.setEncodedUri( uri );
gdalUri = "<WCS_GDAL>";
// prepareUri adds ? or & if necessary, GDAL fails otherwise
gdalUri += "<ServiceURL>" + QgsWcsCapabilities::prepareUri( dsUri.param("url") ) + "</ServiceURL>";
gdalUri += "<ServiceURL>" + Qt::escape( QgsWcsCapabilities::prepareUri( dsUri.param("url") ) ) + "</ServiceURL>";
gdalUri += "<CoverageName>" + dsUri.param("identifier") + "</CoverageName>";
gdalUri += "<PreferredFormat>" + dsUri.param("format") + "</PreferredFormat>";

// TODO: There is no tag for CRS response.
// There is undocumented CRS tag, but it only overrides CRS param in requests
// but BBOX is left unchanged and thus results in server error (usually).
gdalUri += "<GetCoverageExtra>&amp;RESPONSE_CRS=" + dsUri.param("crs") + "</GetCoverageExtra>";

if ( dsUri.hasParam("username") && dsUri.hasParam("password") )
{
gdalUri += "<UserPwd>" + dsUri.param("username") + ":" + dsUri.param("password") + "</UserPwd>";
Expand Down
39 changes: 32 additions & 7 deletions src/providers/gdal/qgswcscapabilities.cpp
Expand Up @@ -166,8 +166,17 @@ bool QgsWcsCapabilities::retrieveServerCapabilities( bool forceRefresh )

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

QString url = prepareUri( mUri.param("url") ) + "SERVICE=WCS&REQUEST=GetCapabilities&VERSION=1.1.0";

mError = "";

Expand Down Expand Up @@ -213,7 +222,7 @@ bool QgsWcsCapabilities::retrieveServerCapabilities( bool forceRefresh )
if ( !domOK )
{
// We had an Dom exception -
// mErrorCaption and mError are pre-filled by parseCapabilitiesDom
// mErrorTitle and mError are pre-filled by parseCapabilitiesDom

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

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

if ( !contentSuccess )
{
mErrorCaption = tr( "Dom Exception" );
mErrorTitle = tr( "Dom Exception" );
mErrorFormat = "text/plain";
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" )
.arg( errorMsg )
Expand All @@ -324,10 +333,12 @@ bool QgsWcsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapa
QgsDebugMsg( "testing tagName " + docElem.tagName() );

if (
docElem.tagName() != "Capabilities"
// We don't support 1.0, but try WCS_Capabilities tag to get version
docElem.tagName() != "WCS_Capabilities" && // 1.0
docElem.tagName() != "Capabilities" // 1.1
)
{
mErrorCaption = tr( "Dom Exception" );
mErrorTitle = tr( "Dom Exception" );
mErrorFormat = "text/plain";
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" )
.arg( "Capabilities" )
Expand All @@ -340,6 +351,20 @@ bool QgsWcsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapa
}

capabilities.version = docElem.attribute( "version" );
mVersion = capabilities.version;

if ( !mVersion.startsWith("1.1.") )
{
mErrorTitle = tr( "Version not supported" );
mErrorFormat = "text/plain";
mError = tr( "Could not get WCS capabilities in the expected version 1.1.\nResponse version was: %1" )
.arg( mVersion );

QgsLogger::debug( "WCS version: " + mError );

return false;
}


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

QString QgsWcsCapabilities::lastErrorTitle()
{
return mErrorCaption;
return mErrorTitle;
}

QString QgsWcsCapabilities::lastError()
Expand Down
5 changes: 4 additions & 1 deletion src/providers/gdal/qgswcscapabilities.h
Expand Up @@ -301,6 +301,9 @@ class QgsWcsCapabilities : public QObject
//! URL part of URI (httpuri)
//QString mBaseUrl;

//! Response capabilities version
QString mVersion;

/**
* Capabilities of the WCS Server (raw)
*/
Expand Down Expand Up @@ -349,7 +352,7 @@ class QgsWcsCapabilities : public QObject
/**
* The error caption associated with the last WCS error.
*/
QString mErrorCaption;
QString mErrorTitle;

/**
* The error message associated with the last WCS error.
Expand Down
40 changes: 13 additions & 27 deletions src/providers/gdal/qgswcssourceselect.cpp
Expand Up @@ -54,18 +54,21 @@ QgsWCSSourceSelect::~QgsWCSSourceSelect()
{
}

bool QgsWCSSourceSelect::populateLayerList( )
void QgsWCSSourceSelect::populateLayerList( )
{
QgsDebugMsg( "entered" );
// mCRSs.clear();

// TODO: showError

mCapabilities.setUri ( mUri );

if ( !mCapabilities.lastError().isEmpty() )
{
showError( mCapabilities.lastErrorTitle(), mCapabilities.lastErrorFormat(), mCapabilities.lastError() );
return;
}

QVector<QgsWcsCoverageSummary> coverages;
if ( !mCapabilities.supportedCoverages( coverages ) )
return false;
return;

QMap<int, QgsNumericSortTreeWidgetItem *> items;
QMap<int, int> coverageParents;
Expand Down Expand Up @@ -102,8 +105,6 @@ bool QgsWCSSourceSelect::populateLayerList( )
{
mLayersTreeWidget->expandItem( mLayersTreeWidget->topLevelItem( 0 ) );
}

return true;
}

void QgsWCSSourceSelect::addClicked( )
Expand All @@ -118,7 +119,7 @@ void QgsWCSSourceSelect::addClicked( )

uri.setParam( "identifier", identifier );

uri.setParam( "crs", selectedCrs() );
uri.setParam( "crs", selectedCRS() );

QgsDebugMsg ( "selectedFormat = " + selectedFormat() );
uri.setParam( "format", selectedFormat() );
Expand All @@ -139,21 +140,20 @@ void QgsWCSSourceSelect::on_mLayersTreeWidget_itemSelectionChanged()
void QgsWCSSourceSelect::updateButtons()
{
QgsDebugMsg ( "entered");
//updateCRSWidgets();

if ( mLayersTreeWidget->selectedItems().isEmpty() )
{
showStatusMessage( tr( "Select a layer" ) );
}
else
{
if ( mCRS.isEmpty() )
if ( selectedCRS().isEmpty() )
{
showStatusMessage( tr( "No CRS selected" ) );
}
}

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

QList<QgsOWSSupportedFormat> QgsWCSSourceSelect::providerFormats()
Expand Down Expand Up @@ -199,7 +199,7 @@ QList<QgsOWSSupportedFormat> QgsWCSSourceSelect::providerFormats()
return formats;
}

QStringList QgsWCSSourceSelect::serverFormats()
QStringList QgsWCSSourceSelect::selectedLayersFormats()
{
QgsDebugMsg ( "entered");

Expand All @@ -212,7 +212,7 @@ QStringList QgsWCSSourceSelect::serverFormats()
return c.supportedFormat;
}

QStringList QgsWCSSourceSelect::serverCRS()
QStringList QgsWCSSourceSelect::selectedLayersCRSs()
{
QgsDebugMsg ( "entered");

Expand All @@ -226,20 +226,6 @@ QStringList QgsWCSSourceSelect::serverCRS()
return c.supportedCrs;
}

QStringList QgsWCSSourceSelect::layerCRS( int id )
{
QVector<QgsWcsCoverageSummary> coverages;
if ( !mCapabilities.supportedCoverages( coverages ) )
foreach ( QgsWcsCoverageSummary c, coverages )
{
if ( c.orderId == id )
{
return c.supportedCrs;
}
}
return QStringList();
}

void QgsWCSSourceSelect::enableLayersForCrs( QTreeWidgetItem *item )
{
// TODO: I am not convinced to disable layers according to selected CRS
Expand Down
25 changes: 4 additions & 21 deletions src/providers/gdal/qgswcssourceselect.h
Expand Up @@ -66,32 +66,15 @@ class QgsWCSSourceSelect : public QgsOWSSourceSelect
private:
QgsWcsCapabilities mCapabilities;

/**
* \brief Populate the layer list - private for now.
*
* \retval false if the layers could not be retrieved or parsed -
* see mWmsProvider->errorString() for more info
*/
bool populateLayerList( );

//! Add layer
// QgsWcsCapabilities virtual methods
void populateLayerList( );
void addClicked();

//! Signaled when a layer selection is changed.
void on_mLayersTreeWidget_itemSelectionChanged();

void enableLayersForCrs( QTreeWidgetItem *item );

void updateButtons();

QList<QgsOWSSupportedFormat> providerFormats();

QStringList serverFormats();

QStringList serverCRS();

QStringList layerCRS( int id );

QStringList selectedLayersFormats();
QStringList selectedLayersCRSs();
};
#endif // QGSWCSSOURCESELECT_H

Expand Down

0 comments on commit 866fa9c

Please sign in to comment.