QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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.insert( 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 QStringList queryLayerNames { flattenedQueryLayers() };
416  for ( const QString &layerName : queryLayerNames )
417  {
418  const QList<QgsMapLayer *> layers = mNicknameLayers.values( layerName );
419  for ( QgsMapLayer *lyr : layers )
420  if ( !mLayersToRender.contains( lyr ) )
421  {
422  mLayersToRender.append( lyr );
423  }
424  }
425  }
426 }
427 
428 void QgsWmsRenderContext::searchLayersToRenderSld()
429 {
430  const QString sld = mParameters.sldBody();
431 
432  if ( sld.isEmpty() )
433  {
434  return;
435  }
436 
437  QDomDocument doc;
438  ( void )doc.setContent( sld, true );
439  QDomElement docEl = doc.documentElement();
440 
441  QDomElement root = doc.firstChildElement( "StyledLayerDescriptor" );
442  QDomElement namedElem = root.firstChildElement( "NamedLayer" );
443 
444  if ( docEl.isNull() )
445  {
446  return;
447  }
448 
449  QDomNodeList named = docEl.elementsByTagName( "NamedLayer" );
450  for ( int i = 0; i < named.size(); ++i )
451  {
452  QDomNodeList names = named.item( i ).toElement().elementsByTagName( "Name" );
453  if ( !names.isEmpty() )
454  {
455  QString lname = names.item( 0 ).toElement().text();
456  if ( mNicknameLayers.contains( lname ) )
457  {
458  mSlds[lname] = namedElem;
459  mLayersToRender.append( mNicknameLayers.values( 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.values( 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.values( 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 QList<QgsMapLayer *>layers = mNicknameLayers.values( name );
536  for ( QgsMapLayer *layer : layers )
537  {
538  bool scaleBasedVisibility = layer->hasScaleBasedVisibility();
539  bool useScaleConstraint = ( scaleDenominator() > 0 && scaleBasedVisibility );
540 
541  if ( !useScaleConstraint || layer->isInScaleRange( scaleDenominator() ) )
542  {
543  visible = true;
544  }
545  }
546 
547  return visible;
548 }
549 
550 QMap<QString, QList<QgsMapLayer *> > QgsWmsRenderContext::layerGroups() const
551 {
552  return mLayerGroups;
553 }
554 
556 {
557  int width = mParameters.widthAsInt();
558 
559  // May use SRCWIDTH to define image map size
560  if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcWidthAsInt() > 0 )
561  {
562  width = mParameters.srcWidthAsInt();
563  }
564 
565  return width;
566 }
567 
569 {
570  int height = mParameters.heightAsInt();
571 
572  // May use SRCHEIGHT to define image map size
573  if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcHeightAsInt() > 0 )
574  {
575  height = mParameters.srcHeightAsInt();
576  }
577 
578  return height;
579 }
580 
582 {
583  //test if maxWidth / maxHeight are set in the project or as an env variable
584  //and WIDTH / HEIGHT parameter is in the range allowed range
585  //WIDTH
586  const int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
587  const int wmsMaxWidthEnv = settings().wmsMaxWidth();
588  int wmsMaxWidth;
589  if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
590  {
591  // both are set, so we take the more conservative one
592  wmsMaxWidth = std::min( wmsMaxWidthProj, wmsMaxWidthEnv );
593  }
594  else
595  {
596  // none or one are set, so we take the bigger one which is the one set or -1
597  wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
598  }
599 
600  if ( wmsMaxWidth != -1 && mapWidth() > wmsMaxWidth )
601  {
602  return false;
603  }
604 
605  //HEIGHT
606  const int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
607  const int wmsMaxHeightEnv = settings().wmsMaxHeight();
608  int wmsMaxHeight;
609  if ( wmsMaxHeightEnv != -1 && wmsMaxHeightProj != -1 )
610  {
611  // both are set, so we take the more conservative one
612  wmsMaxHeight = std::min( wmsMaxHeightProj, wmsMaxHeightEnv );
613  }
614  else
615  {
616  // none or one are set, so we take the bigger one which is the one set or -1
617  wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
618  }
619 
620  if ( wmsMaxHeight != -1 && mapHeight() > wmsMaxHeight )
621  {
622  return false;
623  }
624 
625  // Sanity check from internal QImage checks (see qimage.cpp)
626  // this is to report a meaningful error message in case of
627  // image creation failure and to differentiate it from out
628  // of memory conditions.
629 
630  // depth for now it cannot be anything other than 32, but I don't like
631  // to hardcode it: I hope we will support other depths in the future.
632  uint depth = 32;
633  switch ( mParameters.format() )
634  {
635  case QgsWmsParameters::Format::JPG:
637  default:
638  depth = 32;
639  }
640 
641  const int bytes_per_line = ( ( mapWidth() * depth + 31 ) >> 5 ) << 2; // bytes per scanline (must be multiple of 4)
642 
643  if ( std::numeric_limits<int>::max() / depth < static_cast<uint>( mapWidth() )
644  || bytes_per_line <= 0
645  || mapHeight() <= 0
646  || std::numeric_limits<int>::max() / static_cast<uint>( bytes_per_line ) < static_cast<uint>( mapHeight() )
647  || std::numeric_limits<int>::max() / sizeof( uchar * ) < static_cast<uint>( mapHeight() ) )
648  {
649  return false;
650  }
651 
652  return true;
653 }
654 
656 {
657  double buffer;
658  if ( mFlags & UseTileBuffer )
659  {
660  const QgsRectangle extent = mParameters.bboxAsRectangle();
661  if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
662  {
664  mParameters[QgsWmsParameter::BBOX] );
665  }
666  buffer = tileBuffer() * ( extent.width() / mapWidth );
667  }
668  else
669  {
670  buffer = 0;
671  }
672  return buffer;
673 }
674 
675 QSize QgsWmsRenderContext::mapSize( const bool aspectRatio ) const
676 {
677  int width = mapWidth();
678  int height = mapHeight();
679 
680  // Adapt width / height if the aspect ratio does not correspond with the BBOX.
681  // Required by WMS spec. 1.3.
682  if ( aspectRatio
683  && mParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
684  {
685  QgsRectangle extent = mParameters.bboxAsRectangle();
686  if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
687  {
689  mParameters[QgsWmsParameter::BBOX] );
690  }
691 
692  QString crs = mParameters.crs();
693  if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
694  {
695  crs = QString( "EPSG:4326" );
696  extent.invert();
697  }
698 
700  if ( outputCrs.hasAxisInverted() )
701  {
702  extent.invert();
703  }
704 
705  if ( !extent.isEmpty() && height > 0 && width > 0 )
706  {
707  const double mapRatio = extent.width() / extent.height();
708  const double imageRatio = static_cast<double>( width ) / static_cast<double>( height );
709  if ( !qgsDoubleNear( mapRatio, imageRatio, 0.0001 ) )
710  {
711  // inspired by MapServer, mapdraw.c L115
712  const double cellsize = ( extent.width() / static_cast<double>( width ) ) * 0.5 + ( extent.height() / static_cast<double>( height ) ) * 0.5;
713  width = extent.width() / cellsize;
714  height = extent.height() / cellsize;
715  }
716  }
717  }
718 
719  if ( width <= 0 )
720  {
722  mParameters[QgsWmsParameter::WIDTH] );
723  }
724  else if ( height <= 0 )
725  {
727  mParameters[QgsWmsParameter::HEIGHT] );
728  }
729 
730  return QSize( width, height );
731 }
732 
733 void QgsWmsRenderContext::removeUnwantedLayers()
734 {
735  QList<QgsMapLayer *> layers;
736 
737  for ( QgsMapLayer *layer : mLayersToRender )
738  {
739  const QString nickname = layerNickname( *layer );
740 
741  if ( !layerScaleVisibility( nickname ) )
742  continue;
743 
744  if ( mRestrictedLayers.contains( nickname ) )
745  continue;
746 
747  if ( mFlags & UseWfsLayersOnly )
748  {
750  {
751  continue;
752  }
753 
754  const QStringList wfsLayers = QgsServerProjectUtils::wfsLayerIds( *mProject );
755  if ( ! wfsLayers.contains( layer->id() ) )
756  {
757  continue;
758  }
759  }
760 
761  layers.append( layer );
762  }
763 
764  mLayersToRender = layers;
765 }
766 
767 void QgsWmsRenderContext::checkLayerReadPermissions()
768 {
769 #ifdef HAVE_SERVER_PYTHON_PLUGINS
770  for ( const auto layer : mLayersToRender )
771  {
772  if ( !accessControl()->layerReadPermission( layer ) )
773  {
774  throw QgsSecurityException( QStringLiteral( "You are not allowed to access to the layer: %1" ).arg( layer->name() ) );
775  }
776  }
777 #endif
778 }
779 
780 #ifdef HAVE_SERVER_PYTHON_PLUGINS
781 QgsAccessControl *QgsWmsRenderContext::accessControl() const
782 {
783  return mInterface->accessControls();
784 }
785 #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:315
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:91
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:471
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.