QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
132  QByteArray getPrint();
133 
138  QByteArray getFeatureInfo( const QString &version = "1.3.0" );
139 
143  void configureLayers( QList<QgsMapLayer *> &layers, QgsMapSettings *settings = nullptr );
144 
145  private:
146  QgsLegendSettings legendSettings() const;
147 
148  // Build and returns highlight layers
149  QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
150 
151  // Build and returns external layers
152  QList<QgsMapLayer *> externalLayers( const QList<QgsWmsParametersExternalLayer> &params );
153 
154  // Rendering step for layers
155  QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image ) const;
156 
157  // Rendering step for annotations
158  void annotationsRendering( QPainter *painter ) const;
159 
160  // Set layer opacity
161  void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
162 
163  // Set layer filter and dimension
164  void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
165 
166  QStringList dimensionFilter( QgsVectorLayer *layer ) const;
167 
168  // Set layer python filter
169  void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
170 
171  // Set layer selection
172  void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
173 
174  // Combine map extent with layer extent
175  void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
176 
177  // Scale image with WIDTH/HEIGHT if necessary
178  QImage *scaleImage( const QImage *image ) const;
179 
186  QImage *createImage( const QSize &size ) const;
187 
195  void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true ) const;
196 
197  QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
198  const QImage *outputImage, const QString &version ) const;
199 
215  bool featureInfoFromVectorLayer( QgsVectorLayer *layer,
216  const QgsPointXY *infoPoint,
217  int nFeatures,
218  QDomDocument &infoDocument,
219  QDomElement &layerElement,
220  const QgsMapSettings &mapSettings,
221  QgsRenderContext &renderContext,
222  const QString &version,
223  QgsRectangle *featureBBox = nullptr,
224  QgsGeometry *filterGeom = nullptr ) const;
225 
227  bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
228  const QgsMapSettings &mapSettings,
229  const QgsPointXY *infoPoint,
230  QDomDocument &infoDocument,
231  QDomElement &layerElement,
232  const QString &version ) const;
233 
235  void runHitTest( const QgsMapSettings &mapSettings, HitTest &hitTest ) const;
237  void runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context ) const;
238 
242  bool testFilterStringSafety( const QString &filter ) const;
244  static void groupStringList( QStringList &list, const QString &groupString );
245 
247  void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
248 
250  QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
251 
253  QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
254 
256  QByteArray convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const;
257 
258  QDomElement createFeatureGML(
259  const QgsFeature *feat,
260  QgsVectorLayer *layer,
261  QDomDocument &doc,
263  const QgsMapSettings &mapSettings,
264  const QString &typeName,
265  bool withGeom,
266  int version,
267  QStringList *attributes = nullptr ) const;
268 
270  static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
272  QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
273 
274  /*
275  * Configures the print layout for the GetPrint request
276  *\param c the print layout
277  *\param mapSettings the map settings
278  *\param atlasPrint true if atlas is used for printing
279  *\returns true in case of success
280  * */
281  bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings, bool atlasPrint = false );
282 
283  void removeTemporaryLayers();
284 
285  void handlePrintErrors( const QgsLayout *layout ) const;
286 
287  void setLayerStyle( QgsMapLayer *layer, const QString &style ) const;
288 
289  void setLayerSld( QgsMapLayer *layer, const QDomElement &sld ) const;
290 
291  QgsWmsParameters mWmsParameters;
292 
293  QgsFeatureFilter mFeatureFilter;
294 
295  const QgsProject *mProject = nullptr;
296  QList<QgsMapLayer *> mTemporaryLayers;
297  QgsWmsRenderContext mContext;
298  };
299 
300 } // namespace QgsWms
301 
302 #endif
QByteArray getFeatureInfo(const QString &version="1.3.0")
Creates an xml document that describes the result of the getFeatureInfo request.
Layer tree group node serves as a container for layers and further groups.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:79
~QgsRenderer()
Destructor for QgsRenderer.
HitTest symbols()
Returns the hit test according to the current context.
Represents a raster layer.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QByteArray getPrint()
Returns printed page as binary.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
const QgsCoordinateReferenceSystem & crs
bool withGeom
The QgsMapSettings class contains configuration for rendering of the map.
QImage * getMap()
Returns the map as an image (or nullptr in case of error).
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
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QHash< QgsVectorLayer *, SymbolSet > HitTest
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:32
QJsonObject getLegendGraphicsAsJson(QgsLayerTreeModel &model)
Returns the map legend as a JSON object.
const QString & typeName
A feature filter provider allowing to set filter expressions on a per-layer basis.
Provides an interface to retrieve and manipulate WMS parameters received from the client...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
void configureLayers(QList< QgsMapLayer *> &layers, QgsMapSettings *settings=nullptr)
Configures layers for rendering optionally considering the map settings.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:91
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsRenderer(const QgsWmsRenderContext &context)
Constructor for QgsRenderer.
Median cut implementation.
QSet< QString > SymbolSet
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
Map renderer for WMS requests.
Contains information about the context of a rendering operation.
Rendering context for the WMS renderer.
This class represents a coordinate reference system (CRS).
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
A helper class that centralizes restrictions given by all the access control filter plugins...
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Represents a vector layer which manages a vector based data sets.
QImage * getLegendGraphics(QgsLayerTreeModel &model)
Returns the map legend as an image (or nullptr in case of error).
std::unique_ptr< QgsDxfExport > getDxf()
Returns the map as DXF data.