QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 "qgsfeaturefilter.h"
26 #include <QDomDocument>
27 #include <QMap>
28 #include <QPair>
29 #include <QString>
30 #include <map>
31 
34 class QgsPrintLayout;
35 class QgsConfigParser;
36 class QgsFeature;
37 class QgsFeatureRenderer;
38 class QgsMapLayer;
39 class QgsMapSettings;
40 class QgsPointXY;
41 class QgsRasterLayer;
42 class QgsRasterRenderer;
43 class QgsRectangle;
44 class QgsRenderContext;
45 class QgsVectorLayer;
46 class QgsSymbol;
47 class QgsSymbol;
48 class QgsAccessControl;
49 class QgsDxfExport;
50 class QgsLayerTreeModel;
51 class QgsLayerTree;
52 
53 class QColor;
54 class QFile;
55 class QFont;
56 class QImage;
57 class QPaintDevice;
58 class QPainter;
59 class QStandardItem;
60 class QgsLayerTreeGroup;
61 
62 namespace QgsWms
63 {
64 
72  {
73  public:
74 
78  QgsRenderer( QgsServerInterface *serverIface,
79  const QgsProject *project,
80  QgsWmsParameters &parameters );
81 
82  ~QgsRenderer();
83 
87  QImage *getLegendGraphics();
88 
89  typedef QSet<QString> SymbolSet;
90  typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;
91 
96  QImage *getMap( HitTest *hitTest = nullptr );
97 
101  QImage *getMap( QgsMapSettings &mapSettings, HitTest *hitTest = nullptr );
102 
108  QgsDxfExport getDxf( const QMap<QString, QString> &options );
109 
114  QByteArray getPrint( const QString &formatString );
115 
120  QByteArray getFeatureInfo( const QString &version = "1.3.0" );
121 
122  private:
123 
124  // Init the restricted layers with nicknames
125  void initRestrictedLayers();
126 
127  // Build and returns highlight layers
128  QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
129 
130  // Init a map with nickname for layers' project
131  void initNicknameLayers();
132 
133  void initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName );
134 
135  // Return the nickname of the layer (short name, id or name according to
136  // the project configuration)
137  QString layerNickname( const QgsMapLayer &layer ) const;
138 
139  // Return true if the layer has to be displayed according to he current
140  // scale
141  bool layerScaleVisibility( const QgsMapLayer &layer, double scaleDenominator ) const;
142 
143  // Remove unwanted layers (restricted, not visible, etc)
144  void removeUnwantedLayers( QList<QgsMapLayer *> &layers, double scaleDenominator = -1 ) const;
145 
146  // Remove non identifiable layers (restricted, not visible, etc)
147  void removeNonIdentifiableLayers( QList<QgsMapLayer *> &layers ) const;
148 
149  // Rendering step for layers
150  QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image, HitTest *hitTest = nullptr ) const;
151 
152  // Rendering step for annotations
153  void annotationsRendering( QPainter *painter ) const;
154 
155  // Return a list of layers stylized with LAYERS/STYLES parameters
156  QList<QgsMapLayer *> stylizedLayers( const QList<QgsWmsParametersLayer> &params );
157 
158  // Return a list of layers stylized with SLD parameter
159  QList<QgsMapLayer *> sldStylizedLayers( const QString &sld ) const;
160 
161  // Set layer opacity
162  void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
163 
164  // Set layer filter
165  void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
166 
167  // Set layer python filter
168  void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
169 
170  // Set layer selection
171  void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
172 
173  // Combine map extent with layer extent
174  void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
175 
176  // Scale image with WIDTH/HEIGHT if necessary
177  QImage *scaleImage( const QImage *image ) const;
178 
179  // Check layer read permissions
180  void checkLayerReadPermissions( QgsMapLayer *layer ) const;
181 
182  // Build a layer tree model for legend
183  QgsLayerTreeModel *buildLegendTreeModel( const QList<QgsMapLayer *> &layers, double scaleDenominator, QgsLayerTree &rootGroup );
184 
185  // Returns default dots per mm
186  qreal dotsPerMm() const;
187 
196  QImage *createImage( int width = -1, int height = -1, bool useBbox = true ) const;
197 
205  void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true ) const;
206 
207  QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
208  const QImage *outputImage, const QString &version ) const;
209 
225  bool featureInfoFromVectorLayer( QgsVectorLayer *layer,
226  const QgsPointXY *infoPoint,
227  int nFeatures,
228  QDomDocument &infoDocument,
229  QDomElement &layerElement,
230  const QgsMapSettings &mapSettings,
231  QgsRenderContext &renderContext,
232  const QString &version,
233  QgsRectangle *featureBBox = nullptr,
234  QgsGeometry *filterGeom = nullptr ) const;
235 
237  bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
238  const QgsMapSettings &mapSettings,
239  const QgsPointXY *infoPoint,
240  QDomDocument &infoDocument,
241  QDomElement &layerElement,
242  const QString &version ) const;
243 
245  void runHitTest( const QgsMapSettings &mapSettings, HitTest &hitTest ) const;
247  void runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols, QgsRenderContext &context ) const;
248 
252  bool testFilterStringSafety( const QString &filter ) const;
254  static void groupStringList( QStringList &list, const QString &groupString );
255 
259  bool checkMaximumWidthHeight() const;
260 
262  void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
263 
265  QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
266 
268  QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
269 
270  QDomElement createFeatureGML(
271  const QgsFeature *feat,
272  QgsVectorLayer *layer,
273  QDomDocument &doc,
275  const QgsMapSettings &mapSettings,
276  const QString &typeName,
277  bool withGeom,
278  int version,
279  QStringList *attributes = nullptr ) const;
280 
282  static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
284  QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
285 
287  bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings );
288 
290  QgsMapLayer *createExternalWMSLayer( const QString &externalLayerId ) const;
291 
292  void removeTemporaryLayers();
293 
294  private:
295 
301  int height() const;
302 
308  int width() const;
309 
310  QgsWmsParameters &mWmsParameters;
311 
312 #ifdef HAVE_SERVER_PYTHON_PLUGINS
313  QgsAccessControl *mAccessControl = nullptr;
315 #endif
316  QgsFeatureFilter mFeatureFilter;
317 
318  const QgsServerSettings &mSettings;
319  const QgsProject *mProject = nullptr;
320  QStringList mRestrictedLayers;
321  QMap<QString, QgsMapLayer *> mNicknameLayers;
322  QMap<QString, QList<QgsMapLayer *> > mLayerGroups;
323  QList<QgsMapLayer *> mTemporaryLayers;
324  QStringList flattenedQueryLayers() const;
325 
326  public:
327 
329  int getImageQuality() const;
330 
332  int getWMSPrecision() const;
333 
334  };
335 
336 } // namespace QgsWms
337 
338 #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:40
Base class for all map layer types.
Definition: qgsmaplayer.h:63
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
int getWMSPrecision() const
Returns the precision to use for GetFeatureInfo request.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QgsRenderer(QgsServerInterface *serverIface, const QgsProject *project, QgsWmsParameters &parameters)
Constructor.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
Provides a way to retrieve settings by prioritizing according to environment variables, ini file and default values.
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.
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
QImage * getMap(HitTest *hitTest=nullptr)
Returns the map as an image (or a null pointer in case of error).
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QHash< QgsVectorLayer *, SymbolSet > HitTest
QByteArray getPrint(const QString &formatString)
Returns printed page as binary.
QgsDxfExport getDxf(const QMap< QString, QString > &options)
Returns the map as DXF data.
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:32
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...
QImage * getLegendGraphics()
Returns the map legend as an image (or a null pointer in case of error).
Reads and writes project states.
Definition: qgsproject.h:89
Median cut implementation.
A cache for capabilities xml documents (by configuration file path)
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.
This class represents a coordinate reference system (CRS).
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.
int getImageQuality() const
Returns the image quality to use for getMap request.
Raster renderer pipe that applies colors to a raster.