QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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 checkLayerReadPermissions();
51
52 std::reverse( mLayersToRender.begin(), mLayersToRender.end() );
53}
54
55void 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
87QDomElement 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
100QString 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
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
187QStringList 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
224QList<QgsMapLayer *> QgsWmsRenderContext::layersToRender() const
225{
226 return mLayersToRender;
227}
228
229QList<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
250void 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
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
289QgsMapLayer *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
305bool QgsWmsRenderContext::isValidLayer( const QString &nickname ) const
306{
307 return layer( nickname ) != nullptr;
308}
309
310QList<QgsMapLayer *> QgsWmsRenderContext::layersFromGroup( const QString &nickname ) const
311{
312 return mLayerGroups.value( nickname );
313}
314
315bool QgsWmsRenderContext::isValidGroup( const QString &name ) const
316{
317 return mLayerGroups.contains( name );
318}
319
320void 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
334void 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
384void 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();
415 {
416 if ( restrictedLayersNames.contains( layer->name() ) )
417 {
418 mRestrictedLayers.append( layerNickname( *layer->layer() ) );
419 }
420 }
421}
422
423void 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
467void 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 {
503 {
505 param.mValue = lname;
507 param );
508 }
509 for ( QgsMapLayer *layer : mLayerGroups[lname] )
510 {
511 const QString name = layerNickname( *layer );
512 mSlds[name] = namedElem;
513 mLayersToRender.insert( 0, layer );
514 }
515 }
516 else
517 {
519 param.mValue = lname;
521 param );
522 }
523 }
524 }
525}
526
527void QgsWmsRenderContext::searchLayersToRenderStyle()
528{
529 for ( const QgsWmsParametersLayer &param : mParameters.layersParameters() )
530 {
531 const QString nickname = param.mNickname;
532 const QString style = param.mStyle;
533
534 if ( ! param.mExternalUri.isEmpty() && ( mFlags & AddExternalLayers ) )
535 {
536
537 std::unique_ptr<QgsMapLayer> layer = std::make_unique< QgsRasterLayer >( param.mExternalUri, param.mNickname, QStringLiteral( "wms" ) );
538
539 if ( layer->isValid() )
540 {
541 // to delete later
542 mExternalLayers.append( layer.release() );
543 mLayersToRender.append( mExternalLayers.last() );
544 }
545 }
546 else if ( mNicknameLayers.contains( nickname ) )
547 {
548 if ( !style.isEmpty() )
549 {
550 mStyles[nickname] = style;
551 }
552
553 mLayersToRender.append( mNicknameLayers.values( nickname ) );
554 }
555 else if ( mLayerGroups.contains( nickname ) )
556 {
558 {
560 param.mValue = nickname;
562 param );
563 }
564 // Reverse order of layers from a group
565 QList<QString> layersFromGroup;
566 for ( QgsMapLayer *layer : mLayerGroups[nickname] )
567 {
568 const QString nickname = layerNickname( *layer );
569 if ( !style.isEmpty() )
570 {
571 mStyles[ nickname ] = style;
572 }
573 layersFromGroup.push_front( nickname );
574 }
575
576 for ( const auto &name : layersFromGroup )
577 {
578 mLayersToRender.append( mNicknameLayers.values( name ) );
579 }
580 }
581 else
582 {
584 param.mValue = nickname;
586 param );
587 }
588 }
589}
590
591bool QgsWmsRenderContext::layerScaleVisibility( const QString &name ) const
592{
593 bool visible = false;
594
595 if ( ! mNicknameLayers.contains( name ) )
596 {
597 return visible;
598 }
599
600 const QList<QgsMapLayer *>layers = mNicknameLayers.values( name );
601 for ( QgsMapLayer *layer : layers )
602 {
603 bool scaleBasedVisibility = layer->hasScaleBasedVisibility();
604 bool useScaleConstraint = ( scaleDenominator() > 0 && scaleBasedVisibility );
605
606 if ( !useScaleConstraint || layer->isInScaleRange( scaleDenominator() ) )
607 {
608 visible = true;
609 }
610 }
611
612 return visible;
613}
614
615QMap<QString, QList<QgsMapLayer *> > QgsWmsRenderContext::layerGroups() const
616{
617 return mLayerGroups;
618}
619
621{
622 int width = mParameters.widthAsInt();
623
624 // May use SRCWIDTH to define image map size
625 if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcWidthAsInt() > 0 )
626 {
627 width = mParameters.srcWidthAsInt();
628 }
629
630 return width;
631}
632
634{
635 int height = mParameters.heightAsInt();
636
637 // May use SRCHEIGHT to define image map size
638 if ( ( mFlags & UseSrcWidthHeight ) && mParameters.srcHeightAsInt() > 0 )
639 {
640 height = mParameters.srcHeightAsInt();
641 }
642
643 return height;
644}
645
650
651bool QgsWmsRenderContext::isValidWidthHeight( int width, int height ) const
652{
653 //test if maxWidth / maxHeight are set in the project or as an env variable
654 //and WIDTH / HEIGHT parameter is in the range allowed range
655 //WIDTH
656 const int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
657 const int wmsMaxWidthEnv = settings().wmsMaxWidth();
658 int wmsMaxWidth;
659 if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
660 {
661 // both are set, so we take the more conservative one
662 wmsMaxWidth = std::min( wmsMaxWidthProj, wmsMaxWidthEnv );
663 }
664 else
665 {
666 // none or one are set, so we take the bigger one which is the one set or -1
667 wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
668 }
669
670 if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
671 {
672 return false;
673 }
674
675 //HEIGHT
676 const int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
677 const int wmsMaxHeightEnv = settings().wmsMaxHeight();
678 int wmsMaxHeight;
679 if ( wmsMaxHeightEnv != -1 && wmsMaxHeightProj != -1 )
680 {
681 // both are set, so we take the more conservative one
682 wmsMaxHeight = std::min( wmsMaxHeightProj, wmsMaxHeightEnv );
683 }
684 else
685 {
686 // none or one are set, so we take the bigger one which is the one set or -1
687 wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
688 }
689
690 if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
691 {
692 return false;
693 }
694
695 // Sanity check from internal QImage checks (see qimage.cpp)
696 // this is to report a meaningful error message in case of
697 // image creation failure and to differentiate it from out
698 // of memory conditions.
699
700 // depth for now it cannot be anything other than 32, but I don't like
701 // to hardcode it: I hope we will support other depths in the future.
702 uint depth = 32;
703 switch ( mParameters.format() )
704 {
707 default:
708 depth = 32;
709 }
710
711 const int bytes_per_line = ( ( width * depth + 31 ) >> 5 ) << 2; // bytes per scanline (must be multiple of 4)
712
713 if ( std::numeric_limits<int>::max() / depth < static_cast<uint>( width )
714 || bytes_per_line <= 0
715 || height <= 0
716 || std::numeric_limits<int>::max() / static_cast<uint>( bytes_per_line ) < static_cast<uint>( height )
717 || std::numeric_limits<int>::max() / sizeof( uchar * ) < static_cast<uint>( height ) )
718 {
719 return false;
720 }
721
722 return true;
723}
724
725double QgsWmsRenderContext::mapTileBuffer( const int mapWidth ) const
726{
727 double buffer;
728 if ( mFlags & UseTileBuffer )
729 {
730 const QgsRectangle extent = mParameters.bboxAsRectangle();
731 if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
732 {
734 mParameters[QgsWmsParameter::BBOX] );
735 }
736 buffer = tileBuffer() * ( extent.width() / mapWidth );
737 }
738 else
739 {
740 buffer = 0;
741 }
742 return buffer;
743}
744
745QSize QgsWmsRenderContext::mapSize( const bool aspectRatio ) const
746{
747 int width = mapWidth();
748 int height = mapHeight();
749
750 // Adapt width / height if the aspect ratio does not correspond with the BBOX.
751 // Required by WMS spec. 1.3.
752 if ( aspectRatio
753 && mParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
754 {
755 QgsRectangle extent = mParameters.bboxAsRectangle();
756 if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
757 {
759 mParameters[QgsWmsParameter::BBOX] );
760 }
761
762 QString crs = mParameters.crs();
763 if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
764 {
765 crs = QString( "EPSG:4326" );
766 extent.invert();
767 }
768
771 {
772 extent.invert();
773 }
774
775 if ( !extent.isEmpty() && height > 0 && width > 0 )
776 {
777 const double mapRatio = extent.width() / extent.height();
778 const double imageRatio = static_cast<double>( width ) / static_cast<double>( height );
779 if ( !qgsDoubleNear( mapRatio, imageRatio, 0.0001 ) )
780 {
781 // inspired by MapServer, mapdraw.c L115
782 const double cellsize = ( extent.width() / static_cast<double>( width ) ) * 0.5 + ( extent.height() / static_cast<double>( height ) ) * 0.5;
783 width = extent.width() / cellsize;
784 height = extent.height() / cellsize;
785 }
786 }
787 }
788
789 if ( width <= 0 )
790 {
792 mParameters[QgsWmsParameter::WIDTH] );
793 }
794 else if ( height <= 0 )
795 {
797 mParameters[QgsWmsParameter::HEIGHT] );
798 }
799
800 return QSize( width, height );
801}
802
803void QgsWmsRenderContext::removeUnwantedLayers()
804{
805 QList<QgsMapLayer *> layers;
806
807 for ( QgsMapLayer *layer : mLayersToRender )
808 {
809 const QString nickname = layerNickname( *layer );
810
811 if ( ! isExternalLayer( nickname ) )
812 {
813 if ( !layerScaleVisibility( nickname ) )
814 continue;
815
816 if ( mRestrictedLayers.contains( nickname ) )
817 continue;
818
819 if ( mFlags & UseWfsLayersOnly )
820 {
822 {
823 continue;
824 }
825
826 const QStringList wfsLayers = QgsServerProjectUtils::wfsLayerIds( *mProject );
827 if ( ! wfsLayers.contains( layer->id() ) )
828 {
829 continue;
830 }
831 }
832 }
833
834 layers.append( layer );
835 }
836
837 mLayersToRender = layers;
838}
839
840bool QgsWmsRenderContext::isExternalLayer( const QString &name ) const
841{
842 for ( const auto &layer : mExternalLayers )
843 {
844 if ( layerNickname( *layer ).compare( name ) == 0 )
845 return true;
846 }
847
848 return false;
849}
850
851void QgsWmsRenderContext::checkLayerReadPermissions()
852{
853#ifdef HAVE_SERVER_PYTHON_PLUGINS
854 for ( const auto layer : mLayersToRender )
855 {
856 if ( !accessControl()->layerReadPermission( layer ) )
857 {
858 throw QgsSecurityException( QStringLiteral( "You are not allowed to access to the layer: %1" ).arg( layer->name() ) );
859 }
860 }
861#endif
862}
863
864#ifdef HAVE_SERVER_PYTHON_PLUGINS
865QgsAccessControl *QgsWmsRenderContext::accessControl() const
866{
867 return mInterface->accessControls();
868}
869#endif
870
872{
873 mSocketFeedback = feedback;
874}
875
877{
878 return mSocketFeedback;
879}
@ 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.
Base class for all map layer types.
Definition qgsmaplayer.h:75
QString name
Definition qgsmaplayer.h:78
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Qgis::LayerType type
Definition qgsmaplayer.h:82
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
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.
double width() const
Returns the width of the rectangle.
bool isEmpty() const
Returns true if the rectangle has no area.
double height() const
Returns the height of the rectangle.
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()
Destructor for QgsWmsRenderContext.
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:5144
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs
const double OGC_PX_M