QGIS API Documentation 3.99.0-Master (d270888f95f)
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
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27{
28 if ( !layer || layer->providerType() != "wms"_L1 )
29 return false;
30
31 // Discard WMTS layers
32 const QString url = layer->publicSource();
33 if ( url.contains( "SERVICE=WMTS"_L1, Qt::CaseInsensitive ) || url.contains( "/WMTSCapabilities.xml"_L1, Qt::CaseInsensitive ) )
34 {
35 return false;
36 }
37
38 // Discard XYZ layers
39 const QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( u"wms"_s, layer->source() );
40 if ( parts.value( u"type"_s ).toString() == "xyz"_L1 )
41 {
42 return false;
43 }
44
45 return true;
46}
47
49{
50 if ( !layer || !layer->dataProvider() || !QgsWmsUtils::isWmsLayer( layer ) )
51 return QString();
52
53 return layer->dataProvider()->metadata().value( u"WmsVersion"_s, QString() ).toString();
54}
virtual QVariantMap metadata() const
Returns provider specific metadata.
Base class for all map layer types.
Definition qgsmaplayer.h:83
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.