QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgswmsrendercontext.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswmsrendercontext.cpp
3  ---------------------
4  begin : March 22, 2019
5  copyright : (C) 2019 by Paul Blottiere
6  email : [email protected]
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 "qgslayertree.h"
19 
20 #include "qgswmsrendercontext.h"
21 #include "qgswmsserviceexception.h"
22 #include "qgsserverprojectutils.h"
23 
24 using namespace QgsWms;
25 
26 const double OGC_PX_M = 0.00028; // OGC reference pixel size in meter
27 
29  : mProject( project )
30  , mInterface( interface )
31  , mFlags()
32 {
33 }
34 
36 {
37  mParameters = parameters;
38 
39  initRestrictedLayers();
40  initNicknameLayers();
41 
42  searchLayersToRender();
43  removeUnwantedLayers();
44  checkLayerReadPermissions();
45 
46  std::reverse( mLayersToRender.begin(), mLayersToRender.end() );
47 }
48 
49 void QgsWmsRenderContext::setFlag( const Flag flag, const bool on )
50 {
51  if ( on )
52  {
53  mFlags |= flag;
54  }
55  else
56  {
57  mFlags &= ~flag;
58  }
59 }
60 
62 {
63  return mFlags.testFlag( flag );
64 }
65 
67 {
68  return mParameters;
69 }
70 
72 {
73  return *mInterface->serverSettings();
74 }
75 
77 {
78  return mProject;
79 }
80 
81 QDomElement QgsWmsRenderContext::sld( const QgsMapLayer &layer ) const
82 {
83  QDomElement sld;
84 
85  const QString nickname = layerNickname( layer );
86  if ( mSlds.contains( nickname ) )
87  {
88  sld = mSlds[ nickname ];
89  }
90 
91  return sld;
92 }
93 
95 {
96  QString style;
97 
98  const QString nickname = layerNickname( layer );
99  if ( mStyles.contains( nickname ) )
100  {
101  style = mStyles[ nickname ];
102  }
103 
104  return style;
105 }
106 
108 {
110 
111  for ( const auto &params : mParameters.layersParameters() )
112  {
113  if ( params.mNickname == layerNickname( layer ) )
114  {
115  parameters = params;
116  break;
117  }
118  }
119 
120  return parameters;
121 }
122 
124 {
126 
127  if ( !mParameters.imageQuality().isEmpty() )
128  {
129  imageQuality = mParameters.imageQualityAsInt();
130  }
131 
132  return imageQuality;
133 }
134 
136 {
138 
139  if ( mParameters.wmsPrecisionAsInt() > -1 )
140  {
141  precision = mParameters.wmsPrecisionAsInt();
142  }
143 
144  return precision;
145 }
146 
148 {
149  // Apply DPI parameter if present. This is an extension of QGIS Server
150  // compared to WMS 1.3.
151  // Because of backwards compatibility, this parameter is optional
152  int dpm = 1 / OGC_PX_M;
153 
154  if ( !mParameters.dpi().isEmpty() )
155  {
156  dpm = mParameters.dpiAsDouble() / 0.0254;
157  }
158 
159  return dpm / 1000.0;
160 }
161 
163 {
164  QStringList result;
165  std::function <QStringList( const QString &name )> findLeaves = [ & ]( const QString & name ) -> QStringList
166  {
167  QStringList _result;
168  if ( mLayerGroups.contains( name ) )
169  {
170  const auto &layers { mLayerGroups[ name ] };
171  for ( const auto &l : layers )
172  {
173  const auto nick { layerNickname( *l ) };
174  // This handles the case for root (fake) group
175  if ( mLayerGroups.contains( nick ) )
176  {
177  _result.append( name );
178  }
179  else
180  {
181  _result.append( findLeaves( nick ) );
182  }
183  }
184  }
185  else
186  {
187  _result.append( name );
188  }
189  return _result;
190  };
191  const auto constNicks { mParameters.queryLayersNickname() };
192  for ( const auto &name : constNicks )
193  {
194  result.append( findLeaves( name ) );
195  }
196  return result;
197 }
198 
199 QList<QgsMapLayer *> QgsWmsRenderContext::layersToRender() const
200 {
201  return mLayersToRender;
202 }
203 
204 QList<QgsMapLayer *> QgsWmsRenderContext::layers() const
205 {
206  return mNicknameLayers.values();
207 }
208 
210 {
211  double denominator = -1;
212 
213  if ( mScaleDenominator >= 0 )
214  {
215  denominator = mScaleDenominator;
216  }
217  else if ( mFlags & UseScaleDenominator && ! mParameters.scale().isEmpty() )
218  {
219  denominator = mParameters.scaleAsDouble();
220  }
221 
222  return denominator;
223 }
224 
226 {
227  mScaleDenominator = scaleDenominator;
228  removeUnwantedLayers();
229 }
230 
232 {
233  bool update = false;
234 
235  if ( mFlags & UpdateExtent && ! mParameters.bbox().isEmpty() )
236  {
237  update = true;
238  }
239 
240  return update;
241 }
242 
244 {
245  QString name = layer.shortName();
246  if ( QgsServerProjectUtils::wmsUseLayerIds( *mProject ) )
247  {
248  name = layer.id();
249  }
250  else if ( name.isEmpty() )
251  {
252  name = layer.name();
253  }
254 
255  return name;
256 }
257 
258 QgsMapLayer *QgsWmsRenderContext::layer( const QString &nickname ) const
259 {
260  QgsMapLayer *mlayer = nullptr;
261 
262  for ( auto layer : mLayersToRender )
263  {
264  if ( layerNickname( *layer ).compare( nickname ) == 0 )
265  {
266  mlayer = layer;
267  break;
268  }
269  }
270 
271  return mlayer;
272 }
273 
274 bool QgsWmsRenderContext::isValidLayer( const QString &nickname ) const
275 {
276  return layer( nickname ) != nullptr;
277 }
278 
279 bool QgsWmsRenderContext::isValidGroup( const QString &name ) const
280 {
281  return mLayerGroups.contains( name );
282 }
283 
284 void QgsWmsRenderContext::initNicknameLayers()
285 {
286  for ( QgsMapLayer *ml : mProject->mapLayers() )
287  {
288  mNicknameLayers[ layerNickname( *ml ) ] = ml;
289  }
290 
291  // init groups
292  const QString rootName { QgsServerProjectUtils::wmsRootName( *mProject ) };
293  const QgsLayerTreeGroup *root = mProject->layerTreeRoot();
294 
295  initLayerGroupsRecursive( root, rootName.isEmpty() ? mProject->title() : rootName );
296 }
297 
298 void QgsWmsRenderContext::initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName )
299 {
300  if ( !groupName.isEmpty() )
301  {
302  mLayerGroups[groupName] = QList<QgsMapLayer *>();
303  const auto projectLayerTreeRoot { mProject->layerTreeRoot() };
304  const auto treeGroupLayers { group->findLayers() };
305  // Fast track if there is no custom layer order,
306  // otherwise reorder layers.
307  if ( ! projectLayerTreeRoot->hasCustomLayerOrder() )
308  {
309  for ( const auto &tl : treeGroupLayers )
310  {
311  mLayerGroups[groupName].push_back( tl->layer() );
312  }
313  }
314  else
315  {
316  const auto projectLayerOrder { projectLayerTreeRoot->layerOrder() };
317  // Flat list containing the layers from the tree nodes
318  QList<QgsMapLayer *> groupLayersList;
319  for ( const auto &tl : treeGroupLayers )
320  {
321  groupLayersList << tl->layer();
322  }
323  for ( const auto &l : projectLayerOrder )
324  {
325  if ( groupLayersList.contains( l ) )
326  {
327  mLayerGroups[groupName].push_back( l );
328  }
329  }
330  }
331  }
332 
333  for ( const QgsLayerTreeNode *child : group->children() )
334  {
335  if ( child->nodeType() == QgsLayerTreeNode::NodeGroup )
336  {
337  QString name = child->customProperty( QStringLiteral( "wmsShortName" ) ).toString();
338 
339  if ( name.isEmpty() )
340  name = child->name();
341 
342  initLayerGroupsRecursive( static_cast<const QgsLayerTreeGroup *>( child ), name );
343 
344  }
345  }
346 }
347 
348 void QgsWmsRenderContext::initRestrictedLayers()
349 {
350  mRestrictedLayers.clear();
351 
352  // get name of restricted layers/groups in project
353  const QStringList restricted = QgsServerProjectUtils::wmsRestrictedLayers( *mProject );
354 
355  // extract restricted layers from excluded groups
356  QStringList restrictedLayersNames;
357  QgsLayerTreeGroup *root = mProject->layerTreeRoot();
358 
359  for ( const QString &l : qgis::as_const( restricted ) )
360  {
361  const QgsLayerTreeGroup *group = root->findGroup( l );
362  if ( group )
363  {
364  const QList<QgsLayerTreeLayer *> groupLayers = group->findLayers();
365  for ( QgsLayerTreeLayer *treeLayer : groupLayers )
366  {
367  restrictedLayersNames.append( treeLayer->name() );
368  }
369  }
370  else
371  {
372  restrictedLayersNames.append( l );
373  }
374  }
375 
376  // build output with names, ids or short name according to the configuration
377  const QList<QgsLayerTreeLayer *> layers = root->findLayers();
378  for ( QgsLayerTreeLayer *layer : layers )
379  {
380  if ( restrictedLayersNames.contains( layer->name() ) )
381  {
382  mRestrictedLayers.append( layerNickname( *layer->layer() ) );
383  }
384  }
385 }
386 
387 void QgsWmsRenderContext::searchLayersToRender()
388 {
389  mLayersToRender.clear();
390  mStyles.clear();
391  mSlds.clear();
392 
393  if ( ! mParameters.sldBody().isEmpty() )
394  {
395  searchLayersToRenderSld();
396  }
397  else
398  {
399  searchLayersToRenderStyle();
400  }
401 
402  if ( mFlags & AddQueryLayers )
403  {
404  const auto constLayers { flattenedQueryLayers() };
405  for ( const QString &layer : constLayers )
406  {
407  if ( mNicknameLayers.contains( layer )
408  && !mLayersToRender.contains( mNicknameLayers[layer] ) )
409  {
410  mLayersToRender.append( mNicknameLayers[layer] );
411  }
412  }
413  }
414 }
415 
416 void QgsWmsRenderContext::searchLayersToRenderSld()
417 {
418  const QString sld = mParameters.sldBody();
419 
420  if ( sld.isEmpty() )
421  {
422  return;
423  }
424 
425  QDomDocument doc;
426  ( void )doc.setContent( sld, true );
427  QDomElement docEl = doc.documentElement();
428 
429  QDomElement root = doc.firstChildElement( "StyledLayerDescriptor" );
430  QDomElement namedElem = root.firstChildElement( "NamedLayer" );
431 
432  if ( docEl.isNull() )
433  {
434  return;
435  }
436 
437  QDomNodeList named = docEl.elementsByTagName( "NamedLayer" );
438  for ( int i = 0; i < named.size(); ++i )
439  {
440  QDomNodeList names = named.item( i ).toElement().elementsByTagName( "Name" );
441  if ( !names.isEmpty() )
442  {
443  QString lname = names.item( 0 ).toElement().text();
444  QString err;
445  if ( mNicknameLayers.contains( lname ) )
446  {
447  mSlds[lname] = namedElem;
448  mLayersToRender.append( mNicknameLayers[ lname ] );
449  }
450  else if ( mLayerGroups.contains( lname ) )
451  {
452  for ( QgsMapLayer *layer : mLayerGroups[lname] )
453  {
454  const QString name = layerNickname( *layer );
455  mSlds[name] = namedElem;
456  mLayersToRender.insert( 0, layer );
457  }
458  }
459  else
460  {
462  param.mValue = lname;
464  param );
465  }
466  }
467  }
468 }
469 
470 void QgsWmsRenderContext::searchLayersToRenderStyle()
471 {
472  for ( const QgsWmsParametersLayer &param : mParameters.layersParameters() )
473  {
474  const QString nickname = param.mNickname;
475  const QString style = param.mStyle;
476 
477  if ( mNicknameLayers.contains( nickname ) )
478  {
479  if ( !style.isEmpty() )
480  {
481  mStyles[nickname] = style;
482  }
483 
484  mLayersToRender.append( mNicknameLayers[ nickname ] );
485  }
486  else if ( mLayerGroups.contains( nickname ) )
487  {
488  // Reverse order of layers from a group
489  QList<QString> layersFromGroup;
490  for ( QgsMapLayer *layer : mLayerGroups[nickname] )
491  {
492  const QString nickname = layerNickname( *layer );
493  if ( !style.isEmpty() )
494  {
495  mStyles[ nickname ] = style;
496  }
497  layersFromGroup.push_front( nickname );
498  }
499 
500  for ( const auto &name : layersFromGroup )
501  {
502  mLayersToRender.append( mNicknameLayers[ name ] );
503  }
504  }
505  else
506  {
508  param.mValue = nickname;
510  param );
511  }
512  }
513 }
514 
515 bool QgsWmsRenderContext::layerScaleVisibility( const QString &name ) const
516 {
517  bool visible = false;
518 
519  if ( ! mNicknameLayers.contains( name ) )
520  {
521  return visible;
522  }
523 
524  const QgsMapLayer *layer = mNicknameLayers[ name ];
525  bool scaleBasedVisibility = layer->hasScaleBasedVisibility();
526  bool useScaleConstraint = ( scaleDenominator() > 0 && scaleBasedVisibility );
527 
528  if ( !useScaleConstraint || layer->isInScaleRange( scaleDenominator() ) )
529  {
530  visible = true;
531  }
532 
533  return visible;
534 }
535 
536 QMap<QString, QList<QgsMapLayer *> > QgsWmsRenderContext::layerGroups() const
537 {
538  return mLayerGroups;
539 }
540 
542 {
543  int width = mParameters.widthAsInt();
544 
545  // May use SRCWIDTH to define image map size
546  if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcWidthAsInt() > 0 )
547  {
548  width = mParameters.srcWidthAsInt();
549  }
550 
551  return width;
552 }
553 
555 {
556  int height = mParameters.heightAsInt();
557 
558  // May use SRCHEIGHT to define image map size
559  if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcHeightAsInt() > 0 )
560  {
561  height = mParameters.srcHeightAsInt();
562  }
563 
564  return height;
565 }
566 
568 {
569  //test if maxWidth / maxHeight are set in the project or as an env variable
570  //and WIDTH / HEIGHT parameter is in the range allowed range
571  //WIDTH
572  const int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
573  const int wmsMaxWidthEnv = settings().wmsMaxWidth();
574  int wmsMaxWidth;
575  if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
576  {
577  // both are set, so we take the more conservative one
578  wmsMaxWidth = std::min( wmsMaxWidthProj, wmsMaxWidthEnv );
579  }
580  else
581  {
582  // none or one are set, so we take the bigger one which is the one set or -1
583  wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
584  }
585 
586  if ( wmsMaxWidth != -1 && mapWidth() > wmsMaxWidth )
587  {
588  return false;
589  }
590 
591  //HEIGHT
592  const int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
593  const int wmsMaxHeightEnv = settings().wmsMaxHeight();
594  int wmsMaxHeight;
595  if ( wmsMaxHeightEnv != -1 && wmsMaxHeightProj != -1 )
596  {
597  // both are set, so we take the more conservative one
598  wmsMaxHeight = std::min( wmsMaxHeightProj, wmsMaxHeightEnv );
599  }
600  else
601  {
602  // none or one are set, so we take the bigger one which is the one set or -1
603  wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
604  }
605 
606  if ( wmsMaxHeight != -1 && mapHeight() > wmsMaxHeight )
607  {
608  return false;
609  }
610 
611  // Sanity check from internal QImage checks (see qimage.cpp)
612  // this is to report a meaningful error message in case of
613  // image creation failure and to differentiate it from out
614  // of memory conditions.
615 
616  // depth for now it cannot be anything other than 32, but I don't like
617  // to hardcode it: I hope we will support other depths in the future.
618  uint depth = 32;
619  switch ( mParameters.format() )
620  {
621  case QgsWmsParameters::Format::JPG:
623  default:
624  depth = 32;
625  }
626 
627  const int bytes_per_line = ( ( mapWidth() * depth + 31 ) >> 5 ) << 2; // bytes per scanline (must be multiple of 4)
628 
629  if ( std::numeric_limits<int>::max() / depth < static_cast<uint>( mapWidth() )
630  || bytes_per_line <= 0
631  || mapHeight() <= 0
632  || std::numeric_limits<int>::max() / static_cast<uint>( bytes_per_line ) < static_cast<uint>( mapHeight() )
633  || std::numeric_limits<int>::max() / sizeof( uchar * ) < static_cast<uint>( mapHeight() ) )
634  {
635  return false;
636  }
637 
638  return true;
639 }
640 
641 QSize QgsWmsRenderContext::mapSize( const bool aspectRatio ) const
642 {
643  int width = mapWidth();
644  int height = mapHeight();
645 
646  // Adapt width / height if the aspect ratio does not correspond with the BBOX.
647  // Required by WMS spec. 1.3.
648  if ( aspectRatio
649  && mParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
650  {
651  QgsRectangle extent = mParameters.bboxAsRectangle();
652  if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
653  {
655  mParameters[QgsWmsParameter::BBOX] );
656  }
657 
658  QString crs = mParameters.crs();
659  if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
660  {
661  crs = QString( "EPSG:4326" );
662  extent.invert();
663  }
664 
666  if ( outputCrs.hasAxisInverted() )
667  {
668  extent.invert();
669  }
670 
671  if ( !extent.isEmpty() && height > 0 && width > 0 )
672  {
673  const double mapRatio = extent.width() / extent.height();
674  const double imageRatio = static_cast<double>( width ) / static_cast<double>( height );
675  if ( !qgsDoubleNear( mapRatio, imageRatio, 0.0001 ) )
676  {
677  // inspired by MapServer, mapdraw.c L115
678  const double cellsize = ( extent.width() / static_cast<double>( width ) ) * 0.5 + ( extent.height() / static_cast<double>( height ) ) * 0.5;
679  width = extent.width() / cellsize;
680  height = extent.height() / cellsize;
681  }
682  }
683  }
684 
685  if ( width <= 0 )
686  {
688  mParameters[QgsWmsParameter::WIDTH] );
689  }
690  else if ( height <= 0 )
691  {
693  mParameters[QgsWmsParameter::HEIGHT] );
694  }
695 
696  return QSize( width, height );
697 }
698 
699 void QgsWmsRenderContext::removeUnwantedLayers()
700 {
701  QList<QgsMapLayer *> layers;
702 
703  for ( QgsMapLayer *layer : mLayersToRender )
704  {
705  const QString nickname = layerNickname( *layer );
706 
707  if ( !layerScaleVisibility( nickname ) )
708  continue;
709 
710  if ( mRestrictedLayers.contains( nickname ) )
711  continue;
712 
713  if ( mFlags & UseWfsLayersOnly )
714  {
716  {
717  continue;
718  }
719 
720  const QStringList wfsLayers = QgsServerProjectUtils::wfsLayerIds( *mProject );
721  if ( ! wfsLayers.contains( layer->id() ) )
722  {
723  continue;
724  }
725  }
726 
727  layers.append( layer );
728  }
729 
730  mLayersToRender = layers;
731 }
732 
733 void QgsWmsRenderContext::checkLayerReadPermissions()
734 {
735 #ifdef HAVE_SERVER_PYTHON_PLUGINS
736  for ( const auto layer : mLayersToRender )
737  {
738  if ( !accessControl()->layerReadPermission( layer ) )
739  {
740  throw QgsSecurityException( QStringLiteral( "You are not allowed to access to the layer: %1" ).arg( layer->name() ) );
741  }
742  }
743 #endif
744 }
745 
746 #ifdef HAVE_SERVER_PYTHON_PLUGINS
747 QgsAccessControl *QgsWmsRenderContext::accessControl() const
748 {
749  return mInterface->accessControls();
750 }
751 #endif
Layer tree group node serves as a container for layers and further groups.
int srcHeightAsInt() const
Returns SRCHEIGHT parameter as an int or its default value if not defined.
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:78
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
int imageQualityAsInt() const
Returns IMAGE_QUALITY parameter as an integer.
SERVER_EXPORT int wmsMaxWidth(const QgsProject &project)
Returns the maximum width for WMS images defined in a QGIS project.
QgsMapLayerType type() const
Returns the type of the layer.
QList< QgsMapLayer * > layers() const
Returns a list of all layers read from the project.
virtual QgsServerSettings * serverSettings()=0
Returns the server settings.
QgsWmsParameters parameters() const
Returns WMS parameters.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:263
QgsRectangle bboxAsRectangle() const
Returns BBOX as a rectangle if defined and valid.
QString scale() const
Returns SCALE parameter or an empty string if none is defined.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:265
QString sldBody() const
Returns SLD_body if defined or an empty string.
int wmsMaxWidth() const
Returns the server-wide max width of a WMS GetMap request.
double dpiAsDouble() const
Returns DPI parameter as an int or its default value if not defined.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
bool updateExtent() const
Returns true if the extent has to be updated before the rendering, false otherwise.
int widthAsInt() const
Returns WIDTH parameter as an int or its default value if not defined.
Provides a way to retrieve settings by prioritizing according to environment variables, ini file and default values.
QMap< QString, QList< QgsMapLayer * > > layerGroups() const
Returns a map having layer group names as keys and a list of layers as values.
Exception thrown in case of malformed request.
const QgsCoordinateReferenceSystem & crs
QStringList flattenedQueryLayers() const
Returns a list of query layer names where group names are replaced by the names of their layer compon...
int imageQuality() const
Returns the image quality to use for rendering according to the current configuration.
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
QString bbox() const
Returns BBOX if defined or an empty string.
QgsWmsRenderContext()=default
Default constructor for QgsWmsRenderContext.
bool isValidWidthHeight() const
Returns true if width and height are valid according to the maximum values defined within the project...
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
QString id() const
Returns the layer&#39;s unique ID, which is used to access this layer from QgsProject.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
QString crs() const
Returns CRS or an empty string if none is defined.
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:426
A class to describe the version of a project.
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
Provides an interface to retrieve and manipulate WMS parameters received from the client...
QString imageQuality() const
Returns IMAGE_QUALITY parameter or an empty string if not defined.
This class is a base class for nodes in a layer tree.
Reads and writes project states.
Definition: qgsproject.h:89
QgsProjectVersion versionAsNumber() const
Returns VERSION parameter if defined or its default value.
Flag
Available rendering options.
const double OGC_PX_M
QStringList queryLayersNickname() const
Returns nickname of layers found in QUERY_LAYERS parameter.
Format format() const
Returns format.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
const QgsServerSettings & settings() const
Returns settings of the server.
QSize mapSize(bool aspectRatio=true) const
Returns the size (in pixels) of the map to render, according to width and height WMS parameters as we...
int wmsMaxHeight() const
Returns the server-wide max height of a WMS GetMap request.
const QgsProject * project() const
Returns the project.
Median cut implementation.
double scaleDenominator() const
Returns the scale denominator to use for rendering according to the current configuration.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project&#39;s layer tree.
QString layerNickname(const QgsMapLayer &layer) const
Returns the nickname (short name, id or name) of the layer according to the current configuration...
int heightAsInt() const
Returns HEIGHT parameter as an int or its default value if not defined.
int wmsPrecisionAsInt() const
Returns WMS_PRECISION parameter as an int or its default value if not defined.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
double scaleAsDouble() const
Returns SCALE as a double.
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValidGroup(const QString &name) const
Returns true if name is a group.
int precision() const
Returns the precision to use according to the current configuration.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
QDomElement sld(const QgsMapLayer &layer) const
Returns a SLD document for a specific layer.
SERVER_EXPORT int wmsFeatureInfoPrecision(const QgsProject &project)
Returns the geometry precision for GetFeatureInfo request.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
Exception thrown when data access violates access controls.
bool hasAxisInverted() const
Returns whether axis is inverted (e.g., for WMS 1.3) for the CRS.
SERVER_EXPORT QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
This class represents a coordinate reference system (CRS).
int mapHeight() const
Returns HEIGHT or SRCHEIGHT according to UseSrcWidthHeight flag.
const QgsCoordinateReferenceSystem & outputCrs
A helper class that centralizes restrictions given by all the access control filter plugins...
QString name
Definition: qgsmaplayer.h:82
int srcWidthAsInt() const
Returns SRCWIDTH parameter as an int or its default value if not defined.
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
QString title() const
Returns the project&#39;s title.
Definition: qgsproject.cpp:458
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
QgsMapLayer * layer(const QString &nickname) const
Returns the layer corresponding to the nickname, or a nullptr if not found or if the layer do not nee...
SERVER_EXPORT QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.
Container of other groups and layers.
SERVER_EXPORT QString wmsRootName(const QgsProject &project)
Returns the WMS root layer name defined in a QGIS project.
QString dpi() const
Returns DPI parameter or an empty string if not defined.
QList< QgsWmsParametersLayer > layersParameters() const
Returns parameters for each layer found in LAYER/LAYERS.
WMS parameter received from the client.
QString style(const QgsMapLayer &layer) const
Returns a style&#39;s name for a specific layer.
SERVER_EXPORT int wmsImageQuality(const QgsProject &project)
Returns the quality for WMS images defined in a QGIS project.
void invert()
Swap x/y coordinates in the rectangle.
Definition: qgsrectangle.h:532
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
Layer tree node points to a map layer.
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.
int mapWidth() const
Returns WIDTH or SRCWIDTH according to UseSrcWidthHeight flag.