QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgswmsrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgswmsrendrer.h
3  -------------------
4  begin : May 14, 2006
5  copyright : (C) 2006 by Marco Hugentobler
6  (C) 2017 by David Marteau
7  email : marco dot hugentobler at karto dot baug dot ethz dot ch
8  david dot marteau at 3liz dot com
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #ifndef QGSWMSRENDERER_H
21 #define QGSWMSRENDERER_H
22 
23 #include "qgsserversettings.h"
24 #include "qgswmsparameters.h"
25 #include "qgswmsrendercontext.h"
26 #include "qgsfeaturefilter.h"
28 #include <QDomDocument>
29 #include <QMap>
30 #include <QString>
31 
33 class QgsPrintLayout;
34 class QgsFeature;
35 class QgsLayout;
36 class QgsMapLayer;
37 class QgsMapSettings;
38 class QgsPointXY;
39 class QgsRasterLayer;
40 class QgsRectangle;
41 class QgsRenderContext;
42 class QgsVectorLayer;
43 class QgsAccessControl;
44 class QgsDxfExport;
45 class QgsLayerTreeModel;
46 class QgsLayerTree;
47 class QgsServerInterface;
48 
49 class QImage;
50 class QPaintDevice;
51 class QPainter;
52 class QgsLayerTreeGroup;
53 
54 namespace QgsWms
55 {
56 
64  {
65  public:
66 
72  QgsRenderer( const QgsWmsRenderContext &context );
73 
77  ~QgsRenderer();
78 
86  QImage *getLegendGraphics( QgsLayerTreeModel &model );
87 
95  QImage *getLegendGraphics( QgsLayerTreeModelLegendNode &nodeModel );
96 
104  QJsonObject getLegendGraphicsAsJson( QgsLayerTreeModel &model );
105 
106  typedef QSet<QString> SymbolSet;
107  typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;
108 
113  HitTest symbols();
114 
120  QImage *getMap();
121 
127  std::unique_ptr<QgsDxfExport> getDxf();
128 
133  QByteArray getPrint();
134 
139  QByteArray getFeatureInfo( const QString &version = "1.3.0" );
140 
144  void configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings = nullptr );
145 
146  private:
147  QgsLegendSettings legendSettings() const;
148 
149  // Build and returns highlight layers
150  QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
151 
152  // Rendering step for layers
153  QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image ) const;
154 
155  // Rendering step for annotations
156  void annotationsRendering( QPainter *painter ) const;
157 
158  // Set layer opacity
159  void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
160 
161  // Set layer filter and dimension
162  void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
163 
164  QStringList dimensionFilter( QgsVectorLayer *layer ) const;
165 
166  // Set layer python filter
167  void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
168 
169  // Set layer selection
170  void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
171 
172  // Combine map extent with layer extent
173  void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
174 
175  // Scale image with WIDTH/HEIGHT if necessary
176  QImage *scaleImage( const QImage *image ) const;
177 
184  QImage *createImage( const QSize &size ) const;
185 
193  void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true ) const;
194 
195  QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
196  const QImage *outputImage, const QString &version ) const;
197 
213  bool featureInfoFromVectorLayer( QgsVectorLayer *layer,
214  const QgsPointXY *infoPoint,
215  int nFeatures,
216  QDomDocument &infoDocument,
217  QDomElement &layerElement,
218  const QgsMapSettings &mapSettings,
219  QgsRenderContext &renderContext,
220  const QString &version,
221  QgsRectangle *featureBBox = nullptr,
222  QgsGeometry *filterGeom = nullptr ) const;
223 
225  bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
226  const QgsMapSettings &mapSettings,
227  const QgsPointXY *infoPoint,
228  QDomDocument &infoDocument,
229  QDomElement &layerElement,
230  const QString &version ) const;
231 
233  void runHitTest( const QgsMapSettings &mapSettings, HitTest &hitTest ) const;
235  void runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context ) const;
236 
241  bool testFilterStringSafety( const QString &filter ) const;
243  static void groupStringList( QStringList &list, const QString &groupString );
244 
246  void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
247 
249  QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
250 
252  QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
253 
255  QByteArray convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const;
256 
257  QDomElement createFeatureGML(
258  const QgsFeature *feat,
259  QgsVectorLayer *layer,
260  QDomDocument &doc,
262  const QgsMapSettings &mapSettings,
263  const QString &typeName,
264  bool withGeom,
265  int version,
266  QStringList *attributes = nullptr ) const;
267 
269  static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
271  QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
272 
280  bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings, bool atlasPrint = false );
281 
282  void removeTemporaryLayers();
283 
284  void handlePrintErrors( const QgsLayout *layout ) const;
285 
286  void setLayerStyle( QgsMapLayer *layer, const QString &style ) const;
287 
288  void setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const;
289 
290  QgsWmsParameters mWmsParameters;
291 
292  QgsFeatureFilter mFeatureFilter;
293 
294  const QgsProject *mProject = nullptr;
295  QList<QgsMapLayer *> mTemporaryLayers;
296  const QgsWmsRenderContext &mContext;
297  };
298 
299 } // namespace QgsWms
300 
301 #endif
QgsWms::QgsWmsParameters
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Definition: qgswmsparameters.h:324
qgsserversettings.h
QgsWms::QgsRenderer::HitTest
QHash< QgsVectorLayer *, SymbolSet > HitTest
Definition: qgswmsrenderer.h:107
qgslayertreemodellegendnode.h
QgsDxfExport
Definition: qgsdxfexport.h:63
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsWms::QgsWmsRenderContext
Rendering context for the WMS renderer.
Definition: qgswmsrendercontext.h:35
QgsWms::QgsRenderer::getPrint
QByteArray getPrint()
Returns printed page as binary.
Definition: qgswmsrenderer.cpp:285
QgsLayerTreeModel
The QgsLayerTreeModel class is model implementation for Qt item views framework.
Definition: qgslayertreemodel.h:54
qgsfeaturefilter.h
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsWms::QgsRenderer::getFeatureInfo
QByteArray getFeatureInfo(const QString &version="1.3.0")
Creates an xml document that describes the result of the getFeatureInfo request.
Definition: qgswmsrenderer.cpp:911
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsLayerTree
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:33
QgsPrintLayout
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Definition: qgsprintlayout.h:31
QgsWms::QgsRenderer::QgsRenderer
QgsRenderer(const QgsWmsRenderContext &context)
Constructor for QgsRenderer.
Definition: qgswmsrenderer.cpp:98
QgsWms::QgsRenderer::~QgsRenderer
~QgsRenderer()
Destructor for QgsRenderer.
Definition: qgswmsrenderer.cpp:107
QgsWms::QgsRenderer::getMap
QImage * getMap()
Returns the map as an image (or nullptr in case of error).
Definition: qgswmsrenderer.cpp:784
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:35
QgsLegendSettings
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Definition: qgslegendsettings.h:39
typeName
const QString & typeName
Definition: qgswfsgetfeature.cpp:55
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
QgsWms::QgsRenderer::SymbolSet
QSet< QString > SymbolSet
Definition: qgswmsrenderer.h:106
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
qgswmsparameters.h
QgsWms::QgsRenderer::getDxf
std::unique_ptr< QgsDxfExport > getDxf()
Returns the map as DXF data.
Definition: qgswmsrenderer.cpp:832
withGeom
bool withGeom
Definition: qgswfsgetfeature.cpp:57
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsAccessControl
A helper class that centralizes restrictions given by all the access control filter plugins.
Definition: qgsaccesscontrol.h:37
QgsWms
Median cut implementation.
Definition: qgsdxfwriter.cpp:23
QgsFeatureFilter
A feature filter provider allowing to set filter expressions on a per-layer basis.
Definition: qgsfeaturefilter.h:35
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsWms::QgsRenderer
Map renderer for WMS requests.
Definition: qgswmsrenderer.h:64
QgsWms::QgsRenderer::getLegendGraphics
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).
Definition: qgswmsrenderer.cpp:112
QgsWms::QgsRenderer::configureLayers
void configureLayers(QList< QgsMapLayer * > &layers, QgsMapSettings *settings=nullptr)
Configures layers for rendering optionally considering the map settings.
Definition: qgswmsrenderer.cpp:3110
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map.
Definition: qgsmapsettings.h:88
QgsWms::QgsRenderer::getLegendGraphicsAsJson
QJsonObject getLegendGraphicsAsJson(QgsLayerTreeModel &model)
Returns the map legend as a JSON object.
Definition: qgswmsrenderer.cpp:182
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:61
qgswmsrendercontext.h
QgsWms::QgsRenderer::symbols
HitTest symbols()
Returns the hit test according to the current context.
Definition: qgswmsrenderer.cpp:249
QgsLayerTreeModelLegendNode
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Definition: qgslayertreemodellegendnode.h:51