QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgswmsutils.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswmsutils.cpp
3 ---------------
4 begin : September 2025
5 copyright : (C) 2025 by Germán Carrillo
6 email : german at opengis dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgswmsutils.h"
19
20#include "qgsproviderregistry.h"
21
23{
24 if ( !layer || layer->providerType() != QLatin1String( "wms" ) )
25 return false;
26
27 // Discard WMTS layers
28 const QString url = layer->publicSource();
29 if ( url.contains( QLatin1String( "SERVICE=WMTS" ), Qt::CaseInsensitive ) || url.contains( QLatin1String( "/WMTSCapabilities.xml" ), Qt::CaseInsensitive ) )
30 {
31 return false;
32 }
33
34 // Discard XYZ layers
35 const QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "wms" ), layer->source() );
36 if ( parts.value( QStringLiteral( "type" ) ).toString() == QLatin1String( "xyz" ) )
37 {
38 return false;
39 }
40
41 return true;
42}
43
45{
46 if ( !layer || !layer->dataProvider() || !QgsWmsUtils::isWmsLayer( layer ) )
47 return QString();
48
49 return layer->dataProvider()->metadata().value( QStringLiteral( "WmsVersion" ), QString() ).toString();
50}
virtual QVariantMap metadata() const
Returns provider specific metadata.
Base class for all map layer types.
Definition qgsmaplayer.h:80
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
QString publicSource(bool hidePassword=false) const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
static QString wmsVersion(QgsRasterLayer *layer)
Returns the WMS version of a WMS layer as a string (e.g., "1.3.0").
static bool isWmsLayer(QgsMapLayer *layer)
Returns whether a map layer is an OGC WMS layer or not.