QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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
28  : mProject( project )
29  , mInterface( interface )
30  , mFlags()
31 {
32 }
33 
35 {
36  mParameters = parameters;
37 
38  initRestrictedLayers();
39  initNicknameLayers();
40 
41  searchLayersToRender();
42  removeUnwantedLayers();
43  checkLayerReadPermissions();
44 
45  std::reverse( mLayersToRender.begin(), mLayersToRender.end() );
46 }
47 
48 void QgsWmsRenderContext::setFlag( const Flag flag, const bool on )
49 {
50  if ( on )
51  {
52  mFlags |= flag;
53  }
54  else
55  {
56  mFlags &= ~flag;
57  }
58 }
59 
61 {
62  return mFlags.testFlag( flag );
63 }
64 
66 {
67  return mParameters;
68 }
69 
71 {
72  return *mInterface->serverSettings();
73 }
74 
76 {
77  return mProject;
78 }
79 
80 QDomElement QgsWmsRenderContext::sld( const QgsMapLayer &layer ) const
81 {
82  QDomElement sld;
83 
84  const QString nickname = layerNickname( layer );
85  if ( mSlds.contains( nickname ) )
86  {
87  sld = mSlds[ nickname ];
88  }
89 
90  return sld;
91 }
92 
94 {
95  QString style;
96 
97  const QString nickname = layerNickname( layer );
98  if ( mStyles.contains( nickname ) )
99  {
100  style = mStyles[ nickname ];
101  }
102 
103  return style;
104 }
105 
107 {
109 
110  for ( const auto &params : mParameters.layersParameters() )
111  {
112  if ( params.mNickname == layerNickname( layer ) )
113  {
114  parameters = params;
115  break;
116  }
117  }
118 
119  return parameters;
120 }
121 
123 {
125 
126  if ( !mParameters.imageQuality().isEmpty() )
127  {
128  imageQuality = mParameters.imageQualityAsInt();
129  }
130 
131  return imageQuality;
132 }
133 
135 {
136  int tileBuffer = 0;
137 
138  if ( mParameters.tiledAsBool() )
139  {
140  tileBuffer = QgsServerProjectUtils::wmsTileBuffer( *mProject );
141  }
142 
143  return tileBuffer;
144 }
145 
147 {
149 
150  if ( mParameters.wmsPrecisionAsInt() > -1 )
151  {
152  precision = mParameters.wmsPrecisionAsInt();
153  }
154 
155  return precision;
156 }
157 
159 {
160  // Apply DPI parameter if present. This is an extension of QGIS Server
161  // compared to WMS 1.3.
162  // Because of backwards compatibility, this parameter is optional
163  int dpm = 1 / OGC_PX_M;
164 
165  if ( !mParameters.dpi().isEmpty() )
166  {
167  dpm = mParameters.dpiAsDouble() / 0.0254;
168  }
169 
170  return dpm / 1000.0;
171 }
172 
174 {
175  QStringList result;
176  std::function <QStringList( const QString &name )> findLeaves = [ & ]( const QString & name ) -> QStringList
177  {
178  QStringList _result;
179  if ( mLayerGroups.contains( name ) )
180  {
181  const auto &layers { mLayerGroups[ name ] };
182  for ( const auto &l : layers )
183  {
184  const auto nick { layerNickname( *l ) };
185  // This handles the case for root (fake) group
186  if ( mLayerGroups.contains( nick ) )
187  {
188  _result.append( name );
189  }
190  else
191  {
192  _result.append( findLeaves( nick ) );
193  }
194  }
195  }
196  else
197  {
198  _result.append( name );
199  }
200  return _result;
201  };
202  const auto constNicks { mParameters.queryLayersNickname() };
203  for ( const auto &name : constNicks )
204  {
205  result.append( findLeaves( name ) );
206  }
207  return result;
208 }
209 
210 QList<QgsMapLayer *> QgsWmsRenderContext::layersToRender() const
211 {
212  return mLayersToRender;
213 }
214 
215 QList<QgsMapLayer *> QgsWmsRenderContext::layers() const
216 {
217  return mNicknameLayers.values();
218 }
219 
221 {
222  double denominator = -1;
223 
224  if ( mScaleDenominator >= 0 )
225  {
226  denominator = mScaleDenominator;
227  }
228  else if ( mFlags & UseScaleDenominator && ! mParameters.scale().isEmpty() )
229  {
230  denominator = mParameters.scaleAsDouble();
231  }
232 
233  return denominator;
234 }
235 
237 {
238  mScaleDenominator = scaleDenominator;
239  removeUnwantedLayers();
240 }
241 
243 {
244  bool update = false;
245 
246  if ( mFlags & UpdateExtent && ! mParameters.bbox().isEmpty() )
247  {
248  update = true;
249  }
250 
251  return update;
252 }
253 
255 {
256  QString name = layer.shortName();
257  if ( QgsServerProjectUtils::wmsUseLayerIds( *mProject ) )
258  {
259  name = layer.id();
260  }
261  else if ( name.isEmpty() )
262  {
263  name = layer.name();
264  }
265 
266  return name;
267 }
268 
269 QgsMapLayer *QgsWmsRenderContext::layer( const QString &nickname ) const
270 {
271  QgsMapLayer *mlayer = nullptr;
272 
273  for ( auto layer : mLayersToRender )
274  {
275  if ( layerNickname( *layer ).compare( nickname ) == 0 )
276  {
277  mlayer = layer;
278  break;
279  }
280  }
281 
282  return mlayer;
283 }
284 
285 bool QgsWmsRenderContext::isValidLayer( const QString &nickname ) const
286 {
287  return layer( nickname ) != nullptr;
288 }
289 
290 bool QgsWmsRenderContext::isValidGroup( const QString &name ) const
291 {
292  return mLayerGroups.contains( name );
293 }
294 
295 void QgsWmsRenderContext::initNicknameLayers()
296 {
297  for ( QgsMapLayer *ml : mProject->mapLayers() )
298  {
299  mNicknameLayers[ layerNickname( *ml ) ] = ml;
300  }
301 
302  // init groups
303  const QString rootName { QgsServerProjectUtils::wmsRootName( *mProject ) };
304  const QgsLayerTreeGroup *root = mProject->layerTreeRoot();
305 
306  initLayerGroupsRecursive( root, rootName.isEmpty() ? mProject->title() : rootName );
307 }
308 
309 void QgsWmsRenderContext::initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName )
310 {
311  if ( !groupName.isEmpty() )
312  {
313  mLayerGroups[groupName] = QList<QgsMapLayer *>();
314  const auto projectLayerTreeRoot { mProject->layerTreeRoot() };
315  const auto treeGroupLayers { group->findLayers() };
316  // Fast track if there is no custom layer order,
317  // otherwise reorder layers.
318  if ( ! projectLayerTreeRoot->hasCustomLayerOrder() )
319  {
320  for ( const auto &tl : treeGroupLayers )
321  {
322  mLayerGroups[groupName].push_back( tl->layer() );
323  }
324  }
325  else
326  {
327  const auto projectLayerOrder { projectLayerTreeRoot->layerOrder() };
328  // Flat list containing the layers from the tree nodes
329  QList<QgsMapLayer *> groupLayersList;
330  for ( const auto &tl : treeGroupLayers )
331  {
332  groupLayersList << tl->layer();
333  }
334  for ( const auto &l : projectLayerOrder )
335  {
336  if ( groupLayersList.contains( l ) )
337  {
338  mLayerGroups[groupName].push_back( l );
339  }
340  }
341  }
342  }
343 
344  for ( const QgsLayerTreeNode *child : group->children() )
345  {
346  if ( child->nodeType() == QgsLayerTreeNode::NodeGroup )
347  {
348  QString name = child->customProperty( QStringLiteral( "wmsShortName" ) ).toString();
349 
350  if ( name.isEmpty() )
351  name = child->name();
352 
353  initLayerGroupsRecursive( static_cast<const QgsLayerTreeGroup *>( child ), name );
354 
355  }
356  }
357 }
358 
359 void QgsWmsRenderContext::initRestrictedLayers()
360 {
361  mRestrictedLayers.clear();
362 
363  // get name of restricted layers/groups in project
364  const QStringList restricted = QgsServerProjectUtils::wmsRestrictedLayers( *mProject );
365 
366  // extract restricted layers from excluded groups
367  QStringList restrictedLayersNames;
368  QgsLayerTreeGroup *root = mProject->layerTreeRoot();
369 
370  for ( const QString &l : qgis::as_const( restricted ) )
371  {
372  const QgsLayerTreeGroup *group = root->findGroup( l );
373  if ( group )
374  {
375  const QList<QgsLayerTreeLayer *> groupLayers = group->findLayers();
376  for ( QgsLayerTreeLayer *treeLayer : groupLayers )
377  {
378  restrictedLayersNames.append( treeLayer->name() );
379  }
380  }
381  else
382  {
383  restrictedLayersNames.append( l );
384  }
385  }
386 
387  // build output with names, ids or short name according to the configuration
388  const QList<QgsLayerTreeLayer *> layers = root->findLayers();
389  for ( QgsLayerTreeLayer *layer : layers )
390  {
391  if ( restrictedLayersNames.contains( layer->name() ) )
392  {
393  mRestrictedLayers.append( layerNickname( *layer->layer() ) );
394  }
395  }
396 }
397 
398 void QgsWmsRenderContext::searchLayersToRender()
399 {
400  mLayersToRender.clear();
401  mStyles.clear();
402  mSlds.clear();
403 
404  if ( ! mParameters.sldBody().isEmpty() )
405  {
406  searchLayersToRenderSld();
407  }
408  else
409  {
410  searchLayersToRenderStyle();
411  }
412 
413  if ( mFlags & AddQueryLayers )
414  {
415  const auto constLayers { flattenedQueryLayers() };
416  for ( const QString &layer : constLayers )
417  {
418  if ( mNicknameLayers.contains( layer )
419  && !mLayersToRender.contains( mNicknameLayers[layer] ) )
420  {
421  mLayersToRender.append( mNicknameLayers[layer] );
422  }
423  }
424  }
425 }
426 
427 void QgsWmsRenderContext::searchLayersToRenderSld()
428 {
429  const QString sld = mParameters.sldBody();
430 
431  if ( sld.isEmpty() )
432  {
433  return;
434  }
435 
436  QDomDocument doc;
437  ( void )doc.setContent( sld, true );
438  QDomElement docEl = doc.documentElement();
439 
440  QDomElement root = doc.firstChildElement( "StyledLayerDescriptor" );
441  QDomElement namedElem = root.firstChildElement( "NamedLayer" );
442 
443  if ( docEl.isNull() )
444  {
445  return;
446  }
447 
448  QDomNodeList named = docEl.elementsByTagName( "NamedLayer" );
449  for ( int i = 0; i < named.size(); ++i )
450  {
451  QDomNodeList names = named.item( i ).toElement().elementsByTagName( "Name" );
452  if ( !names.isEmpty() )
453  {
454  QString lname = names.item( 0 ).toElement().text();
455  QString err;
456  if ( mNicknameLayers.contains( lname ) )
457  {
458  mSlds[lname] = namedElem;
459  mLayersToRender.append( mNicknameLayers[ lname ] );
460  }
461  else if ( mLayerGroups.contains( lname ) )
462  {
463  for ( QgsMapLayer *layer : mLayerGroups[lname] )
464  {
465  const QString name = layerNickname( *layer );
466  mSlds[name] = namedElem;
467  mLayersToRender.insert( 0, layer );
468  }
469  }
470  else
471  {
473  param.mValue = lname;
475  param );
476  }
477  }
478  }
479 }
480 
481 void QgsWmsRenderContext::searchLayersToRenderStyle()
482 {
483  for ( const QgsWmsParametersLayer &param : mParameters.layersParameters() )
484  {
485  const QString nickname = param.mNickname;
486  const QString style = param.mStyle;
487 
488  if ( mNicknameLayers.contains( nickname ) )
489  {
490  if ( !style.isEmpty() )
491  {
492  mStyles[nickname] = style;
493  }
494 
495  mLayersToRender.append( mNicknameLayers[ nickname ] );
496  }
497  else if ( mLayerGroups.contains( nickname ) )
498  {
499  // Reverse order of layers from a group
500  QList<QString> layersFromGroup;
501  for ( QgsMapLayer *layer : mLayerGroups[nickname] )
502  {
503  const QString nickname = layerNickname( *layer );
504  if ( !style.isEmpty() )
505  {
506  mStyles[ nickname ] = style;
507  }
508  layersFromGroup.push_front( nickname );
509  }
510 
511  for ( const auto &name : layersFromGroup )
512  {
513  mLayersToRender.append( mNicknameLayers[ name ] );
514  }
515  }
516  else
517  {
519  param.mValue = nickname;
521  param );
522  }
523  }
524 }
525 
526 bool QgsWmsRenderContext::layerScaleVisibility( const QString &name ) const
527 {
528  bool visible = false;
529 
530  if ( ! mNicknameLayers.contains( name ) )
531  {
532  return visible;
533  }
534 
535  const QgsMapLayer *layer = mNicknameLayers[ name ];
536  bool scaleBasedVisibility = layer->hasScaleBasedVisibility();
537  bool useScaleConstraint = ( scaleDenominator() > 0 && scaleBasedVisibility );
538 
539  if ( !useScaleConstraint || layer->isInScaleRange( scaleDenominator() ) )
540  {
541  visible = true;
542  }
543 
544  return visible;
545 }
546 
547 QMap<QString, QList<QgsMapLayer *> > QgsWmsRenderContext::layerGroups() const
548 {
549  return mLayerGroups;
550 }
551 
553 {
554  int width = mParameters.widthAsInt();
555 
556  // May use SRCWIDTH to define image map size
557  if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcWidthAsInt() > 0 )
558  {
559  width = mParameters.srcWidthAsInt();
560  }
561 
562  return width;
563 }
564 
566 {
567  int height = mParameters.heightAsInt();
568 
569  // May use SRCHEIGHT to define image map size
570  if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcHeightAsInt() > 0 )
571  {
572  height = mParameters.srcHeightAsInt();
573  }
574 
575  return height;
576 }
577 
579 {
580  //test if maxWidth / maxHeight are set in the project or as an env variable
581  //and WIDTH / HEIGHT parameter is in the range allowed range
582  //WIDTH
583  const int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
584  const int wmsMaxWidthEnv = settings().wmsMaxWidth();
585  int wmsMaxWidth;
586  if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
587  {
588  // both are set, so we take the more conservative one
589  wmsMaxWidth = std::min( wmsMaxWidthProj, wmsMaxWidthEnv );
590  }
591  else
592  {
593  // none or one are set, so we take the bigger one which is the one set or -1
594  wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
595  }
596 
597  if ( wmsMaxWidth != -1 && mapWidth() > wmsMaxWidth )
598  {
599  return false;
600  }
601 
602  //HEIGHT
603  const int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
604  const int wmsMaxHeightEnv = settings().wmsMaxHeight();
605  int wmsMaxHeight;
606  if ( wmsMaxHeightEnv != -1 && wmsMaxHeightProj != -1 )
607  {
608  // both are set, so we take the more conservative one
609  wmsMaxHeight = std::min( wmsMaxHeightProj, wmsMaxHeightEnv );
610  }
611  else
612  {
613  // none or one are set, so we take the bigger one which is the one set or -1
614  wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
615  }
616 
617  if ( wmsMaxHeight != -1 && mapHeight() > wmsMaxHeight )
618  {
619  return false;
620  }
621 
622  // Sanity check from internal QImage checks (see qimage.cpp)
623  // this is to report a meaningful error message in case of
624  // image creation failure and to differentiate it from out
625  // of memory conditions.
626 
627  // depth for now it cannot be anything other than 32, but I don't like
628  // to hardcode it: I hope we will support other depths in the future.
629  uint depth = 32;
630  switch ( mParameters.format() )
631  {
632  case QgsWmsParameters::Format::JPG:
634  default:
635  depth = 32;
636  }
637 
638  const int bytes_per_line = ( ( mapWidth() * depth + 31 ) >> 5 ) << 2; // bytes per scanline (must be multiple of 4)
639 
640  if ( std::numeric_limits<int>::max() / depth < static_cast<uint>( mapWidth() )
641  || bytes_per_line <= 0
642  || mapHeight() <= 0
643  || std::numeric_limits<int>::max() / static_cast<uint>( bytes_per_line ) < static_cast<uint>( mapHeight() )
644  || std::numeric_limits<int>::max() / sizeof( uchar * ) < static_cast<uint>( mapHeight() ) )
645  {
646  return false;
647  }
648 
649  return true;
650 }
651 
653 {
654  double buffer;
655  if ( mFlags & UseTileBuffer )
656  {
657  const QgsRectangle extent = mParameters.bboxAsRectangle();
658  if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
659  {
661  mParameters[QgsWmsParameter::BBOX] );
662  }
663  buffer = tileBuffer() * ( extent.width() / mapWidth );
664  }
665  else
666  {
667  buffer = 0;
668  }
669  return buffer;
670 }
671 
672 QSize QgsWmsRenderContext::mapSize( const bool aspectRatio ) const
673 {
674  int width = mapWidth();
675  int height = mapHeight();
676 
677  // Adapt width / height if the aspect ratio does not correspond with the BBOX.
678  // Required by WMS spec. 1.3.
679  if ( aspectRatio
680  && mParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
681  {
682  QgsRectangle extent = mParameters.bboxAsRectangle();
683  if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
684  {
686  mParameters[QgsWmsParameter::BBOX] );
687  }
688 
689  QString crs = mParameters.crs();
690  if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
691  {
692  crs = QString( "EPSG:4326" );
693  extent.invert();
694  }
695 
697  if ( outputCrs.hasAxisInverted() )
698  {
699  extent.invert();
700  }
701 
702  if ( !extent.isEmpty() && height > 0 && width > 0 )
703  {
704  const double mapRatio = extent.width() / extent.height();
705  const double imageRatio = static_cast<double>( width ) / static_cast<double>( height );
706  if ( !qgsDoubleNear( mapRatio, imageRatio, 0.0001 ) )
707  {
708  // inspired by MapServer, mapdraw.c L115
709  const double cellsize = ( extent.width() / static_cast<double>( width ) ) * 0.5 + ( extent.height() / static_cast<double>( height ) ) * 0.5;
710  width = extent.width() / cellsize;
711  height = extent.height() / cellsize;
712  }
713  }
714  }
715 
716  if ( width <= 0 )
717  {
719  mParameters[QgsWmsParameter::WIDTH] );
720  }
721  else if ( height <= 0 )
722  {
724  mParameters[QgsWmsParameter::HEIGHT] );
725  }
726 
727  return QSize( width, height );
728 }
729 
730 void QgsWmsRenderContext::removeUnwantedLayers()
731 {
732  QList<QgsMapLayer *> layers;
733 
734  for ( QgsMapLayer *layer : mLayersToRender )
735  {
736  const QString nickname = layerNickname( *layer );
737 
738  if ( !layerScaleVisibility( nickname ) )
739  continue;
740 
741  if ( mRestrictedLayers.contains( nickname ) )
742  continue;
743 
744  if ( mFlags & UseWfsLayersOnly )
745  {
747  {
748  continue;
749  }
750 
751  const QStringList wfsLayers = QgsServerProjectUtils::wfsLayerIds( *mProject );
752  if ( ! wfsLayers.contains( layer->id() ) )
753  {
754  continue;
755  }
756  }
757 
758  layers.append( layer );
759  }
760 
761  mLayersToRender = layers;
762 }
763 
764 void QgsWmsRenderContext::checkLayerReadPermissions()
765 {
766 #ifdef HAVE_SERVER_PYTHON_PLUGINS
767  for ( const auto layer : mLayersToRender )
768  {
769  if ( !accessControl()->layerReadPermission( layer ) )
770  {
771  throw QgsSecurityException( QStringLiteral( "You are not allowed to access to the layer: %1" ).arg( layer->name() ) );
772  }
773  }
774 #endif
775 }
776 
777 #ifdef HAVE_SERVER_PYTHON_PLUGINS
778 QgsAccessControl *QgsWmsRenderContext::accessControl() const
779 {
780  return mInterface->accessControls();
781 }
782 #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:79
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.
SERVER_EXPORT int wmsTileBuffer(const QgsProject &project)
Returns the tile buffer in pixels 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.
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:280
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.
int tileBuffer() const
Returns the tile buffer value to use for rendering according to the current configuration.
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...
bool tiledAsBool() const
Returns TILED parameter as a boolean.
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
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.
double mapTileBuffer(int mapWidth) const
Returns the tile buffer in geographical units for the given map width in pixels.
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:83
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:463
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.