QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
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"
24
25using namespace QgsWms;
26
27const 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
51 std::reverse( mLayersToRender.begin(), mLayersToRender.end() );
52}
53
54bool QgsWmsRenderContext::addLayerToRender( QgsMapLayer *layer )
55{
56 const bool allowed = checkLayerReadPermissions( layer );
57 if ( allowed )
58 {
59 mLayersToRender.append( layer );
60 }
61 return allowed;
62}
63
64
65void QgsWmsRenderContext::setFlag( const Flag flag, const bool on )
66{
67 if ( on )
68 {
69 mFlags |= flag;
70 }
71 else
72 {
73 mFlags &= ~flag;
74 }
75}
76
78{
79 return mFlags.testFlag( flag );
80}
81
83{
84 return mParameters;
85}
86
88{
89 return *mInterface->serverSettings();
90}
91
93{
94 return mProject;
95}
96
97QDomElement QgsWmsRenderContext::sld( const QgsMapLayer &layer ) const
98{
99 QDomElement sld;
100
101 const QString nickname = layerNickname( layer );
102 if ( mSlds.contains( nickname ) )
103 {
104 sld = mSlds[nickname];
105 }
106
107 return sld;
108}
109
110QString QgsWmsRenderContext::style( const QgsMapLayer &layer ) const
111{
112 QString style;
113
114 const QString nickname = layerNickname( layer );
115 if ( mStyles.contains( nickname ) )
116 {
117 style = mStyles[nickname];
118 }
119
120 return style;
121}
122
124{
126
127 const QList<QgsWmsParametersLayer> cLayerParams { mParameters.layersParameters() };
128
129 for ( const auto &params : std::as_const( cLayerParams ) )
130 {
131 if ( params.mNickname == layerNickname( layer ) )
132 {
133 parameters = params;
134 break;
135 }
136 }
137
138 return parameters;
139}
140
142{
144
145 if ( !mParameters.imageQuality().isEmpty() )
146 {
147 imageQuality = mParameters.imageQualityAsInt();
148 }
149
150 return imageQuality;
151}
152
154{
155 int tileBuffer = 0;
156
157 if ( mParameters.tiledAsBool() )
158 {
160 }
161
162 return tileBuffer;
163}
164
169
171{
173
174 if ( mParameters.wmsPrecisionAsInt() > -1 )
175 {
176 precision = mParameters.wmsPrecisionAsInt();
177 }
178
179 return precision;
180}
181
183{
184 // Apply DPI parameter if present. This is an extension of QGIS Server
185 // compared to WMS 1.3.
186 // Because of backwards compatibility, this parameter is optional
187 qreal dpm = 1 / OGC_PX_M;
188
189 if ( !mParameters.dpi().isEmpty() )
190 {
191 dpm = mParameters.dpiAsDouble() / 0.0254;
192 }
193
194 return dpm / 1000.0;
195}
196
197QStringList QgsWmsRenderContext::flattenedQueryLayers( const QStringList &layerNames ) const
198{
199 QStringList result;
200 std::function<QStringList( const QString &name )> findLeaves = [&]( const QString &name ) -> QStringList {
201 QStringList _result;
202 if ( mLayerGroups.contains( name ) )
203 {
204 const auto &layers { mLayerGroups[name] };
205 for ( const auto &l : layers )
206 {
207 // Only add allowed layers
208 if ( checkLayerReadPermissions( l ) )
209 {
210 const auto nick { layerNickname( *l ) };
211 // This handles the case for root (fake) group
212 if ( mLayerGroups.contains( nick ) )
213 {
214 _result.append( name );
215 }
216 else
217 {
218 _result.append( findLeaves( nick ) );
219 }
220 }
221 }
222 }
223 else
224 {
225 _result.append( name );
226 }
227 return _result;
228 };
229
230 for ( const auto &name : std::as_const( layerNames ) )
231 {
232 result.append( findLeaves( name ) );
233 }
234 return result;
235}
236
237QList<QgsMapLayer *> QgsWmsRenderContext::layersToRender() const
238{
239 return mLayersToRender;
240}
241
242QList<QgsMapLayer *> QgsWmsRenderContext::layers() const
243{
244 return mNicknameLayers.values();
245}
246
248{
249 double denominator = -1;
250
251 if ( mScaleDenominator >= 0 )
252 {
253 denominator = mScaleDenominator;
254 }
255 else if ( mFlags & UseScaleDenominator && !mParameters.scale().isEmpty() )
256 {
257 denominator = mParameters.scaleAsDouble();
258 }
259
260 return denominator;
261}
262
263void QgsWmsRenderContext::setScaleDenominator( double scaleDenominator )
264{
265 mScaleDenominator = scaleDenominator;
266 removeUnwantedLayers();
267}
268
270{
271 bool update = false;
272
273 if ( mFlags & UpdateExtent && !mParameters.bbox().isEmpty() )
274 {
275 update = true;
276 }
277
278 return update;
279}
280
282{
283 QString name = layer.serverProperties()->shortName();
284 // For external layers we cannot use the layer id because it's not known to the client, use layer name instead.
285 if ( QgsServerProjectUtils::wmsUseLayerIds( *mProject ) && std::find_if( mExternalLayers.cbegin(), mExternalLayers.cend(), [&layer]( const QgsMapLayer *l ) {
286 return l->id() == layer.id();
287 } )
288 == mExternalLayers.cend() )
289 {
290 name = layer.id();
291 }
292 else if ( name.isEmpty() )
293 {
294 name = layer.name();
295 }
296
297 return name;
298}
299
300QgsMapLayer *QgsWmsRenderContext::layer( const QString &nickname ) const
301{
302 QgsMapLayer *mlayer = nullptr;
303
304 for ( auto layer : mLayersToRender )
305 {
306 if ( layerNickname( *layer ).compare( nickname ) == 0 )
307 {
308 mlayer = layer;
309 break;
310 }
311 }
312
313 return mlayer;
314}
315
316bool QgsWmsRenderContext::isValidLayer( const QString &nickname ) const
317{
318 return layer( nickname );
319}
320
321QList<QgsMapLayer *> QgsWmsRenderContext::layersFromGroup( const QString &nickname ) const
322{
323 return mLayerGroups.value( nickname );
324}
325
326bool QgsWmsRenderContext::isValidGroup( const QString &name ) const
327{
328 return mLayerGroups.contains( name );
329}
330
331void QgsWmsRenderContext::initNicknameLayers()
332{
333 for ( QgsMapLayer *ml : mProject->mapLayers() )
334 {
335 mNicknameLayers.insert( layerNickname( *ml ), ml );
336 }
337
338 // init groups
339 const QString rootName { QgsServerProjectUtils::wmsRootName( *mProject ) };
340 const QgsLayerTreeGroup *root = mProject->layerTreeRoot();
341
342 initLayerGroupsRecursive( root, rootName.isEmpty() ? mProject->title() : rootName );
343}
344
345void QgsWmsRenderContext::initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName )
346{
347 if ( !groupName.isEmpty() )
348 {
349 QList<QgsMapLayer *> layerGroup;
350 const auto projectLayerTreeRoot { mProject->layerTreeRoot() };
351 const auto treeGroupLayers { group->findLayers() };
352 // Fast track if there is no custom layer order,
353 // otherwise reorder layers.
354 if ( !projectLayerTreeRoot->hasCustomLayerOrder() )
355 {
356 for ( const auto &tl : treeGroupLayers )
357 {
358 layerGroup.push_back( tl->layer() );
359 }
360 }
361 else
362 {
363 const auto projectLayerOrder { projectLayerTreeRoot->layerOrder() };
364 // Flat list containing the layers from the tree nodes
365 QList<QgsMapLayer *> groupLayersList;
366 for ( const auto &tl : treeGroupLayers )
367 {
368 groupLayersList << tl->layer();
369 }
370 for ( const auto &l : projectLayerOrder )
371 {
372 if ( groupLayersList.contains( l ) )
373 {
374 layerGroup.push_back( l );
375 }
376 }
377 }
378
379 if ( !layerGroup.empty() )
380 {
381 mLayerGroups[groupName] = layerGroup;
382 }
383 }
384
385 for ( const QgsLayerTreeNode *child : group->children() )
386 {
387 if ( child->nodeType() == QgsLayerTreeNode::NodeGroup )
388 {
389 QString name = child->customProperty( QStringLiteral( "wmsShortName" ) ).toString();
390
391 if ( name.isEmpty() )
392 name = child->name();
393
394 initLayerGroupsRecursive( static_cast<const QgsLayerTreeGroup *>( child ), name );
395 }
396 }
397}
398
399void QgsWmsRenderContext::initRestrictedLayers()
400{
401 mRestrictedLayers.clear();
402
403 // get name of restricted layers/groups in project
404 const QStringList restricted = QgsServerProjectUtils::wmsRestrictedLayers( *mProject );
405
406 // extract restricted layers from excluded groups
407 QStringList restrictedLayersNames;
408 QgsLayerTreeGroup *root = mProject->layerTreeRoot();
409
410 for ( const QString &l : std::as_const( restricted ) )
411 {
412 const QgsLayerTreeGroup *group = root->findGroup( l );
413 if ( group )
414 {
415 const QList<QgsLayerTreeLayer *> groupLayers = group->findLayers();
416 for ( QgsLayerTreeLayer *treeLayer : groupLayers )
417 {
418 restrictedLayersNames.append( treeLayer->name() );
419 }
420 }
421 else
422 {
423 restrictedLayersNames.append( l );
424 }
425 }
426
427 // build output with names, ids or short name according to the configuration
428 const QList<QgsLayerTreeLayer *> layers = root->findLayers();
430 {
431 if ( restrictedLayersNames.contains( layer->name() ) )
432 {
433 mRestrictedLayers.append( layerNickname( *layer->layer() ) );
434 }
435 }
436}
437
438void QgsWmsRenderContext::searchLayersToRender()
439{
440 mLayersToRender.clear();
441 mStyles.clear();
442 mSlds.clear();
443
444 if ( !mParameters.sldBody().isEmpty() )
445 {
446 searchLayersToRenderSld();
447 }
448 else
449 {
450 searchLayersToRenderStyle();
451 }
452
453 if ( mFlags & AddQueryLayers )
454 {
455 const QStringList queryLayerNames = flattenedQueryLayers( mParameters.queryLayersNickname() );
456 for ( const QString &layerName : queryLayerNames )
457 {
458 const QList<QgsMapLayer *> layers = mNicknameLayers.values( layerName );
459 for ( QgsMapLayer *lyr : layers )
460 {
461 if ( !mLayersToRender.contains( lyr ) )
462 {
463 if ( !addLayerToRender( lyr ) )
464 {
465 throw QgsSecurityException( QStringLiteral( "Your are not allowed to access the layer %1" ).arg( lyr->name() ) );
466 }
467 }
468 }
469 }
470 }
471
472 if ( mFlags & AddAllLayers )
473 {
474 const QStringList queryLayerNames = flattenedQueryLayers( mParameters.allLayersNickname() );
475 for ( const QString &layerName : queryLayerNames )
476 {
477 const QList<QgsMapLayer *> layers = mNicknameLayers.values( layerName );
478 for ( QgsMapLayer *lyr : layers )
479 {
480 if ( !mLayersToRender.contains( lyr ) )
481 {
482 if ( !addLayerToRender( lyr ) )
483 {
484 throw QgsSecurityException( QStringLiteral( "Your are not allowed to access the layer %1" ).arg( lyr->name() ) );
485 }
486 }
487 }
488 }
489 }
490}
491
492void QgsWmsRenderContext::searchLayersToRenderSld()
493{
494 const QString sld = mParameters.sldBody();
495
496 if ( sld.isEmpty() )
497 {
498 return;
499 }
500
501 QDomDocument doc;
502 ( void ) doc.setContent( sld, true );
503 QDomElement docEl = doc.documentElement();
504
505 QDomElement root = doc.firstChildElement( "StyledLayerDescriptor" );
506 QDomElement namedElem = root.firstChildElement( "NamedLayer" );
507
508 if ( docEl.isNull() )
509 {
510 return;
511 }
512
513 QDomNodeList named = docEl.elementsByTagName( "NamedLayer" );
514 for ( int i = 0; i < named.size(); ++i )
515 {
516 QDomNodeList names = named.item( i ).toElement().elementsByTagName( "Name" );
517 if ( !names.isEmpty() )
518 {
519 QString lname = names.item( 0 ).toElement().text();
520 if ( mNicknameLayers.contains( lname ) )
521 {
522 mSlds[lname] = namedElem;
523 for ( const auto layer : mNicknameLayers.values( lname ) )
524 {
525 if ( !addLayerToRender( layer ) )
526 {
527 throw QgsSecurityException( QStringLiteral( "Your are not allowed to access the layer %1" ).arg( layer->name() ) );
528 }
529 }
530 }
531 else if ( mLayerGroups.contains( lname ) )
532 {
534 {
536 param.mValue = lname;
538 }
539
540 bool layerAdded = false;
541 for ( QgsMapLayer *layer : mLayerGroups[lname] )
542 {
543 // Insert only allowed layers
544 if ( checkLayerReadPermissions( layer ) )
545 {
546 const QString name = layerNickname( *layer );
547 mSlds[name] = namedElem;
548 mLayersToRender.insert( 0, layer );
549 layerAdded = true;
550 }
551 }
552 // No layers have been added, consider the group
553 // as non-existent.
554 if ( !layerAdded )
555 {
557 param.mValue = lname;
559 }
560 }
561 else
562 {
564 param.mValue = lname;
566 }
567 }
568 }
569}
570
571void QgsWmsRenderContext::searchLayersToRenderStyle()
572{
573 for ( const QgsWmsParametersLayer &param : mParameters.layersParameters() )
574 {
575 const QString nickname = param.mNickname;
576 const QString style = param.mStyle;
577
578 if ( !param.mExternalUri.isEmpty() && ( mFlags & AddExternalLayers ) )
579 {
580 std::unique_ptr<QgsMapLayer> layer = std::make_unique<QgsRasterLayer>( param.mExternalUri, param.mNickname, QStringLiteral( "wms" ) );
581
582 if ( layer->isValid() )
583 {
584 // to delete later
585 mExternalLayers.append( layer.release() );
586 auto lyr = mExternalLayers.last();
587 if ( !addLayerToRender( lyr ) )
588 {
589 throw QgsSecurityException( QStringLiteral( "Your are not allowed to access the layer %1" ).arg( lyr->name() ) );
590 }
591 }
592 }
593 else if ( mNicknameLayers.contains( nickname ) )
594 {
595 if ( !style.isEmpty() )
596 {
597 mStyles[nickname] = style;
598 }
599
600 for ( const auto layer : mNicknameLayers.values( nickname ) )
601 {
602 if ( !addLayerToRender( layer ) )
603 {
604 throw QgsSecurityException( QStringLiteral( "Your are not allowed to access the layer %1" ).arg( layer->name() ) );
605 }
606 }
607 }
608 else if ( mLayerGroups.contains( nickname ) )
609 {
611 {
613 param.mValue = nickname;
615 }
616 // Reverse order of layers from a group
617 QList<QString> layersFromGroup;
618 for ( QgsMapLayer *layer : mLayerGroups[nickname] )
619 {
620 const QString nickname = layerNickname( *layer );
621 if ( !style.isEmpty() )
622 {
623 mStyles[nickname] = style;
624 }
625 layersFromGroup.push_front( nickname );
626 }
627
628 bool layerAdded = false;
629 for ( const auto &name : layersFromGroup )
630 {
631 for ( const auto layer : mNicknameLayers.values( name ) )
632 {
633 if ( addLayerToRender( layer ) )
634 {
635 layerAdded = true;
636 }
637 }
638 }
639 // No layers have been added, consider the group
640 // as non-existent.
641 if ( !layerAdded )
642 {
644 param.mValue = nickname;
646 }
647 }
648 else
649 {
651 param.mValue = nickname;
653 }
654 }
655}
656
657bool QgsWmsRenderContext::layerScaleVisibility( const QString &name ) const
658{
659 bool visible = false;
660
661 if ( !mNicknameLayers.contains( name ) )
662 {
663 return visible;
664 }
665
666 const QList<QgsMapLayer *> layers = mNicknameLayers.values( name );
667 for ( QgsMapLayer *layer : layers )
668 {
669 bool scaleBasedVisibility = layer->hasScaleBasedVisibility();
670 bool useScaleConstraint = ( scaleDenominator() > 0 && scaleBasedVisibility );
671
672 if ( !useScaleConstraint || layer->isInScaleRange( scaleDenominator() ) )
673 {
674 visible = true;
675 }
676 }
677
678 return visible;
679}
680
681QMap<QString, QList<QgsMapLayer *>> QgsWmsRenderContext::layerGroups() const
682{
683 return mLayerGroups;
684}
685
687{
688 int width = mParameters.widthAsInt();
689
690 // May use SRCWIDTH to define image map size
691 if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcWidthAsInt() > 0 )
692 {
693 width = mParameters.srcWidthAsInt();
694 }
695
696 return width;
697}
698
700{
701 int height = mParameters.heightAsInt();
702
703 // May use SRCHEIGHT to define image map size
704 if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcHeightAsInt() > 0 )
705 {
706 height = mParameters.srcHeightAsInt();
707 }
708
709 return height;
710}
711
716
717bool QgsWmsRenderContext::isValidWidthHeight( int width, int height ) const
718{
719 if ( width <= 0 || height <= 0 )
720 return false;
721
722 //test if maxWidth / maxHeight are set in the project or as an env variable
723 //and WIDTH / HEIGHT parameter is in the range allowed range
724 //WIDTH
725 const int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
726 const int wmsMaxWidthEnv = settings().wmsMaxWidth();
727 int wmsMaxWidth;
728 if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
729 {
730 // both are set, so we take the more conservative one
731 wmsMaxWidth = std::min( wmsMaxWidthProj, wmsMaxWidthEnv );
732 }
733 else
734 {
735 // none or one are set, so we take the bigger one which is the one set or -1
736 wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
737 }
738
739 if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
740 {
741 return false;
742 }
743
744 //HEIGHT
745 const int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
746 const int wmsMaxHeightEnv = settings().wmsMaxHeight();
747 int wmsMaxHeight;
748 if ( wmsMaxHeightEnv != -1 && wmsMaxHeightProj != -1 )
749 {
750 // both are set, so we take the more conservative one
751 wmsMaxHeight = std::min( wmsMaxHeightProj, wmsMaxHeightEnv );
752 }
753 else
754 {
755 // none or one are set, so we take the bigger one which is the one set or -1
756 wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
757 }
758
759 if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
760 {
761 return false;
762 }
763
764 // Sanity check from internal QImage checks
765 // (see QImageData::calculateImageParameters() in qimage_p.h)
766 // this is to report a meaningful error message in case of
767 // image creation failure and to differentiate it from out
768 // of memory conditions.
769
770 // depth for now it cannot be anything other than 32, but I don't like
771 // to hardcode it: I hope we will support other depths in the future.
772 int depth = 32;
773 switch ( mParameters.format() )
774 {
777 default:
778 depth = 32;
779 }
780
781 if ( width > ( std::numeric_limits<int>::max() - 31 ) / depth )
782 return false;
783
784 const int bytes_per_line = ( ( width * depth + 31 ) >> 5 ) << 2; // bytes per scanline (must be multiple of 4)
785
786 if ( std::numeric_limits<int>::max() / bytes_per_line < height
787 || std::numeric_limits<int>::max() / sizeof( uchar * ) < static_cast<uint>( height ) )
788 {
789 return false;
790 }
791
792 return true;
793}
794
795double QgsWmsRenderContext::mapTileBuffer( const int mapWidth ) const
796{
797 double buffer;
798 if ( mFlags & UseTileBuffer )
799 {
800 const QgsRectangle extent = mParameters.bboxAsRectangle();
801 if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
802 {
804 }
805 buffer = tileBuffer() * ( extent.width() / mapWidth );
806 }
807 else
808 {
809 buffer = 0;
810 }
811 return buffer;
812}
813
814QSize QgsWmsRenderContext::mapSize( const bool aspectRatio ) const
815{
816 int width = mapWidth();
817 int height = mapHeight();
818
819 // Adapt width / height if the aspect ratio does not correspond with the BBOX.
820 // Required by WMS spec. 1.3.
821 if ( aspectRatio
822 && mParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
823 {
824 QgsRectangle extent = mParameters.bboxAsRectangle();
825 if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
826 {
828 }
829
830 QString crs = mParameters.crs();
831 if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
832 {
833 crs = QString( "EPSG:4326" );
834 extent.invert();
835 }
836
839 {
840 extent.invert();
841 }
842
843 if ( !extent.isEmpty() && height > 0 && width > 0 )
844 {
845 const double mapRatio = extent.width() / extent.height();
846 const double imageRatio = static_cast<double>( width ) / static_cast<double>( height );
847 if ( !qgsDoubleNear( mapRatio, imageRatio, 0.0001 ) )
848 {
849 // inspired by MapServer, mapdraw.c L115
850 const double cellsize = ( extent.width() / static_cast<double>( width ) ) * 0.5 + ( extent.height() / static_cast<double>( height ) ) * 0.5;
851 width = extent.width() / cellsize;
852 height = extent.height() / cellsize;
853 }
854 }
855 }
856
857 if ( width <= 0 )
858 {
860 }
861 else if ( height <= 0 )
862 {
864 }
865
866 return QSize( width, height );
867}
868
869void QgsWmsRenderContext::removeUnwantedLayers()
870{
871 QList<QgsMapLayer *> layers;
872
873 for ( QgsMapLayer *layer : mLayersToRender )
874 {
875 const QString nickname = layerNickname( *layer );
876
877 if ( !isExternalLayer( nickname ) )
878 {
879 if ( !layerScaleVisibility( nickname ) )
880 continue;
881
882 if ( mRestrictedLayers.contains( nickname ) )
883 continue;
884
885 if ( mFlags & UseWfsLayersOnly )
886 {
888 {
889 continue;
890 }
891
892 const QStringList wfsLayers = QgsServerProjectUtils::wfsLayerIds( *mProject );
893 if ( !wfsLayers.contains( layer->id() ) )
894 {
895 continue;
896 }
897 }
898 }
899
900 layers.append( layer );
901 }
902
903 mLayersToRender = layers;
904}
905
906bool QgsWmsRenderContext::isExternalLayer( const QString &name ) const
907{
908 for ( const auto &layer : mExternalLayers )
909 {
910 if ( layerNickname( *layer ).compare( name ) == 0 )
911 return true;
912 }
913
914 return false;
915}
916
917bool QgsWmsRenderContext::checkLayerReadPermissions( QgsMapLayer *layer ) const
918{
919#ifdef HAVE_SERVER_PYTHON_PLUGINS
920 if ( !accessControl()->layerReadPermission( layer ) )
921 {
922 QString msg = QStringLiteral( "Checking forbidden access for layer: %1" ).arg( layer->name() );
924 return false;
925 }
926#endif
927 Q_UNUSED( layer )
928 return true;
929}
930
931#ifdef HAVE_SERVER_PYTHON_PLUGINS
932QgsAccessControl *QgsWmsRenderContext::accessControl() const
933{
934 return mInterface->accessControls();
935}
936#endif
937
939{
940 mSocketFeedback = feedback;
941}
942
944{
945 return mSocketFeedback;
946}
@ Info
Information message.
Definition qgis.h:155
@ Vector
Vector layer.
A helper class that centralizes restrictions given by all the access control filter plugins.
Exception thrown in case of malformed request.
This class represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool hasAxisInverted() const
Returns whether the axis order is inverted for the CRS compared to the order east/north (longitude/la...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Layer tree group node serves as a container for layers and further groups.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
Layer tree node points to a map layer.
This class is a base class for nodes in a layer tree.
@ NodeGroup
Container of other groups and layers.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Base class for all map layer types.
Definition qgsmaplayer.h:76
QString name
Definition qgsmaplayer.h:80
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
QString id
Definition qgsmaplayer.h:79
Qgis::LayerType type
Definition qgsmaplayer.h:86
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
A class to describe the version of a project.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
QString title() const
Returns the project's title.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
A rectangle specified with double values.
void invert()
Swap x/y coordinates in the rectangle.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
virtual QgsAccessControl * accessControls() const =0
Gets the registered access control filters.
virtual QgsServerSettings * serverSettings()=0
Returns the server settings.
Provides a way to retrieve settings by prioritizing according to environment variables,...
int wmsMaxWidth() const
Returns the server-wide max width of a WMS GetMap request.
int wmsMaxHeight() const
Returns the server-wide max height of a WMS GetMap request.
Exception thrown in case of malformed request.
Exception thrown when data access violates access controls.
WMS parameter received from the client.
Provides an interface to retrieve and manipulate WMS parameters received from the client.
int wmsPrecisionAsInt() const
Returns WMS_PRECISION parameter as an int or its default value if not defined.
QStringList allLayersNickname() const
Returns nickname of layers found in LAYER and LAYERS parameters.
QgsProjectVersion versionAsNumber() const
Returns VERSION parameter if defined or its default value.
QString scale() const
Returns SCALE parameter or an empty string if none is defined.
double scaleAsDouble() const
Returns SCALE as a double.
QgsRectangle bboxAsRectangle() const
Returns BBOX as a rectangle if defined and valid.
double dpiAsDouble() const
Returns DPI parameter as an int or its default value if not defined.
QList< QgsWmsParametersLayer > layersParameters() const
Returns parameters for each layer found in LAYER/LAYERS.
QString bbox() const
Returns BBOX if defined or an empty string.
int heightAsInt() const
Returns HEIGHT parameter as an int or its default value if not defined.
Format format() const
Returns format.
int widthAsInt() const
Returns WIDTH parameter as an int or its default value if not defined.
QString sldBody() const
Returns SLD_body if defined or an empty string.
int imageQualityAsInt() const
Returns IMAGE_QUALITY parameter as an integer.
int srcHeightAsInt() const
Returns SRCHEIGHT parameter as an int or its default value if not defined.
QString imageQuality() const
Returns IMAGE_QUALITY parameter or an empty string if not defined.
QString crs() const
Returns CRS or an empty string if none is defined.
bool tiledAsBool() const
Returns TILED parameter as a boolean.
QString dpi() const
Returns DPI parameter or an empty string if not defined.
QStringList queryLayersNickname() const
Returns nickname of layers found in QUERY_LAYERS parameter.
int srcWidthAsInt() const
Returns SRCWIDTH parameter as an int or its default value if not defined.
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...
bool isExternalLayer(const QString &name) const
Returns true if the layer is an external layer, false otherwise.
bool isValidGroup(const QString &name) const
Returns true if name is a group.
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...
QgsFeedback * socketFeedback() const
Returns the response feedback if any.
QgsWmsRenderContext(const QgsProject *project, QgsServerInterface *interface)
Constructor for QgsWmsRenderContext.
QList< QgsMapLayer * > layers() const
Returns a list of all layers read from the project.
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
QList< QgsMapLayer * > layersToRender() const
Returns a list of all layers to actually render according to the current configuration.
int mapWidth() const
Returns WIDTH or SRCWIDTH according to UseSrcWidthHeight flag.
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...
int tileBuffer() const
Returns the tile buffer value to use for rendering according to the current configuration.
bool updateExtent() const
Returns true if the extent has to be updated before the rendering, false otherwise.
const QgsServerSettings & settings() const
Returns settings of the server.
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
bool isValidWidthHeight() const
Returns true if width and height are valid according to the maximum values defined within the project...
QList< QgsMapLayer * > layersFromGroup(const QString &nickname) const
Returns the group's layers list corresponding to the nickname, or an empty list if not found.
QgsWmsParameters parameters() const
Returns WMS parameters.
void setScaleDenominator(double scaleDenominator)
Sets a custom scale denominator.
QString style(const QgsMapLayer &layer) const
Returns a style's name for a specific layer.
QMap< QString, QList< QgsMapLayer * > > layerGroups() const
Returns a map having layer group names as keys and a list of layers as values.
double mapTileBuffer(int mapWidth) const
Returns the tile buffer in geographical units for the given map width in pixels.
QString layerNickname(const QgsMapLayer &layer) const
Returns the nickname (short name, id or name) of the layer according to the current configuration.
void setSocketFeedback(QgsFeedback *feedback)
Sets the response feedback.
double scaleDenominator() const
Returns the scale denominator to use for rendering according to the current configuration.
qreal dotsPerMm() const
Returns default dots per mm according to the current configuration.
bool testFlag(Flag flag) const
Returns the status of a rendering flag.
QDomElement sld(const QgsMapLayer &layer) const
Returns a SLD document for a specific layer.
bool isValidLayer(const QString &nickname) const
Returns true if the layer has to be rendered, false otherwise.
const QgsProject * project() const
Returns the project.
int precision() const
Returns the precision to use according to the current configuration.
int imageQuality() const
Returns the image quality to use for rendering according to the current configuration.
int mapHeight() const
Returns HEIGHT or SRCHEIGHT according to UseSrcWidthHeight flag.
bool renderMapTiles() const
Returns true if WMS requests should use the QgsMapSettings::RenderMapTile flag, so that no visible ar...
Flag
Available rendering options.
@ AddAllLayers
For GetPrint: add layers from LAYER(S) parameter.
SERVER_EXPORT int wmsTileBuffer(const QgsProject &project)
Returns the tile buffer in pixels for WMS images defined in a QGIS project.
SERVER_EXPORT QString wmsRootName(const QgsProject &project)
Returns the WMS root layer name defined in a QGIS project.
SERVER_EXPORT bool wmsSkipNameForGroup(const QgsProject &project)
Returns if name attribute should be skipped for groups in WMS capabilities document.
SERVER_EXPORT int wmsFeatureInfoPrecision(const QgsProject &project)
Returns the geometry precision for GetFeatureInfo request.
SERVER_EXPORT bool wmsUseLayerIds(const QgsProject &project)
Returns if layer ids are used as name in WMS.
SERVER_EXPORT QStringList wfsLayerIds(const QgsProject &project)
Returns the Layer ids list defined in a QGIS project as published in WFS.
SERVER_EXPORT bool wmsRenderMapTiles(const QgsProject &project)
Returns true if WMS requests should use the QgsMapSettings::RenderMapTile flag, so that no visible ar...
SERVER_EXPORT QStringList wmsRestrictedLayers(const QgsProject &project)
Returns the restricted layer name list.
SERVER_EXPORT int wmsImageQuality(const QgsProject &project)
Returns the quality for WMS images defined in a QGIS project.
SERVER_EXPORT int wmsMaxWidth(const QgsProject &project)
Returns the maximum width for WMS images defined in a QGIS project.
SERVER_EXPORT int wmsMaxHeight(const QgsProject &project)
Returns the maximum height for WMS images defined in a QGIS project.
Median cut implementation.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:6066
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs
const double OGC_PX_M