QGIS API Documentation  3.6.0-Noosa (5873452)
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 <QString>
29 
31 class QgsPrintLayout;
32 class QgsFeature;
33 class QgsLayout;
34 class QgsMapLayer;
35 class QgsMapSettings;
36 class QgsPointXY;
37 class QgsRasterLayer;
38 class QgsRectangle;
39 class QgsRenderContext;
40 class QgsVectorLayer;
41 class QgsAccessControl;
42 class QgsDxfExport;
43 class QgsLayerTreeModel;
44 class QgsLayerTree;
45 
46 class QImage;
47 class QPaintDevice;
48 class QPainter;
49 class QgsLayerTreeGroup;
50 
51 namespace QgsWms
52 {
53 
61  {
62  public:
63 
67  QgsRenderer( QgsServerInterface *serverIface,
68  const QgsProject *project,
69  const QgsWmsParameters &parameters );
70 
71  ~QgsRenderer();
72 
76  QImage *getLegendGraphics();
77 
78  typedef QSet<QString> SymbolSet;
79  typedef QHash<QgsVectorLayer *, SymbolSet> HitTest;
80 
85  QImage *getMap( HitTest *hitTest = nullptr );
86 
90  QImage *getMap( QgsMapSettings &mapSettings, HitTest *hitTest = nullptr );
91 
97  QgsDxfExport getDxf( const QMap<QString, QString> &options );
98 
103  QByteArray getPrint( const QString &formatString );
104 
109  QByteArray getFeatureInfo( const QString &version = "1.3.0" );
110 
111  private:
112 
113  // Init the restricted layers with nicknames
114  void initRestrictedLayers();
115 
116  // Build and returns highlight layers
117  QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );
118 
119  // Init a map with nickname for layers' project
120  void initNicknameLayers();
121 
122  void initLayerGroupsRecursive( const QgsLayerTreeGroup *group, const QString &groupName );
123 
124  // Return the nickname of the layer (short name, id or name according to
125  // the project configuration)
126  QString layerNickname( const QgsMapLayer &layer ) const;
127 
128  // Return true if the layer has to be displayed according to he current
129  // scale
130  bool layerScaleVisibility( const QgsMapLayer &layer, double scaleDenominator ) const;
131 
132  // Remove unwanted layers (restricted, not visible, etc)
133  void removeUnwantedLayers( QList<QgsMapLayer *> &layers, double scaleDenominator = -1 ) const;
134 
135  // Remove non identifiable layers (restricted, not visible, etc)
136  void removeNonIdentifiableLayers( QList<QgsMapLayer *> &layers ) const;
137 
138  // Rendering step for layers
139  QPainter *layersRendering( const QgsMapSettings &mapSettings, QImage &image, HitTest *hitTest = nullptr ) const;
140 
141  // Rendering step for annotations
142  void annotationsRendering( QPainter *painter ) const;
143 
144  // Return a list of layers stylized with LAYERS/STYLES parameters
145  QList<QgsMapLayer *> stylizedLayers( const QList<QgsWmsParametersLayer> &params );
146 
147  // Return a list of layers stylized with SLD parameter
148  QList<QgsMapLayer *> sldStylizedLayers( const QString &sld ) const;
149 
150  // Set layer opacity
151  void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;
152 
153  // Set layer filter
154  void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );
155 
156  // Set layer python filter
157  void setLayerAccessControlFilter( QgsMapLayer *layer ) const;
158 
159  // Set layer selection
160  void setLayerSelection( QgsMapLayer *layer, const QStringList &fids ) const;
161 
162  // Combine map extent with layer extent
163  void updateExtent( const QgsMapLayer *layer, QgsMapSettings &mapSettings ) const;
164 
165  // Scale image with WIDTH/HEIGHT if necessary
166  QImage *scaleImage( const QImage *image ) const;
167 
168  // Check layer read permissions
169  void checkLayerReadPermissions( QgsMapLayer *layer ) const;
170 
171  // Build a layer tree model for legend
172  QgsLayerTreeModel *buildLegendTreeModel( const QList<QgsMapLayer *> &layers, double scaleDenominator, QgsLayerTree &rootGroup );
173 
174  // Returns default dots per mm
175  qreal dotsPerMm() const;
176 
185  QImage *createImage( int width = -1, int height = -1, bool useBbox = true ) const;
186 
193  void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings ) 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 
240  bool testFilterStringSafety( const QString &filter ) const;
242  static void groupStringList( QStringList &list, const QString &groupString );
243 
247  bool checkMaximumWidthHeight() const;
248 
250  void convertFeatureInfoToSia2045( QDomDocument &doc ) const;
251 
253  QByteArray convertFeatureInfoToHtml( const QDomDocument &doc ) const;
254 
256  QByteArray convertFeatureInfoToText( const QDomDocument &doc ) const;
257 
259  QByteArray convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const;
260 
261  QDomElement createFeatureGML(
262  QgsFeature *feat,
263  QgsVectorLayer *layer,
264  QDomDocument &doc,
266  const QgsMapSettings &mapSettings,
267  const QString &typeName,
268  bool withGeom,
269  int version,
270  QStringList *attributes = nullptr ) const;
271 
273  static QString replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QVariant &attributeVal );
275  QgsRectangle featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &ms, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const;
276 
277  /*
278  * Configures the print layout for the GetPrint request
279  *\param c the print layout
280  *\param mapSettings the map settings
281  *\param atlasPrint true if atlas is used for printing
282  *\returns true in case of success
283  * */
284  bool configurePrintLayout( QgsPrintLayout *c, const QgsMapSettings &mapSettings, bool atlasPrint = false );
285 
287  QgsMapLayer *createExternalWMSLayer( const QString &externalLayerId ) const;
288 
289  void removeTemporaryLayers();
290 
291  void handlePrintErrors( const QgsLayout *layout ) const;
292 
293  private:
294 
295  const QgsWmsParameters &mWmsParameters;
296 
297 #ifdef HAVE_SERVER_PYTHON_PLUGINS
298  QgsAccessControl *mAccessControl = nullptr;
300 #endif
301  QgsFeatureFilter mFeatureFilter;
302 
303  const QgsServerSettings &mSettings;
304  const QgsProject *mProject = nullptr;
305  QStringList mRestrictedLayers;
306  QMap<QString, QgsMapLayer *> mNicknameLayers;
307  QMap<QString, QList<QgsMapLayer *> > mLayerGroups;
308  QList<QgsMapLayer *> mTemporaryLayers;
309 
310  public:
311 
313  int getImageQuality() const;
314 
316  int getWMSPrecision() const;
317 
318  };
319 
320 } // namespace QgsWms
321 
322 #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:64
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
int getImageQuality() const
Returns the image quality to use for getMap request.
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.
int getWMSPrecision() const
Returns the precision to use for GetFeatureInfo request.
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
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
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.
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.
QgsRenderer(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsParameters &parameters)
Constructor.
Represents a vector layer which manages a vector based data sets.