489 changes: 344 additions & 145 deletions src/providers/gdal/qgswcscapabilities.cpp

Large diffs are not rendered by default.

45 changes: 39 additions & 6 deletions src/providers/gdal/qgswcscapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct QgsWcsCoverageSummary
QStringList supportedFormat;
QgsRectangle wgs84BoundingBox;
QVector<QgsWcsCoverageSummary> coverageSummary;
bool described; // 1.0
};

/** Contents structure */
Expand Down Expand Up @@ -136,8 +137,6 @@ class QgsWcsCapabilities : public QObject
* otherwise we contact the host directly.
*
*/
//QgsWcsCapabilities( QString const & theUri = 0 );

QgsWcsCapabilities( QgsDataSourceURI const & theUri );
QgsWcsCapabilities( );

Expand All @@ -158,13 +157,14 @@ class QgsWcsCapabilities : public QObject
*/
bool supportedCoverages( QVector<QgsWcsCoverageSummary> &coverageSummary );


/**
* \brief Returns a map for the hierarchy of layers
*/
void coverageParents( QMap<int, int> &parents, QMap<int, QStringList> &parentNames ) const;

//! Get coverage summare for identifier
QgsWcsCoverageSummary coverageSummary( QString const & theIdentifier );
QgsWcsCoverageSummary * coverageSummary( QString const & theIdentifier, QgsWcsCoverageSummary* parent = 0 );

/**
* \brief Prepare the URI so that we can later simply append param=value
Expand All @@ -178,6 +178,17 @@ class QgsWcsCapabilities : public QObject
*/
QString getCoverageUrl() const;

//! Send request to server
bool sendRequest( QString const & url );

/** Get additional coverage info from server. Version 1.0 GetCapabilities
* response does not contain all info (CRS, formats).
*/
bool describeCoverage( QString const &identifier, bool forceRefresh = false );

bool convertToDom( QByteArray const &xml );
bool parseDescribeCoverageDom( QByteArray const &xml, QgsWcsCoverageSummary *coverage );

//! set authorization header
void setAuthorization( QNetworkRequest &request ) const;

Expand Down Expand Up @@ -219,10 +230,16 @@ class QgsWcsCapabilities : public QObject
void capabilitiesReplyProgress( qint64, qint64 );

private:
void showMessageBox( const QString& title, const QString& text );
void showMessageBox( const QString &title, const QString &text );

//! Get tag name without namespace
QString stripNS( const QString & name );
QString stripNS( const QString &name );

//! Get text of first child of specified name, NS is ignored
QString firstChildText( const QDomElement &element, const QString &name );

//! Get first child of specified name, NS is ignored
QDomElement firstChild( const QDomElement &element, const QString &name );

/**
* \brief Retrieve and parse the (cached) Capabilities document from the server
Expand All @@ -241,10 +258,25 @@ class QgsWcsCapabilities : public QObject
//! \return false if the capabilities document could not be parsed - see lastError() for more info
bool parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapabilitiesProperty &capabilities );

// ------------- 1.0 --------------------
//! parse the WCS Service XML element
void parseServiceIdentification( QDomElement const &e, QgsWcsServiceIdentification &serviceIdentification );
void parseService( QDomElement const &e, QgsWcsServiceIdentification &serviceIdentification );

//! parse the WCS Capability XML element
void parseCapability( QDomElement const &e, QgsWcsOperationsMetadata &operationsMetadata );

//! parse the WCS Layer XML element
void parseContentMetadata( QDomElement const &e, QgsWcsCoverageSummary &coverageSummary );

//! parse the WCS Layer XML element
void parseCoverageOfferingBrief( QDomElement const &e, QgsWcsCoverageSummary &coverageSummary,
QgsWcsCoverageSummary *parent = 0 );

// ------------- 1.1 --------------------
//! parse the WCS ServiceIdentificatio XML element
void parseServiceIdentification( QDomElement const &e, QgsWcsServiceIdentification &serviceIdentification );

//! parse the WCS OperationsMetadata XML element
void parseOperationsMetadata( QDomElement const &e, QgsWcsOperationsMetadata &operationsMetadata );

//! parse the WCS GetCoverage
Expand Down Expand Up @@ -288,6 +320,7 @@ class QgsWcsCapabilities : public QObject

/**
* layers hosted by the WCS Server
* This vector contain initial copies which are not updated by coverageSummary()!!!
*/
QVector<QgsWcsCoverageSummary> mCoveragesSupported;

Expand Down
45 changes: 29 additions & 16 deletions src/providers/gdal/qgswcssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,22 @@ void QgsWCSSourceSelect::populateLayerList( )
}
}

QString QgsWCSSourceSelect::selectedIdentifier()
{
QList<QTreeWidgetItem *> selectionList = mLayersTreeWidget->selectedItems();
if ( selectionList.size() < 1 ) return QString(); // should not happen
QString identifier = selectionList.value( 0 )->data( 0, Qt::UserRole + 0 ).toString();
QgsDebugMsg( " identifier = " + identifier );
return identifier;
}

void QgsWCSSourceSelect::addClicked( )
{
QgsDebugMsg( "entered" );
QgsDataSourceURI uri = mUri;

QList<QTreeWidgetItem *> selectionList = mLayersTreeWidget->selectedItems();
if ( selectionList.size() < 1 ) return; // should not happen
QString identifier = selectionList.value( 0 )->data( 0, Qt::UserRole + 0 ).toString();
QgsDebugMsg( " identifier = " + identifier );
QString identifier = selectedIdentifier();
if ( identifier.isEmpty() ) { return; }

uri.setParam( "identifier", identifier );

Expand All @@ -138,6 +145,12 @@ void QgsWCSSourceSelect::addClicked( )
void QgsWCSSourceSelect::on_mLayersTreeWidget_itemSelectionChanged()
{
QgsDebugMsg( "entered" );

QString identifier = selectedIdentifier();
if ( identifier.isEmpty() ) { return; }

mCapabilities.describeCoverage( identifier ); // 1.0 get additional info

populateFormats();

populateCRS();
Expand Down Expand Up @@ -194,27 +207,27 @@ QStringList QgsWCSSourceSelect::selectedLayersFormats()
{
QgsDebugMsg( "entered" );

QList<QTreeWidgetItem *> selectionList = mLayersTreeWidget->selectedItems();
if ( selectionList.size() < 1 ) return QStringList();
QString identifier = selectionList.value( 0 )->data( 0, Qt::UserRole + 0 ).toString();
QgsDebugMsg( " identifier = " + identifier );
QString identifier = selectedIdentifier();
if ( identifier.isEmpty() ) { return QStringList(); }

QgsWcsCoverageSummary c = mCapabilities.coverageSummary( identifier );
return c.supportedFormat;
QgsWcsCoverageSummary * c = mCapabilities.coverageSummary( identifier );
if ( !c ) { return QStringList(); }

QgsDebugMsg( "supportedFormat = " + c->supportedFormat.join( "," ) );
return c->supportedFormat;
}

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

QList<QTreeWidgetItem *> selectionList = mLayersTreeWidget->selectedItems();
if ( selectionList.size() < 1 ) return QStringList();
QString identifier = selectionList.value( 0 )->data( 0, Qt::UserRole + 0 ).toString();
QgsDebugMsg( " identifier = " + identifier );
QString identifier = selectedIdentifier();
if ( identifier.isEmpty() ) { return QStringList(); }

QgsWcsCoverageSummary c = mCapabilities.coverageSummary( identifier );
QgsWcsCoverageSummary * c = mCapabilities.coverageSummary( identifier );
if ( !c ) { return QStringList(); }

return c.supportedCrs;
return c->supportedCrs;
}

void QgsWCSSourceSelect::enableLayersForCrs( QTreeWidgetItem *item )
Expand Down
6 changes: 4 additions & 2 deletions src/providers/gdal/qgswcssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au
wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG
generalized : (C) 2012 Radim Blazek, based on qgsowsconnection.h
***************************************************************************/

/***************************************************************************
Expand Down Expand Up @@ -48,7 +48,7 @@ class QDomElement;
*/
class QgsWCSSourceSelect : public QgsOWSSourceSelect
{
Q_OBJECT
Q_OBJECT

public:
//! Constructor
Expand All @@ -66,6 +66,8 @@ class QgsWCSSourceSelect : public QgsOWSSourceSelect
private:
QgsWcsCapabilities mCapabilities;

QString selectedIdentifier();

// QgsWcsCapabilities virtual methods
void populateLayerList( );
void addClicked();
Expand Down