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