QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgswms.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswms.cpp
3  -------------------------
4  begin : December 20 , 2016
5  copyright : (C) 2007 by Marco Hugentobler ( parts from qgswmshandler)
6  (C) 2014 by Alessandro Pasotti ( parts from qgswmshandler)
7  (C) 2016 by David Marteau
8  email : marco dot hugentobler at karto dot baug dot ethz dot ch
9  a dot pasotti at itopen dot it
10  david dot marteau at 3liz dot com
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #include "qgsmodule.h"
23 #include "qgsdxfwriter.h"
24 #include "qgswmsserviceexception.h"
25 #include "qgswmsgetcapabilities.h"
26 #include "qgswmsgetmap.h"
27 #include "qgswmsgetstyles.h"
28 #include "qgswmsgetcontext.h"
30 #include "qgswmsgetprint.h"
31 #include "qgswmsgetfeatureinfo.h"
32 #include "qgswmsdescribelayer.h"
34 #include "qgswmsparameters.h"
35 #include "qgswmsrequest.h"
36 
37 #define QSTR_COMPARE( str, lit )\
38  (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
39 
40 namespace QgsWms
41 {
42 
49  class Service: public QgsService
50  {
51  public:
52 
58  Service( const QString &version, QgsServerInterface *serverIface )
59  : mVersion( version )
60  , mServerIface( serverIface )
61  {}
62 
63  QString name() const override { return QStringLiteral( "WMS" ); }
64  QString version() const override { return mVersion; }
65 
66  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
67  const QgsProject *project ) override
68  {
69  // Get the request
70  const QgsWmsRequest wmsRequest( request );
71  const QString req = wmsRequest.wmsParameters().request();
72 
73  if ( req.isEmpty() )
74  {
76  QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
77  }
78 
79  if ( QSTR_COMPARE( req, "GetCapabilities" ) )
80  {
81  writeGetCapabilities( mServerIface, project, wmsRequest, response );
82  }
83  else if ( QSTR_COMPARE( req, "GetProjectSettings" ) )
84  {
85  writeGetCapabilities( mServerIface, project, request, response, true );
86  }
87  else if ( QSTR_COMPARE( req, "GetMap" ) )
88  {
89  if QSTR_COMPARE( wmsRequest.wmsParameters().formatAsString(), "application/dxf" )
90  {
91  writeAsDxf( mServerIface, project, request, response );
92  }
93  else
94  {
95  writeGetMap( mServerIface, project, request, response );
96  }
97  }
98  else if ( QSTR_COMPARE( req, "GetFeatureInfo" ) )
99  {
100  writeGetFeatureInfo( mServerIface, project, request, response );
101  }
102  else if ( QSTR_COMPARE( req, "GetContext" ) )
103  {
104  writeGetContext( mServerIface, project, request, response );
105  }
106  else if ( QSTR_COMPARE( req, "GetSchemaExtension" ) )
107  {
108  writeGetSchemaExtension( response );
109  }
110  else if ( QSTR_COMPARE( req, "GetStyle" ) || QSTR_COMPARE( req, "GetStyles" ) )
111  {
112  writeGetStyles( mServerIface, project, request, response );
113  }
114  else if ( QSTR_COMPARE( req, "DescribeLayer" ) )
115  {
116  writeDescribeLayer( mServerIface, project, request, response );
117  }
118  else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
119  {
120  writeGetLegendGraphics( mServerIface, project, request, response );
121  }
122  else if ( QSTR_COMPARE( req, "GetPrint" ) )
123  {
124  if ( mServerIface->serverSettings() && mServerIface->serverSettings()->getPrintDisabled() )
125  {
126  // GetPrint has been disabled
127  QgsDebugMsg( QStringLiteral( "WMS GetPrint request called, but it has been disabled." ) );
129  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
130  }
131  writeGetPrint( mServerIface, project, request, response );
132  }
133  else
134  {
135  // Operation not supported
137  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
138  }
139  }
140 
141  private:
142  QString mVersion;
143  QgsServerInterface *mServerIface = nullptr;
144  };
145 } // namespace QgsWms
146 
154 {
155  public:
156  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
157  {
158  QgsDebugMsg( QStringLiteral( "WMSModule::registerSelf called" ) );
159  registry.registerService( new QgsWms::Service( "1.3.0", serverIface ) );
160  }
161 };
162 
163 
164 // Entry points
166 {
167  static QgsWmsModule sModule;
168  return &sModule;
169 }
171 {
172  // Nothing to do
173 }
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
virtual QgsServerSettings * serverSettings()=0
Returns the server settings.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
bool getPrintDisabled() const
Returns true if WMS GetPrint request is disabled and the project's reading flag QgsProject::ReadFlag:...
Class defining the service module interface for QGIS server services.
QgsServiceRegistry Class defining the registry manager for QGIS server services.
void registerService(QgsService *service)
Register a service by its name and version.
QgsService Class defining interfaces for QGIS server services.
Definition: qgsservice.h:40
Module specialized for WMS service.
Definition: qgswms.cpp:154
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswms.cpp:156
Exception class for WMS service exceptions.
QString formatAsString() const
Returns FORMAT parameter as a string.
QString request() const override
Returns REQUEST parameter as a string or an empty string if not defined.
Class defining request interface passed to WMS service.
Definition: qgswmsrequest.h:35
const QgsWmsParameters & wmsParameters() const
Returns the parameters interpreted for the WMS service.
OGC web service specialized for WMS.
Definition: qgswms.cpp:50
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WMS service.
Definition: qgswms.cpp:58
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition: qgswms.cpp:66
QString version() const override
Definition: qgswms.cpp:64
QString name() const override
Definition: qgswms.cpp:63
Median cut implementation.
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response, bool projectSettings)
Output GetCapabilities response.
void writeDescribeLayer(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
void writeGetLegendGraphics(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetLegendGRaphics response.
void writeGetSchemaExtension(QgsServerResponse &response)
Output GetSchemaExtension response.
void writeAsDxf(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
void writeGetContext(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetContext response.
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetPrint response.
void writeGetStyles(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetStyles response.
void writeGetFeatureInfo(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetFeatureInfo response.
#define QGISEXTERN
Definition: qgis.h:2079
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
#define QSTR_COMPARE(str, lit)
Definition: qgswms.cpp:37
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswms.cpp:170
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswms.cpp:165