QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
93 QString QgsWmsRenderContext::style( const QgsMapLayer &layer ) const
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  {
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 
236 void QgsWmsRenderContext::setScaleDenominator( double scaleDenominator )
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 
254 QString QgsWmsRenderContext::layerNickname( const QgsMapLayer &layer ) const
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 QList<QgsMapLayer *> QgsWmsRenderContext::layersFromGroup( const QString &nickname ) const
291 {
292  return mLayerGroups.value( nickname );
293 }
294 
295 bool QgsWmsRenderContext::isValidGroup( const QString &name ) const
296 {
297  return mLayerGroups.contains( name );
298 }
299 
300 void QgsWmsRenderContext::initNicknameLayers()
301 {
302  for ( QgsMapLayer *ml : mProject->mapLayers() )
303  {
304  mNicknameLayers.insert( layerNickname( *ml ), ml );
305  }
306 
307  // init groups
308  const QString rootName { QgsServerProjectUtils::wmsRootName( *mProject ) };
309  const QgsLayerTreeGroup *root = mProject->layerTreeRoot();
310 
311  initLayerGroupsRecursive( root, rootName.isEmpty() ? mProject->title() : rootName );
312 }
313 
314 void QgsWmsRenderContext::initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName )
315 {
316  if ( !groupName.isEmpty() )
317  {
318  mLayerGroups[groupName] = QList<QgsMapLayer *>();
319  const auto projectLayerTreeRoot { mProject->layerTreeRoot() };
320  const auto treeGroupLayers { group->findLayers() };
321  // Fast track if there is no custom layer order,
322  // otherwise reorder layers.
323  if ( ! projectLayerTreeRoot->hasCustomLayerOrder() )
324  {
325  for ( const auto &tl : treeGroupLayers )
326  {
327  mLayerGroups[groupName].push_back( tl->layer() );
328  }
329  }
330  else
331  {
332  const auto projectLayerOrder { projectLayerTreeRoot->layerOrder() };
333  // Flat list containing the layers from the tree nodes
334  QList<QgsMapLayer *> groupLayersList;
335  for ( const auto &tl : treeGroupLayers )
336  {
337  groupLayersList << tl->layer();
338  }
339  for ( const auto &l : projectLayerOrder )
340  {
341  if ( groupLayersList.contains( l ) )
342  {
343  mLayerGroups[groupName].push_back( l );
344  }
345  }
346  }
347  }
348 
349  for ( const QgsLayerTreeNode *child : group->children() )
350  {
351  if ( child->nodeType() == QgsLayerTreeNode::NodeGroup )
352  {
353  QString name = child->customProperty( QStringLiteral( "wmsShortName" ) ).toString();
354 
355  if ( name.isEmpty() )
356  name = child->name();
357 
358  initLayerGroupsRecursive( static_cast<const QgsLayerTreeGroup *>( child ), name );
359 
360  }
361  }
362 }
363 
364 void QgsWmsRenderContext::initRestrictedLayers()
365 {
366  mRestrictedLayers.clear();
367 
368  // get name of restricted layers/groups in project
369  const QStringList restricted = QgsServerProjectUtils::wmsRestrictedLayers( *mProject );
370 
371  // extract restricted layers from excluded groups
372  QStringList restrictedLayersNames;
373  QgsLayerTreeGroup *root = mProject->layerTreeRoot();
374 
375  for ( const QString &l : qgis::as_const( restricted ) )
376  {
377  const QgsLayerTreeGroup *group = root->findGroup( l );
378  if ( group )
379  {
380  const QList<QgsLayerTreeLayer *> groupLayers = group->findLayers();
381  for ( QgsLayerTreeLayer *treeLayer : groupLayers )
382  {
383  restrictedLayersNames.append( treeLayer->name() );
384  }
385  }
386  else
387  {
388  restrictedLayersNames.append( l );
389  }
390  }
391 
392  // build output with names, ids or short name according to the configuration
393  const QList<QgsLayerTreeLayer *> layers = root->findLayers();
394  for ( QgsLayerTreeLayer *layer : layers )
395  {
396  if ( restrictedLayersNames.contains( layer->name() ) )
397  {
398  mRestrictedLayers.append( layerNickname( *layer->layer() ) );
399  }
400  }
401 }
402 
403 void QgsWmsRenderContext::searchLayersToRender()
404 {
405  mLayersToRender.clear();
406  mStyles.clear();
407  mSlds.clear();
408 
409  if ( ! mParameters.sldBody().isEmpty() )
410  {
411  searchLayersToRenderSld();
412  }
413  else
414  {
415  searchLayersToRenderStyle();
416  }
417 
418  if ( mFlags & AddQueryLayers )
419  {
420  const QStringList queryLayerNames { flattenedQueryLayers() };
421  for ( const QString &layerName : queryLayerNames )
422  {
423  const QList<QgsMapLayer *> layers = mNicknameLayers.values( layerName );
424  for ( QgsMapLayer *lyr : layers )
425  if ( !mLayersToRender.contains( lyr ) )
426  {
427  mLayersToRender.append( lyr );
428  }
429  }
430  }
431 }
432 
433 void QgsWmsRenderContext::searchLayersToRenderSld()
434 {
435  const QString sld = mParameters.sldBody();
436 
437  if ( sld.isEmpty() )
438  {
439  return;
440  }
441 
442  QDomDocument doc;
443  ( void )doc.setContent( sld, true );
444  QDomElement docEl = doc.documentElement();
445 
446  QDomElement root = doc.firstChildElement( "StyledLayerDescriptor" );
447  QDomElement namedElem = root.firstChildElement( "NamedLayer" );
448 
449  if ( docEl.isNull() )
450  {
451  return;
452  }
453 
454  QDomNodeList named = docEl.elementsByTagName( "NamedLayer" );
455  for ( int i = 0; i < named.size(); ++i )
456  {
457  QDomNodeList names = named.item( i ).toElement().elementsByTagName( "Name" );
458  if ( !names.isEmpty() )
459  {
460  QString lname = names.item( 0 ).toElement().text();
461  if ( mNicknameLayers.contains( lname ) )
462  {
463  mSlds[lname] = namedElem;
464  mLayersToRender.append( mNicknameLayers.values( lname ) );
465  }
466  else if ( mLayerGroups.contains( lname ) )
467  {
468  for ( QgsMapLayer *layer : mLayerGroups[lname] )
469  {
470  const QString name = layerNickname( *layer );
471  mSlds[name] = namedElem;
472  mLayersToRender.insert( 0, layer );
473  }
474  }
475  else
476  {
478  param.mValue = lname;
480  param );
481  }
482  }
483  }
484 }
485 
486 void QgsWmsRenderContext::searchLayersToRenderStyle()
487 {
488  for ( const QgsWmsParametersLayer &param : mParameters.layersParameters() )
489  {
490  const QString nickname = param.mNickname;
491  const QString style = param.mStyle;
492 
493  if ( mNicknameLayers.contains( nickname ) )
494  {
495  if ( !style.isEmpty() )
496  {
497  mStyles[nickname] = style;
498  }
499 
500  mLayersToRender.append( mNicknameLayers.values( nickname ) );
501  }
502  else if ( mLayerGroups.contains( nickname ) )
503  {
504  // Reverse order of layers from a group
505  QList<QString> layersFromGroup;
506  for ( QgsMapLayer *layer : mLayerGroups[nickname] )
507  {
508  const QString nickname = layerNickname( *layer );
509  if ( !style.isEmpty() )
510  {
511  mStyles[ nickname ] = style;
512  }
513  layersFromGroup.push_front( nickname );
514  }
515 
516  for ( const auto &name : layersFromGroup )
517  {
518  mLayersToRender.append( mNicknameLayers.values( name ) );
519  }
520  }
521  else
522  {
524  param.mValue = nickname;
526  param );
527  }
528  }
529 }
530 
531 bool QgsWmsRenderContext::layerScaleVisibility( const QString &name ) const
532 {
533  bool visible = false;
534 
535  if ( ! mNicknameLayers.contains( name ) )
536  {
537  return visible;
538  }
539 
540  const QList<QgsMapLayer *>layers = mNicknameLayers.values( name );
541  for ( QgsMapLayer *layer : layers )
542  {
543  bool scaleBasedVisibility = layer->hasScaleBasedVisibility();
544  bool useScaleConstraint = ( scaleDenominator() > 0 && scaleBasedVisibility );
545 
546  if ( !useScaleConstraint || layer->isInScaleRange( scaleDenominator() ) )
547  {
548  visible = true;
549  }
550  }
551 
552  return visible;
553 }
554 
555 QMap<QString, QList<QgsMapLayer *> > QgsWmsRenderContext::layerGroups() const
556 {
557  return mLayerGroups;
558 }
559 
561 {
562  int width = mParameters.widthAsInt();
563 
564  // May use SRCWIDTH to define image map size
565  if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcWidthAsInt() > 0 )
566  {
567  width = mParameters.srcWidthAsInt();
568  }
569 
570  return width;
571 }
572 
574 {
575  int height = mParameters.heightAsInt();
576 
577  // May use SRCHEIGHT to define image map size
578  if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcHeightAsInt() > 0 )
579  {
580  height = mParameters.srcHeightAsInt();
581  }
582 
583  return height;
584 }
585 
587 {
588  //test if maxWidth / maxHeight are set in the project or as an env variable
589  //and WIDTH / HEIGHT parameter is in the range allowed range
590  //WIDTH
591  const int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
592  const int wmsMaxWidthEnv = settings().wmsMaxWidth();
593  int wmsMaxWidth;
594  if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
595  {
596  // both are set, so we take the more conservative one
597  wmsMaxWidth = std::min( wmsMaxWidthProj, wmsMaxWidthEnv );
598  }
599  else
600  {
601  // none or one are set, so we take the bigger one which is the one set or -1
602  wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
603  }
604 
605  if ( wmsMaxWidth != -1 && mapWidth() > wmsMaxWidth )
606  {
607  return false;
608  }
609 
610  //HEIGHT
611  const int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
612  const int wmsMaxHeightEnv = settings().wmsMaxHeight();
613  int wmsMaxHeight;
614  if ( wmsMaxHeightEnv != -1 && wmsMaxHeightProj != -1 )
615  {
616  // both are set, so we take the more conservative one
617  wmsMaxHeight = std::min( wmsMaxHeightProj, wmsMaxHeightEnv );
618  }
619  else
620  {
621  // none or one are set, so we take the bigger one which is the one set or -1
622  wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
623  }
624 
625  if ( wmsMaxHeight != -1 && mapHeight() > wmsMaxHeight )
626  {
627  return false;
628  }
629 
630  // Sanity check from internal QImage checks (see qimage.cpp)
631  // this is to report a meaningful error message in case of
632  // image creation failure and to differentiate it from out
633  // of memory conditions.
634 
635  // depth for now it cannot be anything other than 32, but I don't like
636  // to hardcode it: I hope we will support other depths in the future.
637  uint depth = 32;
638  switch ( mParameters.format() )
639  {
640  case QgsWmsParameters::Format::JPG:
642  default:
643  depth = 32;
644  }
645 
646  const int bytes_per_line = ( ( mapWidth() * depth + 31 ) >> 5 ) << 2; // bytes per scanline (must be multiple of 4)
647 
648  if ( std::numeric_limits<int>::max() / depth < static_cast<uint>( mapWidth() )
649  || bytes_per_line <= 0
650  || mapHeight() <= 0
651  || std::numeric_limits<int>::max() / static_cast<uint>( bytes_per_line ) < static_cast<uint>( mapHeight() )
652  || std::numeric_limits<int>::max() / sizeof( uchar * ) < static_cast<uint>( mapHeight() ) )
653  {
654  return false;
655  }
656 
657  return true;
658 }
659 
660 double QgsWmsRenderContext::mapTileBuffer( const int mapWidth ) const
661 {
662  double buffer;
663  if ( mFlags & UseTileBuffer )
664  {
665  const QgsRectangle extent = mParameters.bboxAsRectangle();
666  if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
667  {
669  mParameters[QgsWmsParameter::BBOX] );
670  }
671  buffer = tileBuffer() * ( extent.width() / mapWidth );
672  }
673  else
674  {
675  buffer = 0;
676  }
677  return buffer;
678 }
679 
680 QSize QgsWmsRenderContext::mapSize( const bool aspectRatio ) const
681 {
682  int width = mapWidth();
683  int height = mapHeight();
684 
685  // Adapt width / height if the aspect ratio does not correspond with the BBOX.
686  // Required by WMS spec. 1.3.
687  if ( aspectRatio
688  && mParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
689  {
690  QgsRectangle extent = mParameters.bboxAsRectangle();
691  if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
692  {
694  mParameters[QgsWmsParameter::BBOX] );
695  }
696 
697  QString crs = mParameters.crs();
698  if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
699  {
700  crs = QString( "EPSG:4326" );
701  extent.invert();
702  }
703 
705  if ( outputCrs.hasAxisInverted() )
706  {
707  extent.invert();
708  }
709 
710  if ( !extent.isEmpty() && height > 0 && width > 0 )
711  {
712  const double mapRatio = extent.width() / extent.height();
713  const double imageRatio = static_cast<double>( width ) / static_cast<double>( height );
714  if ( !qgsDoubleNear( mapRatio, imageRatio, 0.0001 ) )
715  {
716  // inspired by MapServer, mapdraw.c L115
717  const double cellsize = ( extent.width() / static_cast<double>( width ) ) * 0.5 + ( extent.height() / static_cast<double>( height ) ) * 0.5;
718  width = extent.width() / cellsize;
719  height = extent.height() / cellsize;
720  }
721  }
722  }
723 
724  if ( width <= 0 )
725  {
727  mParameters[QgsWmsParameter::WIDTH] );
728  }
729  else if ( height <= 0 )
730  {
732  mParameters[QgsWmsParameter::HEIGHT] );
733  }
734 
735  return QSize( width, height );
736 }
737 
738 void QgsWmsRenderContext::removeUnwantedLayers()
739 {
740  QList<QgsMapLayer *> layers;
741 
742  for ( QgsMapLayer *layer : mLayersToRender )
743  {
744  const QString nickname = layerNickname( *layer );
745 
746  if ( !layerScaleVisibility( nickname ) )
747  continue;
748 
749  if ( mRestrictedLayers.contains( nickname ) )
750  continue;
751 
752  if ( mFlags & UseWfsLayersOnly )
753  {
755  {
756  continue;
757  }
758 
759  const QStringList wfsLayers = QgsServerProjectUtils::wfsLayerIds( *mProject );
760  if ( ! wfsLayers.contains( layer->id() ) )
761  {
762  continue;
763  }
764  }
765 
766  layers.append( layer );
767  }
768 
769  mLayersToRender = layers;
770 }
771 
772 void QgsWmsRenderContext::checkLayerReadPermissions()
773 {
774 #ifdef HAVE_SERVER_PYTHON_PLUGINS
775  for ( const auto layer : mLayersToRender )
776  {
777  if ( !accessControl()->layerReadPermission( layer ) )
778  {
779  throw QgsSecurityException( QStringLiteral( "You are not allowed to access to the layer: %1" ).arg( layer->name() ) );
780  }
781  }
782 #endif
783 }
784 
785 #ifdef HAVE_SERVER_PYTHON_PLUGINS
786 QgsAccessControl *QgsWmsRenderContext::accessControl() const
787 {
788  return mInterface->accessControls();
789 }
790 #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:101
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:336
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:479
QgsWms::QgsWmsRenderContext::mapWidth
int mapWidth() const
Returns WIDTH or SRCWIDTH according to UseSrcWidthHeight flag.
Definition: qgswmsrendercontext.cpp:560
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:290
QgsLayerTreeNode
Definition: qgslayertreenode.h:74
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:418
QgsWms::QgsWmsParameters::wmsPrecisionAsInt
int wmsPrecisionAsInt() const
Returns WMS_PRECISION parameter as an int or its default value if not defined.
Definition: qgswmsparameters.cpp:1334
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:93
QgsProject::mapLayers
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Definition: qgsproject.cpp:3347
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: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: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:48
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:34
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:242
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:555
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:586
QgsCoordinateReferenceSystem::hasAxisInverted
bool hasAxisInverted() const
Returns whether axis is inverted (e.g., for WMS 1.3) for the CRS.
Definition: qgscoordinatereferencesystem.cpp:808
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:122
QgsWms::QgsWmsParameter::WIDTH
@ WIDTH
Definition: qgswmsparameters.h:123
QgsWms::QgsWmsParameters::dpi
QString dpi() const
Returns DPI parameter or an empty string if not defined.
Definition: qgswmsparameters.cpp:746
QgsServerInterface::accessControls
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
QgsWms::QgsWmsParametersLayer
Definition: qgswmsparameters.h:62
QgsRectangle
Definition: qgsrectangle.h:41
OGC_PX_M
const double OGC_PX_M
Definition: qgswmsrendercontext.cpp:26
QgsProject
Definition: qgsproject.h:92
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:82
QgsWms::QgsWmsParameter::LAYER
@ LAYER
Definition: qgswmsparameters.h:133
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:63
QgsWms::QgsWmsRenderContext::tileBuffer
int tileBuffer() const
Returns the tile buffer value to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:134
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:669
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:3016
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: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:120
QgsWms::QgsWmsRenderContext::QgsWmsRenderContext
QgsWmsRenderContext()=default
Default constructor for QgsWmsRenderContext.
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:680
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:173
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:236
QgsWms::PNG
@ PNG
Definition: qgswmsutils.h:42
QgsLayerTreeLayer
Definition: qgslayertreelayer.h:43
QgsServerProjectUtils::wmsRestrictedLayers
SERVER_EXPORT QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.
Definition: qgsserverprojectutils.cpp:311
QgsLayerTreeGroup
Definition: qgslayertreegroup.h:34
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:61
QgsWms::QgsWmsRenderContext::settings
const QgsServerSettings & settings() const
Returns settings of the server.
Definition: qgswmsrendercontext.cpp:70
QgsWms::QgsWmsRenderContext::isValidLayer
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
Definition: qgswmsrendercontext.cpp:285
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:146
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:676
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:80
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:254
QgsWms::QgsWmsParameter::BBOX
@ BBOX
Definition: qgswmsparameters.h:125
QgsWms::QgsWmsParameters::format
Format format() const
Returns format.
Definition: qgswmsparameters.cpp:790
QgsCoordinateReferenceSystem
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:36
QgsWms
WMS implementation.
Definition: qgsdxfwriter.cpp:22
QgsWms::QgsWmsRenderContext::isValidGroup
bool isValidGroup(const QString &name) const
Returns true if name is a group.
Definition: qgswmsrendercontext.cpp:295
QgsWms::QgsWmsRenderContext::scaleDenominator
double scaleDenominator() const
Returns the scale denominator to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:220
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:269
QgsWms::QgsBadRequestException
Exception thrown in case of malformed request.
Definition: qgswmsserviceexception.h:226
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsWms::QgsWmsRenderContext::testFlag
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
Definition: qgswmsrendercontext.cpp:60
QgsWms::QgsWmsParameters::scale
QString scale() const
Returns SCALE parameter or an empty string if none is defined.
Definition: qgswmsparameters.cpp:937
QgsRectangle::height
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
QgsServerSettings::wmsMaxHeight
int wmsMaxHeight() const
Returns the server-wide max height of a WMS GetMap request.
Definition: qgsserversettings.cpp:413
QgsWms::QgsWmsRenderContext::project
const QgsProject * project() const
Returns the project.
Definition: qgswmsrendercontext.cpp:75
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:660
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:85
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:111
qgswmsserviceexception.h
QgsWms::QgsWmsParameter::HEIGHT
@ HEIGHT
Definition: qgswmsparameters.h:124
QgsWms::QgsWmsRenderContext::dotsPerMm
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
Definition: qgswmsrendercontext.cpp:158
QgsWms::QgsWmsRenderContext::UseScaleDenominator
@ UseScaleDenominator
Definition: qgswmsrendercontext.h:53
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:210
QgsWms::QgsWmsRenderContext::UseTileBuffer
@ UseTileBuffer
Definition: qgswmsrendercontext.h:64
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
QgsMapLayer::type
QgsMapLayerType type() const
Returns the type of the layer.
Definition: qgsmaplayer.cpp:129
QgsWms::QgsWmsRenderContext::mapHeight
int mapHeight() const
Returns HEIGHT or SRCHEIGHT according to UseSrcWidthHeight flag.
Definition: qgswmsrendercontext.cpp:573
QgsWms::QgsWmsRenderContext::layers
QList< QgsMapLayer * > layers() const
Returns a list of all layers read from the project.
Definition: qgswmsrendercontext.cpp:215
QgsServerInterface
Definition: qgsserverinterface.h:60
QgsRectangle::width
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsProjectVersion
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:65
qgswmsrendercontext.h