QGIS API Documentation  3.12.1-București (121cc00ff0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
21 double QgsServerProjectUtils::ceilWithPrecision( double number, int places )
22 {
23  double scaleFactor = std::pow( 10.0, places );
24  return ( std::ceil( number * scaleFactor ) / scaleFactor );
25 }
26 
27 double QgsServerProjectUtils::floorWithPrecision( double number, int places )
28 {
29  double scaleFactor = std::pow( 10.0, places );
30  return ( std::floor( number * scaleFactor ) / scaleFactor );
31 }
32 
34 {
35  return project.readBoolEntry( QStringLiteral( "WMSServiceCapabilities" ), QStringLiteral( "/" ), false );
36 }
37 
39 {
40  return project.readEntry( QStringLiteral( "WMSServiceTitle" ), QStringLiteral( "/" ) );
41 }
42 
44 {
45  return project.readEntry( QStringLiteral( "WMSServiceAbstract" ), QStringLiteral( "/" ) );
46 }
47 
49 {
50  QStringList keywordList;
51  QStringList list = project.readListEntry( QStringLiteral( "WMSKeywordList" ), QStringLiteral( "/" ), QStringList() );
52  if ( !list.isEmpty() )
53  {
54  for ( int i = 0; i < list.size(); ++i )
55  {
56  QString keyword = list.at( i );
57  if ( !keyword.isEmpty() )
58  {
59  keywordList.append( keyword );
60  }
61  }
62  }
63  return keywordList;
64 }
65 
67 {
68  return project.readEntry( QStringLiteral( "WMSOnlineResource" ), QStringLiteral( "/" ) );
69 }
70 
72 {
73  return project.readEntry( QStringLiteral( "WMSContactOrganization" ), QStringLiteral( "/" ) );
74 }
75 
77 {
78  return project.readEntry( QStringLiteral( "WMSContactPosition" ), QStringLiteral( "/" ) );
79 }
80 
82 {
83  return project.readEntry( QStringLiteral( "WMSContactPerson" ), QStringLiteral( "/" ) );
84 }
85 
87 {
88  return project.readEntry( QStringLiteral( "WMSContactMail" ), QStringLiteral( "/" ) );
89 }
90 
92 {
93  return project.readEntry( QStringLiteral( "WMSContactPhone" ), QStringLiteral( "/" ) );
94 }
95 
97 {
98  return project.readEntry( QStringLiteral( "WMSFees" ), QStringLiteral( "/" ) );
99 }
100 
102 {
103  return project.readEntry( QStringLiteral( "WMSAccessConstraints" ), QStringLiteral( "/" ) );
104 }
105 
107 {
108  return project.readNumEntry( QStringLiteral( "WMSMaxWidth" ), QStringLiteral( "/" ), -1 );
109 }
110 
112 {
113  return project.readNumEntry( QStringLiteral( "WMSMaxHeight" ), QStringLiteral( "/" ), -1 );
114 }
115 
117 {
118  return project.readBoolEntry( QStringLiteral( "WMSUseLayerIDs" ), QStringLiteral( "/" ), false );
119 }
120 
122 {
123  return project.readNumEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), -1 );
124 }
125 
127 {
128  return project.readNumEntry( QStringLiteral( "WMSTileBuffer" ), QStringLiteral( "/" ), 0 );
129 }
130 
132 {
133  return project.readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 );
134 }
135 
137 {
138  return project.readDoubleEntry( QStringLiteral( "WMSDefaultMapUnitsPerMm" ), QStringLiteral( "/" ), 1 );
139 }
140 
142 {
143  QString sia2045 = project.readEntry( QStringLiteral( "WMSInfoFormatSIA2045" ), QStringLiteral( "/" ), "" );
144 
145  return sia2045.compare( QLatin1String( "enabled" ), Qt::CaseInsensitive ) == 0
146  || sia2045.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;
147 }
148 
150 {
151  QString wktGeom = project.readEntry( QStringLiteral( "WMSAddWktGeometry" ), QStringLiteral( "/" ), "" );
152 
153  return wktGeom.compare( QLatin1String( "enabled" ), Qt::CaseInsensitive ) == 0
154  || wktGeom.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;
155 }
156 
158 {
159  QString segmGeom = project.readEntry( QStringLiteral( "WMSSegmentizeFeatureInfoGeometry" ), QStringLiteral( "/" ), "" );
160 
161  return segmGeom.compare( QLatin1String( "enabled" ), Qt::CaseInsensitive ) == 0
162  || segmGeom.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;
163 }
164 
166 {
167  return project.readNumEntry( QStringLiteral( "WMSPrecision" ), QStringLiteral( "/" ), 6 );
168 }
169 
171 {
172  return project.readEntry( QStringLiteral( "WMSFeatureInfoDocumentElement" ), QStringLiteral( "/" ), "" );
173 }
174 
176 {
177  return project.readEntry( QStringLiteral( "WMSFeatureInfoDocumentElementNS" ), QStringLiteral( "/" ), "" );
178 }
179 
181 {
182  return project.readEntry( QStringLiteral( "WMSFeatureInfoSchema" ), QStringLiteral( "/" ), "" );
183 }
184 
185 QHash<QString, QString> QgsServerProjectUtils::wmsFeatureInfoLayerAliasMap( const QgsProject &project )
186 {
187  QHash<QString, QString> aliasMap;
188 
189  //WMSFeatureInfoAliasLayers
190  QStringList aliasLayerStringList = project.readListEntry( QStringLiteral( "WMSFeatureInfoAliasLayers" ), QStringLiteral( "/value" ), QStringList() );
191  if ( aliasLayerStringList.isEmpty() )
192  {
193  return aliasMap;
194  }
195 
196  //WMSFeatureInfoLayerAliases
197  QStringList layerAliasStringList = project.readListEntry( QStringLiteral( "WMSFeatureInfoLayerAliases" ), QStringLiteral( "/value" ), QStringList() );
198  if ( layerAliasStringList.isEmpty() )
199  {
200  return aliasMap;
201  }
202 
203  int nMapEntries = std::min( aliasLayerStringList.size(), layerAliasStringList.size() );
204  for ( int i = 0; i < nMapEntries; ++i )
205  {
206  aliasMap.insert( aliasLayerStringList.at( i ), layerAliasStringList.at( i ) );
207  }
208 
209  return aliasMap;
210 }
211 
213 {
214  return project.readBoolEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/activated" ) );
215 }
216 
218 {
219  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/language" ) );
220 }
221 
223 {
224  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/metadataUrl" ) );
225 }
226 
228 {
229  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/metadataUrlType" ) );
230 }
231 
233 {
234  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/temporalReference" ) );
235 }
236 
238 {
239  return project.readEntry( QStringLiteral( "WMSInspire" ), QStringLiteral( "/metadataDate" ) );
240 }
241 
243 {
244  return project.readListEntry( QStringLiteral( "WMSRestrictedComposers" ), QStringLiteral( "/" ), QStringList() );
245 }
246 
248 {
249  QStringList crsList;
250  QStringList wmsCrsList = project.readListEntry( QStringLiteral( "WMSCrsList" ), QStringLiteral( "/" ), QStringList() );
251  if ( !wmsCrsList.isEmpty() )
252  {
253  for ( int i = 0; i < wmsCrsList.size(); ++i )
254  {
255  QString crs = wmsCrsList.at( i );
256  if ( !crs.isEmpty() )
257  {
258  crsList.append( crs );
259  }
260  }
261  }
262  if ( crsList.isEmpty() )
263  {
264  QStringList valueList = project.readListEntry( QStringLiteral( "WMSEpsgList" ), QStringLiteral( "/" ), QStringList() );
265  bool conversionOk;
266  for ( int i = 0; i < valueList.size(); ++i )
267  {
268  int epsgNr = valueList.at( i ).toInt( &conversionOk );
269  if ( conversionOk )
270  {
271  crsList.append( QStringLiteral( "EPSG:%1" ).arg( epsgNr ) );
272  }
273  }
274  }
275  if ( crsList.isEmpty() )
276  {
277  //no CRS restriction defined in the project. Provide project CRS, wgs84 and pseudo mercator
278  QString projectCrsId = project.crs().authid();
279  crsList.append( projectCrsId );
280  if ( projectCrsId.compare( QLatin1String( "EPSG:4326" ), Qt::CaseInsensitive ) != 0 )
281  {
282  crsList.append( QStringLiteral( "EPSG:%1" ).arg( 4326 ) );
283  }
284  if ( projectCrsId.compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) != 0 )
285  {
286  crsList.append( QStringLiteral( "EPSG:%1" ).arg( 3857 ) );
287  }
288  }
289  return crsList;
290 }
291 
293 {
294  return project.readEntry( QStringLiteral( "WMSUrl" ), QStringLiteral( "/" ), "" );
295 }
296 
298 {
299  return project.readEntry( QStringLiteral( "WMSRootName" ), QStringLiteral( "/" ), "" );
300 }
301 
303 {
304  return project.readListEntry( QStringLiteral( "WMSRestrictedLayers" ), QStringLiteral( "/" ), QStringList() );
305 }
306 
308 {
309  bool ok = false;
310  QStringList values = project.readListEntry( QStringLiteral( "WMSExtent" ), QStringLiteral( "/" ), QStringList(), &ok );
311  if ( !ok || values.size() != 4 )
312  {
313  return QgsRectangle();
314  }
315  //order of value elements must be xmin, ymin, xmax, ymax
316  double xmin = values[ 0 ].toDouble();
317  double ymin = values[ 1 ].toDouble();
318  double xmax = values[ 2 ].toDouble();
319  double ymax = values[ 3 ].toDouble();
320  return QgsRectangle( xmin, ymin, xmax, ymax );
321 }
322 
324 {
325  return project.readEntry( QStringLiteral( "WFSUrl" ), QStringLiteral( "/" ), "" );
326 }
327 
328 QStringList QgsServerProjectUtils::wfsLayerIds( const QgsProject &project )
329 {
330  return project.readListEntry( QStringLiteral( "WFSLayers" ), QStringLiteral( "/" ) );
331 }
332 
333 int QgsServerProjectUtils::wfsLayerPrecision( const QgsProject &project, const QString &layerId )
334 {
335  return project.readNumEntry( QStringLiteral( "WFSLayersPrecision" ), "/" + layerId, 6 );
336 }
337 
339 {
340  return project.readListEntry( QStringLiteral( "WFSTLayers" ), QStringLiteral( "Update" ) );
341 }
342 
344 {
345  return project.readListEntry( QStringLiteral( "WFSTLayers" ), QStringLiteral( "Insert" ) );
346 }
347 
349 {
350  return project.readListEntry( QStringLiteral( "WFSTLayers" ), QStringLiteral( "Delete" ) );
351 }
352 
354 {
355  return project.readEntry( QStringLiteral( "WCSUrl" ), QStringLiteral( "/" ), "" );
356 }
357 
358 QStringList QgsServerProjectUtils::wcsLayerIds( const QgsProject &project )
359 {
360  return project.readListEntry( QStringLiteral( "WCSLayers" ), QStringLiteral( "/" ) );
361 }
362 
364 {
365  return project.readEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), "" );
366 }
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.
SERVER_EXPORT double floorWithPrecision(double number, int places)
Returns a double less than number to the specified number of places.
QgsCoordinateReferenceSystem crs
Definition: qgsproject.h:97
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:91
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 double ceilWithPrecision(double number, int places)
Returns a double greater than number to the specified number of places.
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.