Skip to content

Commit

Permalink
add support for WCS in GeoNode provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and nyalldawson committed Apr 17, 2021
1 parent f8a1191 commit caf8126
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/core/geocms/geonode/qgsgeonoderequest.cpp
Expand Up @@ -270,7 +270,7 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con
const QVariantMap jsonVariantMap = jsonObject.toVariantMap();
const QVariantList layerList = jsonVariantMap.value( QStringLiteral( "objects" ) ).toList();

QString wmsURLFormat, wfsURLFormat, xyzURLFormat;
QString wmsURLFormat, wfsURLFormat, wcsURLFormat, xyzURLFormat;

for ( const QVariant &layer : std::as_const( layerList ) )
{
Expand All @@ -291,7 +291,7 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con

if ( ! layerMap.contains( QStringLiteral( "links" ) ) )
{
if ( wmsURLFormat.isEmpty() && wfsURLFormat.isEmpty() && xyzURLFormat.isEmpty() )
if ( wmsURLFormat.isEmpty() && wfsURLFormat.isEmpty() && wcsURLFormat.isEmpty() && xyzURLFormat.isEmpty() )
{
bool success = requestBlocking( QStringLiteral( "/api/layers/" ) + layerStruct.id );
if ( success )
Expand All @@ -303,24 +303,26 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con
QgsGeoNodeRequest::ServiceLayerDetail tempLayerStruct;
tempLayerStruct = parseOwsUrl( tempLayerStruct, resourceUriLinks );

if ( tempLayerStruct.wmsURL.isEmpty() && tempLayerStruct.wfsURL.isEmpty() && tempLayerStruct.xyzURL.isEmpty() )
if ( tempLayerStruct.wmsURL.isEmpty() && tempLayerStruct.wfsURL.isEmpty() && tempLayerStruct.wcsURL.isEmpty() && tempLayerStruct.xyzURL.isEmpty() )
continue;

// Avoid iterating all the layers to get the service url. Instead, generate a string format once we found one service url
// for every service (wms, wfs, xyz). And then use the string format for the other layers since they are identical.
// for every service (wms, wfs, wcs, xyz). And then use the string format for the other layers since they are identical.
switch ( tempLayerStruct.server )
{
case QgsGeoNodeRequest::BackendServer::QgisServer:
{
wmsURLFormat = ! tempLayerStruct.wmsURL.isEmpty() ? tempLayerStruct.wmsURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : QString();
wfsURLFormat = ! tempLayerStruct.wfsURL.isEmpty() ? tempLayerStruct.wfsURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : QString();
wcsURLFormat = ! tempLayerStruct.wcsURL.isEmpty() ? tempLayerStruct.wcsURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : QString();
xyzURLFormat = ! tempLayerStruct.xyzURL.isEmpty() ? tempLayerStruct.xyzURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : QString();
break;
}
case QgsGeoNodeRequest::BackendServer::Geoserver:
{
wmsURLFormat = ! tempLayerStruct.wmsURL.isEmpty() ? tempLayerStruct.wmsURL : QString();
wfsURLFormat = ! tempLayerStruct.wfsURL.isEmpty() ? tempLayerStruct.wfsURL : QString();
wcsURLFormat = ! tempLayerStruct.wcsURL.isEmpty() ? tempLayerStruct.wcsURL : QString();
xyzURLFormat = ! tempLayerStruct.xyzURL.isEmpty() ? tempLayerStruct.xyzURL.replace( layerStruct.name, QStringLiteral( "%1" ) ) : QString();
break;
}
Expand All @@ -336,6 +338,7 @@ QList<QgsGeoNodeRequest::ServiceLayerDetail> QgsGeoNodeRequest::parseLayers( con
// Replace string argument with the layer id.
layerStruct.wmsURL = wmsURLFormat.contains( "%1" ) ? wmsURLFormat.arg( layerStruct.name ) : wmsURLFormat;
layerStruct.wfsURL = wfsURLFormat.contains( "%1" ) ? wfsURLFormat.arg( layerStruct.name ) : wfsURLFormat;
layerStruct.wcsURL = wcsURLFormat.contains( "%1" ) ? wcsURLFormat.arg( layerStruct.name ) : wcsURLFormat;
layerStruct.xyzURL = xyzURLFormat.contains( "%1" ) ? xyzURLFormat.arg( layerStruct.name ) : xyzURLFormat;
}
}
Expand Down Expand Up @@ -364,6 +367,10 @@ QgsGeoNodeRequest::ServiceLayerDetail QgsGeoNodeRequest::parseOwsUrl( QgsGeoNode
{
urlFound = layerStruct.wfsURL = linkMap.value( QStringLiteral( "url" ) ).toString();
}
else if ( linkMap.value( QStringLiteral( "link_type" ) ) == QLatin1String( "OGC:WCS" ) )
{
urlFound = layerStruct.wcsURL = linkMap.value( QStringLiteral( "url" ) ).toString();
}
else if ( linkMap.value( QStringLiteral( "link_type" ) ) == QLatin1String( "image" ) )
{
if ( linkMap.contains( QStringLiteral( "name" ) ) && linkMap.value( QStringLiteral( "name" ) ) == QLatin1String( "Tiles" ) )
Expand Down Expand Up @@ -445,6 +452,10 @@ QStringList QgsGeoNodeRequest::fetchServiceUrlsBlocking( const QString &serviceT
{
url = layer.wfsURL;
}
else if ( QString::compare( serviceType, QStringLiteral( "wcs" ), Qt::CaseInsensitive ) == 0 )
{
url = layer.wcsURL;
}
else if ( QString::compare( serviceType, QStringLiteral( "xyz" ), Qt::CaseInsensitive ) == 0 )
{
url = layer.xyzURL;
Expand Down Expand Up @@ -489,6 +500,10 @@ QgsStringMap QgsGeoNodeRequest::fetchServiceUrlDataBlocking( const QString &serv
{
url = layer.wfsURL;
}
else if ( QString::compare( serviceType, QStringLiteral( "wcs" ), Qt::CaseInsensitive ) == 0 )
{
url = layer.wcsURL;
}
else if ( QString::compare( serviceType, QStringLiteral( "xyz" ), Qt::CaseInsensitive ) == 0 )
{
url = layer.xyzURL;
Expand Down
2 changes: 2 additions & 0 deletions src/core/geocms/geonode/qgsgeonoderequest.h
Expand Up @@ -96,6 +96,8 @@ class CORE_EXPORT QgsGeoNodeRequest : public QObject
QString wmsURL;
//! WFS URL for layer
QString wfsURL;
//! WCS URL for layer
QString wcsURL;
//! XYZ tileserver URL for layer
QString xyzURL;
//! Backend server (geoserver or qgis-server)
Expand Down
14 changes: 13 additions & 1 deletion src/providers/geonode/qgsgeonodedataitems.cpp
Expand Up @@ -38,6 +38,7 @@ QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()

QStringList wmsUrl = geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WMS" ) );
QStringList wfsUrl = geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WFS" ) );
QStringList wcsUrl = geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WCS" ) );
QStringList xyzUrl = geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "XYZ" ) );

if ( !wmsUrl.isEmpty() )
Expand All @@ -54,6 +55,13 @@ QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
services.append( service );
}

if ( !wcsUrl.isEmpty() )
{
QString path = mPath + QStringLiteral( "/wcs" );
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection.get(), QStringLiteral( "WCS" ), path );
services.append( service );
}

if ( !xyzUrl.isEmpty() )
{
QString path = mPath + QStringLiteral( "/xyz" );
Expand All @@ -75,6 +83,10 @@ QgsGeoNodeServiceItem::QgsGeoNodeServiceItem( QgsDataItem *parent, QgsGeoNodeCon
{
mIconName = QStringLiteral( "mIconWms.svg" );
}
else if ( serviceName == QLatin1String( "WCS" ) )
{
mIconName = QStringLiteral( "mIconWcs.svg" );
}
else
{
mIconName = QStringLiteral( "mIconWfs.svg" );
Expand All @@ -95,7 +107,7 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()

while ( !skipProvider )
{
const QString &key = mServiceName != QLatin1String( "WFS" ) ? QStringLiteral( "wms" ) : mServiceName;
const QString &key = mServiceName != QLatin1String( "WFS" ) ? mServiceName == QLatin1String( "WCS" ) ? QStringLiteral( "wcs" ) : QStringLiteral( "wms" ) : mServiceName;

const QList<QgsDataItemProvider *> providerList = QgsProviderRegistry::instance()->dataItemProviders( key );
if ( providerList.isEmpty() )
Expand Down
51 changes: 51 additions & 0 deletions src/providers/wcs/qgswcsdataitems.cpp
Expand Up @@ -19,6 +19,10 @@
#include "qgsdatasourceuri.h"
#include "qgsowsconnection.h"

#include "qgsgeonodeconnection.h"
#include "qgsgeonoderequest.h"
#include "qgssettings.h"

#ifdef HAVE_GUI
#include "qgswcssourceselect.h"
#endif
Expand Down Expand Up @@ -254,3 +258,50 @@ QgsDataItem *QgsWcsDataItemProvider::createDataItem( const QString &path, QgsDat

return nullptr;
}


QVector<QgsDataItem *> QgsWcsDataItemProvider::createDataItems( const QString &path, QgsDataItem *parentItem )
{
QVector<QgsDataItem *> items;
if ( path.startsWith( QLatin1String( "geonode:/" ) ) )
{
QString connectionName = path.split( '/' ).last();
if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
{
QgsGeoNodeConnection connection( connectionName );

QString url = connection.uri().param( QStringLiteral( "url" ) );
QgsGeoNodeRequest geonodeRequest( url, true );

const QStringList encodedUris( geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WCS" ) ) );

if ( !encodedUris.isEmpty() )
{
for ( const QString &encodedUri : encodedUris )
{
QgsDebugMsgLevel( encodedUri, 3 );
QgsDataSourceUri uri;
QgsSettings settings;
QString key( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + "/" + connectionName );

QString dpiMode = settings.value( key + "/wcs/dpiMode", "all" ).toString();
uri.setParam( QStringLiteral( "url" ), encodedUri );
if ( !dpiMode.isEmpty() )
{
uri.setParam( QStringLiteral( "dpiMode" ), dpiMode );
}

QgsDebugMsgLevel( QStringLiteral( "WCS full uri: '%1'." ).arg( QString( uri.encodedUri() ) ), 2 );

QgsDataItem *item = new QgsWCSConnectionItem( parentItem, QStringLiteral( "WCS" ), path, uri.encodedUri() );
if ( item )
{
items.append( item );
}
}
}
}
}

return items;
}
1 change: 1 addition & 0 deletions src/providers/wcs/qgswcsdataitems.h
Expand Up @@ -82,6 +82,7 @@ class QgsWcsDataItemProvider : public QgsDataItemProvider
int capabilities() const override;

QgsDataItem *createDataItem( const QString &pathIn, QgsDataItem *parentItem ) override;
QVector<QgsDataItem *> createDataItems( const QString &path, QgsDataItem *parentItem );
};

#endif // QGSWCSDATAITEMS_H

0 comments on commit caf8126

Please sign in to comment.