QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsserverprojectutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsserverprojectutils.cpp
3  -------------------------
4  begin : December 19, 2016
5  copyright : (C) 2016 by Paul Blottiere
6  email : paul dot blottiere at oslandia dot com
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 "qgsserverprojectutils.h"
19 #include "qgsproject.h"
20 
22 {
23  return project.readBoolEntry( QStringLiteral( "WMSServiceCapabilities" ), QStringLiteral( "/" ), false );
24 }
25 
27 {
28  return project.readEntry( QStringLiteral( "WMSServiceTitle" ), QStringLiteral( "/" ) );
29 }
30 
32 {
33  return project.readEntry( QStringLiteral( "WMSServiceAbstract" ), QStringLiteral( "/" ) );
34 }
35 
37 {
38  QStringList keywordList;
39  QStringList list = project.readListEntry( QStringLiteral( "WMSKeywordList" ), QStringLiteral( "/" ), QStringList() );
40  if ( !list.isEmpty() )
41  {
42  for ( int i = 0; i < list.size(); ++i )
43  {
44  QString keyword = list.at( i );
45  if ( !keyword.isEmpty() )
46  {
47  keywordList.append( keyword );
48  }
49  }
50  }
51  return keywordList;
52 }
53 
55 {
56  return project.readEntry( QStringLiteral( "WMSOnlineResource" ), QStringLiteral( "/" ) );
57 }
58 
60 {
61  return project.readEntry( QStringLiteral( "WMSContactOrganization" ), QStringLiteral( "/" ) );
62 }
63 
65 {
66  return project.readEntry( QStringLiteral( "WMSContactPosition" ), QStringLiteral( "/" ) );
67 }
68 
70 {
71  return project.readEntry( QStringLiteral( "WMSContactPerson" ), QStringLiteral( "/" ) );
72 }
73 
75 {
76  return project.readEntry( QStringLiteral( "WMSContactMail" ), QStringLiteral( "/" ) );
77 }
78 
80 {
81  return project.readEntry( QStringLiteral( "WMSContactPhone" ), QStringLiteral( "/" ) );
82 }
83 
85 {
86  return project.readEntry( QStringLiteral( "WMSFees" ), QStringLiteral( "/" ) );
87 }
88 
90 {
91  return project.readEntry( QStringLiteral( "WMSAccessConstraints" ), QStringLiteral( "/" ) );
92 }
93 
95 {
96  return project.readNumEntry( QStringLiteral( "WMSMaxWidth" ), QStringLiteral( "/" ), -1 );
97 }
98 
100 {
101  return project.readNumEntry( QStringLiteral( "WMSMaxHeight" ), QStringLiteral( "/" ), -1 );
102 }
103 
105 {
106  return project.readBoolEntry( QStringLiteral( "WMSUseLayerIDs" ), QStringLiteral( "/" ), false );
107 }
108 
110 {
111  return project.readNumEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), -1 );
112 }
113 
115 {
116  return project.readNumEntry( QStringLiteral( "WMSTileBuffer" ), QStringLiteral( "/" ), 0 );
117 }
118 
120 {
121  return project.readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 );
122 }
123 
125 {
126  return project.readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 );
127 }
128 
130 {
131  QString sia2045 = project.readEntry( QStringLiteral( "WMSInfoFormatSIA2045" ), QStringLiteral( "/" ), "" );
132 
133  return sia2045.compare( QLatin1String( "enabled" ), Qt::CaseInsensitive ) == 0
134  || sia2045.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;
135 }
136 
138 {
139  QString wktGeom = project.readEntry( QStringLiteral( "WMSAddWktGeometry" ), QStringLiteral( "/" ), "" );
140 
141  return wktGeom.compare( QLatin1String( "enabled" ), Qt::CaseInsensitive ) == 0
142  || wktGeom.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;
143 }
144 
146 {
147  QString segmGeom = project.readEntry( QStringLiteral( "WMSSegmentizeFeatureInfoGeometry" ), QStringLiteral( "/" ), "" );
148 
149  return segmGeom.compare( QLatin1String( "enabled" ), Qt::CaseInsensitive ) == 0
150  || segmGeom.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;
151 }
152 
154 {
155  return project.readNumEntry( QStringLiteral( "WMSPrecision" ), QStringLiteral( "/" ), 6 );
156 }
157 
159 {
160  return project.readEntry( QStringLiteral( "WMSFeatureInfoDocumentElement" ), QStringLiteral( "/" ), "" );
161 }
162 
164 {
165  return project.readEntry( QStringLiteral( "WMSFeatureInfoDocumentElementNS" ), QStringLiteral( "/" ), "" );
166 }
167 
169 {
170  return project.readEntry( QStringLiteral( "WMSFeatureInfoSchema" ), QStringLiteral( "/" ), "" );
171 }
172 
173 QHash<QString, QString> QgsServerProjectUtils::wmsFeatureInfoLayerAliasMap( const QgsProject &project )
174 {
175  QHash<QString, QString> aliasMap;
176 
177  //WMSFeatureInfoAliasLayers
178  QStringList aliasLayerStringList = project.readListEntry( QStringLiteral( "WMSFeatureInfoAliasLayers" ), QStringLiteral( "/value" ), QStringList() );
179  if ( aliasLayerStringList.isEmpty() )
180  {
181  return aliasMap;
182  }
183 
184  //WMSFeatureInfoLayerAliases
185  QStringList layerAliasStringList = project.readListEntry( QStringLiteral( "WMSFeatureInfoLayerAliases" ), QStringLiteral( "/value" ), QStringList() );
186  if ( layerAliasStringList.isEmpty() )
187  {
188  return aliasMap;
189  }
190 
191  int nMapEntries = std::min( aliasLayerStringList.size(), layerAliasStringList.size() );
192  for ( int i = 0; i < nMapEntries; ++i )
193  {
194  aliasMap.insert( aliasLayerStringList.at( i ), layerAliasStringList.at( i ) );
195  }
196 
197  return aliasMap;
198 }
199 
201 {
202  return project.readBoolEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/activated" ) );
203 }
204 
206 {
207  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/language" ) );
208 }
209 
211 {
212  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/metadataUrl" ) );
213 }
214 
216 {
217  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/metadataUrlType" ) );
218 }
219 
221 {
222  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/temporalReference" ) );
223 }
224 
226 {
227  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/metadataDate" ) );
228 }
229 
231 {
232  return project.readListEntry( QStringLiteral( "WMSRestrictedComposers" ), QStringLiteral( "/" ), QStringList() );
233 }
234 
236 {
237  QStringList crsList;
238  QStringList wmsCrsList = project.readListEntry( QStringLiteral( "WMSCrsList" ), QStringLiteral( "/" ), QStringList() );
239  if ( !wmsCrsList.isEmpty() )
240  {
241  for ( int i = 0; i < wmsCrsList.size(); ++i )
242  {
243  QString crs = wmsCrsList.at( i );
244  if ( !crs.isEmpty() )
245  {
246  crsList.append( crs );
247  }
248  }
249  }
250  if ( crsList.isEmpty() )
251  {
252  QStringList valueList = project.readListEntry( QStringLiteral( "WMSEpsgList" ), QStringLiteral( "/" ), QStringList() );
253  bool conversionOk;
254  for ( int i = 0; i < valueList.size(); ++i )
255  {
256  int epsgNr = valueList.at( i ).toInt( &conversionOk );
257  if ( conversionOk )
258  {
259  crsList.append( QStringLiteral( "EPSG:%1" ).arg( epsgNr ) );
260  }
261  }
262  }
263  if ( crsList.isEmpty() )
264  {
265  //no CRS restriction defined in the project. Provide project CRS, wgs84 and pseudo mercator
266  QString projectCrsId = project.crs().authid();
267  crsList.append( projectCrsId );
268  if ( projectCrsId.compare( QLatin1String( "EPSG:4326" ), Qt::CaseInsensitive ) != 0 )
269  {
270  crsList.append( QStringLiteral( "EPSG:%1" ).arg( 4326 ) );
271  }
272  if ( projectCrsId.compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) != 0 )
273  {
274  crsList.append( QStringLiteral( "EPSG:%1" ).arg( 3857 ) );
275  }
276  }
277  return crsList;
278 }
279 
281 {
282  return project.readEntry( QStringLiteral( "WMSUrl" ), QStringLiteral( "/" ), "" );
283 }
284 
286 {
287  return project.readEntry( QStringLiteral( "WMSRootName" ), QStringLiteral( "/" ), "" );
288 }
289 
291 {
292  return project.readListEntry( QStringLiteral( "WMSRestrictedLayers" ), QStringLiteral( "/" ), QStringList() );
293 }
294 
296 {
297  bool ok = false;
298  QStringList values = project.readListEntry( QStringLiteral( "WMSExtent" ), QStringLiteral( "/" ), QStringList(), &ok );
299  if ( !ok || values.size() != 4 )
300  {
301  return QgsRectangle();
302  }
303  //order of value elements must be xmin, ymin, xmax, ymax
304  double xmin = values[ 0 ].toDouble();
305  double ymin = values[ 1 ].toDouble();
306  double xmax = values[ 2 ].toDouble();
307  double ymax = values[ 3 ].toDouble();
308  return QgsRectangle( xmin, ymin, xmax, ymax );
309 }
310 
312 {
313  return project.readEntry( QStringLiteral( "WFSUrl" ), QStringLiteral( "/" ), "" );
314 }
315 
316 QStringList QgsServerProjectUtils::wfsLayerIds( const QgsProject &project )
317 {
318  return project.readListEntry( QStringLiteral( "WFSLayers" ), QStringLiteral( "/" ) );
319 }
320 
321 int QgsServerProjectUtils::wfsLayerPrecision( const QgsProject &project, const QString &layerId )
322 {
323  return project.readNumEntry( QStringLiteral( "WFSLayersPrecision" ), "/" + layerId, 6 );
324 }
325 
327 {
328  return project.readListEntry( QStringLiteral( "WFSTLayers" ), QStringLiteral( "Update" ) );
329 }
330 
332 {
333  return project.readListEntry( QStringLiteral( "WFSTLayers" ), QStringLiteral( "Insert" ) );
334 }
335 
337 {
338  return project.readListEntry( QStringLiteral( "WFSTLayers" ), QStringLiteral( "Delete" ) );
339 }
340 
342 {
343  return project.readEntry( QStringLiteral( "WCSUrl" ), QStringLiteral( "/" ), "" );
344 }
345 
346 QStringList QgsServerProjectUtils::wcsLayerIds( const QgsProject &project )
347 {
348  return project.readListEntry( QStringLiteral( "WCSLayers" ), QStringLiteral( "/" ) );
349 }
350 
352 {
353  return project.readEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), "" );
354 }
SERVER_EXPORT QString wmsInspireMetadataUrl(const QgsProject &project)
Returns the Inspire metadata URL.
SERVER_EXPORT QStringList wmsOutputCrsList(const QgsProject &project)
Returns the WMS output CRS list.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
SERVER_EXPORT QStringList wfstUpdateLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with update capabilities...
SERVER_EXPORT int wmsMaxWidth(const QgsProject &project)
Returns the maximum width for WMS images defined in a QGIS project.
SERVER_EXPORT bool owsServiceCapabilities(const QgsProject &project)
Returns if owsService capabilities are enabled.
SERVER_EXPORT int wmsTileBuffer(const QgsProject &project)
Returns the tile buffer in pixels for WMS images defined in a QGIS project.
SERVER_EXPORT QString wmsServiceUrl(const QgsProject &project)
Returns the WMS service url defined in a QGIS project.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
SERVER_EXPORT QString owsServiceContactPosition(const QgsProject &project)
Returns the owsService contact position defined in project.
SERVER_EXPORT QString owsServiceContactPerson(const QgsProject &project)
Returns the owsService contact person defined in project.
SERVER_EXPORT QStringList owsServiceKeywords(const QgsProject &project)
Returns the owsService keywords defined in project.
SERVER_EXPORT double wmsDefaultMapUnitsPerMm(const QgsProject &project)
Returns the default number of map units per millimeters in case of the scale is not given...
SERVER_EXPORT QString owsServiceAbstract(const QgsProject &project)
Returns the owsService abstract defined in project.
SERVER_EXPORT QString wmsFeatureInfoDocumentElement(const QgsProject &project)
Returns the document element name for XML GetFeatureInfo request.
SERVER_EXPORT QHash< QString, QString > wmsFeatureInfoLayerAliasMap(const QgsProject &project)
Returns the mapping between layer name and wms layer name for GetFeatureInfo request.
SERVER_EXPORT bool wmsInfoFormatSia2045(const QgsProject &project)
Returns if the info format is SIA20145.
const QgsCoordinateReferenceSystem & crs
SERVER_EXPORT QString wmsInspireMetadataDate(const QgsProject &project)
Returns the Inspire metadata date.
SERVER_EXPORT QString wmtsServiceUrl(const QgsProject &project)
Returns the WMTS service url defined in a QGIS project.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
SERVER_EXPORT bool wmsFeatureInfoAddWktGeometry(const QgsProject &project)
Returns if the geometry is displayed as Well Known Text in GetFeatureInfo request.
SERVER_EXPORT int wmsMaxAtlasFeatures(const QgsProject &project)
Returns the maximum number of atlas features which can be printed in a request.
SERVER_EXPORT QString wmsFeatureInfoDocumentElementNs(const QgsProject &project)
Returns the document element namespace for XML GetFeatureInfo request.
SERVER_EXPORT QStringList wfstDeleteLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with delete capabilities...
SERVER_EXPORT QStringList wmsRestrictedComposers(const QgsProject &project)
Returns the restricted composer list.
QgsCoordinateReferenceSystem crs
Definition: qgsproject.h:95
SERVER_EXPORT QStringList wcsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WCS.
SERVER_EXPORT bool wmsFeatureInfoSegmentizeWktGeometry(const QgsProject &project)
Returns if the geometry has to be segmentize in GetFeatureInfo request.
SERVER_EXPORT bool wmsInspireActivate(const QgsProject &project)
Returns if Inspire is activated.
SERVER_EXPORT QString wmsInspireTemporalReference(const QgsProject &project)
Returns the Inspire temporal reference.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:89
SERVER_EXPORT QString wmsInspireLanguage(const QgsProject &project)
Returns the Inspire language.
SERVER_EXPORT QString owsServiceFees(const QgsProject &project)
Returns the owsService fees defined in project.
SERVER_EXPORT QString owsServiceAccessConstraints(const QgsProject &project)
Returns the owsService access constraints defined in project.
SERVER_EXPORT int wfsLayerPrecision(const QgsProject &project, const QString &layerId)
Returns the Layer precision defined in a QGIS project for the WFS GetFeature.
SERVER_EXPORT QString owsServiceOnlineResource(const QgsProject &project)
Returns the owsService online resource defined in project.
SERVER_EXPORT QString owsServiceContactOrganization(const QgsProject &project)
Returns the owsService contact organization defined in project.
SERVER_EXPORT QString wcsServiceUrl(const QgsProject &project)
Returns the WCS service url defined in a QGIS project.
SERVER_EXPORT int wmsFeatureInfoPrecision(const QgsProject &project)
Returns the geometry precision for GetFeatureInfo request.
SERVER_EXPORT QgsRectangle wmsExtent(const QgsProject &project)
Returns the WMS Extent restriction.
SERVER_EXPORT QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
SERVER_EXPORT QString wmsInspireMetadataUrlType(const QgsProject &project)
Returns the Inspire metadata URL type.
SERVER_EXPORT QStringList wfstInsertLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published as WFS-T with insert capabilities...
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
SERVER_EXPORT QString owsServiceContactMail(const QgsProject &project)
Returns the owsService contact mail defined in project.
SERVER_EXPORT QString wmsFeatureInfoSchema(const QgsProject &project)
Returns the schema URL for XML GetFeatureInfo request.
SERVER_EXPORT QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.
SERVER_EXPORT QString wmsRootName(const QgsProject &project)
Returns the WMS root layer name defined in a QGIS project.
SERVER_EXPORT QString wfsServiceUrl(const QgsProject &project)
Returns the WFS service url defined in a QGIS project.
QString authid() const
Returns the authority identifier for the CRS.
SERVER_EXPORT QString owsServiceTitle(const QgsProject &project)
Returns the owsService title defined in project.
SERVER_EXPORT int wmsImageQuality(const QgsProject &project)
Returns the quality for WMS images defined in a QGIS project.
SERVER_EXPORT QString owsServiceContactPhone(const QgsProject &project)
Returns the owsService contact phone defined in project.
SERVER_EXPORT int wmsMaxHeight(const QgsProject &project)
Returns the maximum height for WMS images defined in a QGIS project.
SERVER_EXPORT bool wmsUseLayerIds(const QgsProject &project)
Returns if layer ids are used as name in WMS.