Skip to content
Permalink
Browse files
WCS better version support
  • Loading branch information
blazek committed Apr 26, 2012
1 parent 58c3774 commit 866fa9c84a295c3cebadcbedc141ed780bbce7f0

Large diffs are not rendered by default.

@@ -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
@@ -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();
@@ -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,
@@ -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;

@@ -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();
@@ -42,6 +42,7 @@
#include <QFile>
#include <QHash>
#include <QTime>
#include <QTextDocument>

#include "gdalwarper.h"
#include "ogr_spatialref.h"
@@ -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>";
@@ -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 = "";

@@ -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 );

@@ -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 )
@@ -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" )
@@ -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();
@@ -618,7 +643,7 @@ void QgsWcsCapabilities::coverageParents( QMap<int, int> &parents, QMap<int, QSt

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

QString QgsWcsCapabilities::lastError()
@@ -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)
*/
@@ -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.
@@ -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;
@@ -102,8 +105,6 @@ bool QgsWCSSourceSelect::populateLayerList( )
{
mLayersTreeWidget->expandItem( mLayersTreeWidget->topLevelItem( 0 ) );
}

return true;
}

void QgsWCSSourceSelect::addClicked( )
@@ -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() );
@@ -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()
@@ -199,7 +199,7 @@ QList<QgsOWSSupportedFormat> QgsWCSSourceSelect::providerFormats()
return formats;
}

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

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

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

@@ -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
@@ -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

Loading

0 comments on commit 866fa9c

Please sign in to comment.