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