25using namespace Qt::StringLiterals;
29 const double scaleFactor = std::pow( 10.0, places );
30 return ( std::ceil( number * scaleFactor ) / scaleFactor );
35 const double scaleFactor = std::pow( 10.0, places );
36 return ( std::floor( number * scaleFactor ) / scaleFactor );
41 return project.
readBoolEntry( u
"WMSServiceCapabilities"_s, u
"/"_s,
false );
46 QString title = project.
readEntry( u
"WMSServiceTitle"_s, u
"/"_s );
47 if ( title.isEmpty() )
49 title = project.
title();
51 if ( title.isEmpty() )
53 title = QObject::tr(
"Untitled" );
60 return project.
readEntry( u
"WMSServiceAbstract"_s, u
"/"_s );
65 QStringList keywordList;
66 const QStringList list = project.
readListEntry( u
"WMSKeywordList"_s, u
"/"_s, QStringList() );
67 if ( !list.isEmpty() )
69 for (
int i = 0; i < list.size(); ++i )
71 const QString keyword = list.at( i );
72 if ( !keyword.isEmpty() )
74 keywordList.append( keyword );
83 QString wmsOnlineResource = project.
readEntry( u
"WMSOnlineResource"_s, u
"/"_s );
89 return wmsOnlineResourceProperty.
valueAsString( context, wmsOnlineResource );
92 return wmsOnlineResource;
97 return project.
readEntry( u
"WMSContactOrganization"_s, u
"/"_s );
102 return project.
readEntry( u
"WMSContactPosition"_s, u
"/"_s );
107 return project.
readEntry( u
"WMSContactPerson"_s, u
"/"_s );
112 return project.
readEntry( u
"WMSContactMail"_s, u
"/"_s );
117 return project.
readEntry( u
"WMSContactPhone"_s, u
"/"_s );
122 return project.
readEntry( u
"WMSFees"_s, u
"/"_s );
127 return project.
readEntry( u
"WMSAccessConstraints"_s, u
"/"_s );
132 return project.
readNumEntry( u
"WMSMaxWidth"_s, u
"/"_s, -1 );
137 return project.
readNumEntry( u
"WMSMaxHeight"_s, u
"/"_s, -1 );
142 return project.
readBoolEntry( u
"WMSUseLayerIDs"_s, u
"/"_s,
false );
147 return project.
readNumEntry( u
"WMSImageQuality"_s, u
"/"_s, -1 );
152 return project.
readNumEntry( u
"WMSTileBuffer"_s, u
"/"_s, 0 );
157 return project.
readNumEntry( u
"WMSMaxAtlasFeatures"_s, u
"/"_s, 1 );
162 return project.
readDoubleEntry( u
"WMSDefaultMapUnitsPerMm"_s, u
"/"_s, 1 );
167 const QString sia2045 = project.
readEntry( u
"WMSInfoFormatSIA2045"_s, u
"/"_s,
"" );
169 return sia2045.compare(
"enabled"_L1, Qt::CaseInsensitive ) == 0 || sia2045.compare(
"true"_L1, Qt::CaseInsensitive ) == 0;
174 const QString wktGeom = project.
readEntry( u
"WMSAddWktGeometry"_s, u
"/"_s,
"" );
176 return wktGeom.compare(
"enabled"_L1, Qt::CaseInsensitive ) == 0 || wktGeom.compare(
"true"_L1, Qt::CaseInsensitive ) == 0;
181 const QString useFormSettings = project.
readEntry( u
"WMSFeatureInfoUseAttributeFormSettings"_s, u
"/"_s,
"" );
182 return useFormSettings.compare(
"enabled"_L1, Qt::CaseInsensitive ) == 0 || useFormSettings.compare(
"true"_L1, Qt::CaseInsensitive ) == 0;
187 const QString useFormSettings = project.
readEntry( u
"WMSHTMLFeatureInfoUseOnlyMaptip"_s, u
"/"_s,
"" );
188 return useFormSettings.compare(
"true"_L1, Qt::CaseInsensitive ) == 0;
193 const QString segmGeom = project.
readEntry( u
"WMSSegmentizeFeatureInfoGeometry"_s, u
"/"_s,
"" );
195 return segmGeom.compare(
"enabled"_L1, Qt::CaseInsensitive ) == 0 || segmGeom.compare(
"true"_L1, Qt::CaseInsensitive ) == 0;
200 const QString legendGroups = project.
readEntry( u
"WMSAddLayerGroupsLegendGraphic"_s, u
"/"_s,
"" );
201 return legendGroups.compare(
"enabled"_L1, Qt::CaseInsensitive ) == 0 || legendGroups.compare(
"true"_L1, Qt::CaseInsensitive ) == 0;
206 return project.
readBoolEntry( u
"WMSSkipNameForGroup"_s, u
"/"_s,
false );
211 return project.
readNumEntry( u
"WMSPrecision"_s, u
"/"_s, 6 );
216 return project.
readEntry( u
"WMSFeatureInfoDocumentElement"_s, u
"/"_s,
"" );
221 return project.
readEntry( u
"WMSFeatureInfoDocumentElementNS"_s, u
"/"_s,
"" );
226 return project.
readEntry( u
"WMSFeatureInfoSchema"_s, u
"/"_s,
"" );
231 QHash<QString, QString> aliasMap;
234 const QStringList aliasLayerStringList = project.
readListEntry( u
"WMSFeatureInfoAliasLayers"_s, u
"/value"_s, QStringList() );
235 if ( aliasLayerStringList.isEmpty() )
241 const QStringList layerAliasStringList = project.
readListEntry( u
"WMSFeatureInfoLayerAliases"_s, u
"/value"_s, QStringList() );
242 if ( layerAliasStringList.isEmpty() )
247 const int nMapEntries = std::min( aliasLayerStringList.size(), layerAliasStringList.size() );
248 for (
int i = 0; i < nMapEntries; ++i )
250 aliasMap.insert( aliasLayerStringList.at( i ), layerAliasStringList.at( i ) );
258 return project.
readBoolEntry( u
"WMSInspire"_s, u
"/activated"_s );
263 return project.
readEntry( u
"WMSInspire"_s, u
"/language"_s );
268 return project.
readEntry( u
"WMSInspire"_s, u
"/metadataUrl"_s );
273 return project.
readEntry( u
"WMSInspire"_s, u
"/metadataUrlType"_s );
278 return project.
readEntry( u
"WMSInspire"_s, u
"/temporalReference"_s );
283 return project.
readEntry( u
"WMSInspire"_s, u
"/metadataDate"_s );
288 return project.
readListEntry( u
"WMSRestrictedComposers"_s, u
"/"_s, QStringList() );
294 const QStringList wmsCrsList = project.
readListEntry( u
"WMSCrsList"_s, u
"/"_s, QStringList() );
295 if ( !wmsCrsList.isEmpty() )
297 for (
const auto &crs : std::as_const( wmsCrsList ) )
299 if ( !crs.isEmpty() )
301 crsList.append( crs );
305 if ( crsList.isEmpty() )
307 const QStringList valueList = project.
readListEntry( u
"WMSEpsgList"_s, u
"/"_s, QStringList() );
309 for (
const auto &espgStr : valueList )
311 const int epsgNr = espgStr.toInt( &conversionOk );
314 crsList.append( u
"EPSG:%1"_s.arg( epsgNr ) );
318 if ( crsList.isEmpty() )
321 const QString projectCrsId = project.
crs().
authid();
322 crsList.append( projectCrsId );
323 if ( projectCrsId.compare(
"EPSG:4326"_L1, Qt::CaseInsensitive ) != 0 )
325 crsList.append( u
"EPSG:%1"_s.arg( 4326 ) );
327 if ( projectCrsId.compare(
"EPSG:3857"_L1, Qt::CaseInsensitive ) != 0 )
329 crsList.append( u
"EPSG:%1"_s.arg( 3857 ) );
338 QStringList crsListAsOgcUrn;
339 for (
const QString &crsString : crsList )
344 return crsListAsOgcUrn;
349 const QString serviceUpper = service.toUpper();
350 QString url = settings.
serviceUrl( serviceUpper );
351 if ( !url.isEmpty() )
357 if ( serviceUpper ==
"WMS"_L1 )
361 else if ( serviceUpper ==
"WFS"_L1 )
365 else if ( serviceUpper ==
"WCS"_L1 )
369 else if ( serviceUpper ==
"WMTS"_L1 )
373 url = request.
header( header );
374 if ( !url.isEmpty() )
379 if ( !url.isEmpty() )
388 if ( !forwarded.isEmpty() )
390 forwarded = forwarded.split(
','_L1 )[0];
391 const QStringList elements = forwarded.split(
';' );
392 for (
const QString &element : elements )
394 QStringList splited_element = element.trimmed().split(
'='_L1 );
395 if ( splited_element[0] ==
"host" )
397 host = splited_element[1];
399 if ( splited_element[0] ==
"proto" )
401 proto = splited_element[1];
406 if ( host.isEmpty() )
412 if ( host.isEmpty() )
417 QUrl urlQUrl = request.
baseUrl();
418 if ( !proto.isEmpty() )
420 urlQUrl.setScheme( proto );
423 if ( !host.isEmpty() )
425 QStringList hostPort = host.split(
':'_L1 );
426 if ( hostPort.length() == 1 )
428 urlQUrl.setHost( hostPort[0] );
429 urlQUrl.setPort( -1 );
431 if ( hostPort.length() == 2 )
433 urlQUrl.setHost( hostPort[0] );
434 urlQUrl.setPort( hostPort[1].toInt() );
439 const QUrlQuery query { request.
originalUrl().query() };
440 const QList<QPair<QString, QString>> constItems { query.queryItems() };
442 for (
const QPair<QString, QString> &item : std::as_const( constItems ) )
444 if ( 0 == item.first.compare(
"MAP"_L1, Qt::CaseSensitivity::CaseInsensitive ) )
451 if ( !map.isEmpty() )
454 query.setQueryItems( { {
"MAP", map } } );
455 urlQUrl.setQuery( query );
459 urlQUrl.setQuery(
nullptr );
462 return urlQUrl.url();
467 QString url = project.
readEntry( u
"WMSUrl"_s, u
"/"_s,
"" );
470 url =
serviceUrl( u
"WMS"_s, request, settings );
477 return project.
readEntry( u
"WMSRootName"_s, u
"/"_s,
"" );
482 return project.
readListEntry( u
"WMSRestrictedLayers"_s, u
"/"_s, QStringList() );
488 QStringList values = project.
readListEntry( u
"WMSExtent"_s, u
"/"_s, QStringList(), &ok );
489 if ( !ok || values.size() != 4 )
494 const double xmin = values[0].toDouble();
495 const double ymin = values[1].toDouble();
496 const double xmax = values[2].toDouble();
497 const double ymax = values[3].toDouble();
503 QString url = project.
readEntry( u
"WFSUrl"_s, u
"/"_s,
"" );
506 url =
serviceUrl( u
"WFS"_s, request, settings );
518 return project.
readNumEntry( u
"WFSLayersPrecision"_s,
"/" + layerId, 6 );
523 return project.
readListEntry( u
"WFSTLayers"_s, u
"Update"_s );
528 return project.
readListEntry( u
"WFSTLayers"_s, u
"Insert"_s );
533 return project.
readListEntry( u
"WFSTLayers"_s, u
"Delete"_s );
538 QString url = project.
readEntry( u
"WCSUrl"_s, u
"/"_s,
"" );
541 url =
serviceUrl( u
"WCS"_s, request, settings );
553 QString url = project.
readEntry( u
"WMTSUrl"_s, u
"/"_s,
"" );
556 url =
serviceUrl( u
"WMTS"_s, request, settings );
563 return project.
readBoolEntry( u
"RenderMapTile"_s, u
"/"_s,
false );
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
Reads an integer from the specified scope and key.
QgsPropertyCollection dataDefinedServerProperties() const
Returns the data defined properties used for overrides in user defined server parameters.
@ WMSOnlineResource
Alias.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
Reads a boolean from the specified scope and key.
QgsCoordinateReferenceSystem crs
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
Reads a double from the specified scope and key.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Reads a string list from the specified scope and key.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
A store for object properties.
QString expressionString() const
Returns the expression used for the property value.
QString valueAsString(const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a string.
bool isActive() const
Returns whether the property is currently active.
A rectangle specified with double values.
static QString wmsFeatureInfoSchema(const QgsProject &project)
Returns the schema URL for XML GetFeatureInfo request.
static int wmsTileBuffer(const QgsProject &project)
Returns the tile buffer in pixels for WMS images defined in a QGIS project.
static QString wcsServiceUrl(const QgsProject &project, const QgsServerRequest &request=QgsServerRequest(), const QgsServerSettings &settings=QgsServerSettings())
Returns the WCS service url.
static QString wmsRootName(const QgsProject &project)
Returns the WMS root layer name defined in a QGIS project.
static bool wmsInfoFormatSia2045(const QgsProject &project)
Returns if the info format is SIA20145.
static bool wmsSkipNameForGroup(const QgsProject &project)
Returns if name attribute should be skipped for groups in WMS capabilities document.
static QString wmsInspireMetadataUrl(const QgsProject &project)
Returns the Inspire metadata URL.
static bool wmsHTMLFeatureInfoUseOnlyMaptip(const QgsProject &project)
Returns if only the maptip should be used for HTML feature info response so that the HTML response to...
static QString wmtsServiceUrl(const QgsProject &project, const QgsServerRequest &request=QgsServerRequest(), const QgsServerSettings &settings=QgsServerSettings())
Returns the WMTS service url.
static int wmsFeatureInfoPrecision(const QgsProject &project)
Returns the geometry precision for GetFeatureInfo request.
static double ceilWithPrecision(double number, int places)
Returns a double greater than number to the specified number of places.
static QString wmsFeatureInfoDocumentElementNs(const QgsProject &project)
Returns the document element namespace for XML GetFeatureInfo request.
static QStringList wmsRestrictedComposers(const QgsProject &project)
Returns the restricted composer list.
static QgsRectangle wmsExtent(const QgsProject &project)
Returns the WMS Extent restriction.
static bool wmsUseLayerIds(const QgsProject &project)
Returns if layer ids are used as name in WMS.
static bool wmsFeatureInfoSegmentizeWktGeometry(const QgsProject &project)
Returns if the geometry has to be segmentize in GetFeatureInfo request.
static QString owsServiceAccessConstraints(const QgsProject &project)
Returns the owsService access constraints defined in project.
static QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
static bool wmsRenderMapTiles(const QgsProject &project)
Returns true if WMS requests should use the QgsMapSettings::RenderMapTile flag, so that no visible ar...
static QString owsServiceOnlineResource(const QgsProject &project)
Returns the owsService online resource defined in project.
static QString owsServiceFees(const QgsProject &project)
Returns the owsService fees defined in project.
static QStringList owsServiceKeywords(const QgsProject &project)
Returns the owsService keywords defined in project.
static QString owsServiceContactPosition(const QgsProject &project)
Returns the owsService contact position defined in project.
static QStringList wfstUpdateLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with update capabilities.
static bool wmsFeatureInfoUseAttributeFormSettings(const QgsProject &project)
Returns if feature form settings should be considered for the format of the feature info response.
static QStringList wmsOutputCrsListAsOgcUrn(const QgsProject &project)
Returns the WMS output CRS list as OGC URNs.
static QString serviceUrl(const QString &service, const QgsServerRequest &request, const QgsServerSettings &settings)
Returns the service url defined in the environment variable or with HTTP header.
static QStringList wfstInsertLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with insert capabilities.
static QString wmsInspireTemporalReference(const QgsProject &project)
Returns the Inspire temporal reference.
static QStringList wmsOutputCrsList(const QgsProject &project)
Returns the WMS output CRS list.
static QString wmsInspireMetadataDate(const QgsProject &project)
Returns the Inspire metadata date.
static QString owsServiceContactOrganization(const QgsProject &project)
Returns the owsService contact organization defined in project.
static QHash< QString, QString > wmsFeatureInfoLayerAliasMap(const QgsProject &project)
Returns the mapping between layer name and wms layer name for GetFeatureInfo request.
static bool wmsFeatureInfoAddWktGeometry(const QgsProject &project)
Returns if the geometry is displayed as Well Known Text in GetFeatureInfo request.
static QString wmsServiceUrl(const QgsProject &project, const QgsServerRequest &request=QgsServerRequest(), const QgsServerSettings &settings=QgsServerSettings())
Returns the WMS service url.
static QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.
static int wmsImageQuality(const QgsProject &project)
Returns the quality for WMS images defined in a QGIS project.
static QString wmsInspireLanguage(const QgsProject &project)
Returns the Inspire language.
static QString wmsInspireMetadataUrlType(const QgsProject &project)
Returns the Inspire metadata URL type.
static double wmsDefaultMapUnitsPerMm(const QgsProject &project)
Returns the default number of map units per millimeters in case of the scale is not given.
static bool owsServiceCapabilities(const QgsProject &project)
Returns if owsService capabilities are enabled.
static bool wmsInspireActivate(const QgsProject &project)
Returns if Inspire is activated.
static int wmsMaxWidth(const QgsProject &project)
Returns the maximum width for WMS images defined in a QGIS project.
static QString owsServiceTitle(const QgsProject &project)
Returns the owsService title defined in project.
static QString owsServiceContactMail(const QgsProject &project)
Returns the owsService contact mail defined in project.
static QString owsServiceAbstract(const QgsProject &project)
Returns the owsService abstract defined in project.
static double floorWithPrecision(double number, int places)
Returns a double less than number to the specified number of places.
static QStringList wfstDeleteLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with delete capabilities.
static QString wfsServiceUrl(const QgsProject &project, const QgsServerRequest &request=QgsServerRequest(), const QgsServerSettings &settings=QgsServerSettings())
Returns the WFS service url.
static int wmsMaxHeight(const QgsProject &project)
Returns the maximum height for WMS images defined in a QGIS project.
static QStringList wcsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WCS.
static bool wmsAddLegendGroupsLegendGraphic(const QgsProject &project)
Returns if legend groups should be in the legend graphic response if GetLegendGraphic is called on a ...
static QString wmsFeatureInfoDocumentElement(const QgsProject &project)
Returns the document element name for XML GetFeatureInfo request.
static int wmsMaxAtlasFeatures(const QgsProject &project)
Returns the maximum number of atlas features which can be printed in a request.
static QString owsServiceContactPhone(const QgsProject &project)
Returns the owsService contact phone defined in project.
static int wfsLayerPrecision(const QgsProject &project, const QString &layerId)
Returns the Layer precision defined in a QGIS project for the WFS GetFeature.
static QString owsServiceContactPerson(const QgsProject &project)
Returns the owsService contact person defined in project.
Defines requests passed to QgsService classes.
virtual QString header(const QString &name) const
Returns the header value.
QUrl baseUrl() const
Returns the base URL of QGIS server.
QUrl originalUrl() const
Returns the request url as seen by the web server, by default this is equal to the url seen by QGIS s...
RequestHeader
The internal HTTP Header used for the request as enum.
@ X_QGIS_WMS_SERVICE_URL
The QGIS WMS service URL.
@ X_QGIS_WCS_SERVICE_URL
The QGIS WCS service URL.
@ X_QGIS_WFS_SERVICE_URL
The QGIS WFS service URL.
@ X_FORWARDED_PROTO
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto.
@ X_QGIS_WMTS_SERVICE_URL
The QGIS WMTS service URL.
@ X_QGIS_SERVICE_URL
The QGIS service URL.
@ X_FORWARDED_HOST
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host.
@ FORWARDED
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded, https://tools....
@ HOST
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host.
Provides a way to retrieve settings by prioritizing according to environment variables,...
QString serviceUrl(const QString &service) const
Returns the service URL from the setting.