QGIS API Documentation  3.6.0-Noosa (5873452)
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 "qgswmsgetcapabilities.h"
25 #include "qgswmsgetmap.h"
26 #include "qgswmsgetstyles.h"
27 #include "qgswmsgetcontext.h"
29 #include "qgswmsgetprint.h"
30 #include "qgswmsgetfeatureinfo.h"
31 #include "qgswmsdescribelayer.h"
33 #include "qgswmsparameters.h"
34 
35 #define QSTR_COMPARE( str, lit )\
36  (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
37 
38 namespace QgsWms
39 {
40 
47  class Service: public QgsService
48  {
49  public:
50 
56  Service( const QString &version, QgsServerInterface *serverIface )
57  : mVersion( version )
58  , mServerIface( serverIface )
59  {}
60 
61  QString name() const override { return QStringLiteral( "WMS" ); }
62  QString version() const override { return mVersion; }
63 
64  bool allowMethod( QgsServerRequest::Method method ) const override
65  {
66  return method == QgsServerRequest::GetMethod;
67  }
68 
69  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
70  const QgsProject *project ) override
71  {
72  const QgsWmsParameters parameters( QUrlQuery( request.url() ) );
73 
74  QString version = parameters.version();
75  if ( version.isEmpty() )
76  {
77  // WMTVER needs to be supported by WMS 1.1.1 for backwards
78  // compatibility with WMS 1.0.0
79  version = parameters.wmtver();
80  }
81 
82  // Set the default version
83  if ( version.isEmpty() || !parameters.versionIsValid( version ) )
84  {
85  version = mVersion;
86  }
87 
88  // Get the request
89  const QString req = parameters.request();
90  if ( req.isEmpty() )
91  {
92  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
93  QStringLiteral( "Please check the value of the REQUEST parameter" ) );
94  }
95 
96  if ( ( mVersion.compare( QLatin1String( "1.1.1" ) ) == 0 \
97  && req.compare( QLatin1String( "capabilities" ) ) == 0 )
98  || req.compare( QLatin1String( "GetCapabilities" ) ) == 0 )
99  {
100  writeGetCapabilities( mServerIface, project, version, request, response, false );
101  }
102  else if ( QSTR_COMPARE( req, "GetProjectSettings" ) )
103  {
104  //getProjectSettings extends WMS 1.3.0 capabilities
105  version = QStringLiteral( "1.3.0" );
106  writeGetCapabilities( mServerIface, project, version, request, response, true );
107  }
108  else if ( QSTR_COMPARE( req, "GetMap" ) )
109  {
110  QString format = parameters.formatAsString();
111  if QSTR_COMPARE( format, "application/dxf" )
112  {
113  writeAsDxf( mServerIface, project, version, request, response );
114  }
115  else
116  {
117  writeGetMap( mServerIface, project, version, request, response );
118  }
119  }
120  else if ( QSTR_COMPARE( req, "GetFeatureInfo" ) )
121  {
122  writeGetFeatureInfo( mServerIface, project, version, request, response );
123  }
124  else if ( QSTR_COMPARE( req, "GetContext" ) )
125  {
126  writeGetContext( mServerIface, project, version, request, response );
127  }
128  else if ( QSTR_COMPARE( req, "GetSchemaExtension" ) )
129  {
130  writeGetSchemaExtension( mServerIface, version, request, response );
131  }
132  else if ( QSTR_COMPARE( req, "GetStyle" ) )
133  {
134  writeGetStyle( mServerIface, project, version, request, response );
135  }
136  else if ( QSTR_COMPARE( req, "GetStyles" ) )
137  {
138  writeGetStyles( mServerIface, project, version, request, response );
139  }
140  else if ( QSTR_COMPARE( req, "DescribeLayer" ) )
141  {
142  writeDescribeLayer( mServerIface, project, version, request, response );
143  }
144  else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
145  {
146  writeGetLegendGraphics( mServerIface, project, version, request, response );
147  }
148  else if ( QSTR_COMPARE( req, "GetPrint" ) )
149  {
150  writeGetPrint( mServerIface, project, version, request, response );
151  }
152  else
153  {
154  // Operation not supported
155  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
156  QString( "Request %1 is not supported" ).arg( req ) );
157  }
158  }
159 
160  private:
161  QString mVersion;
162  QgsServerInterface *mServerIface = nullptr;
163  };
164 } // namespace QgsWms
165 
173 {
174  public:
175  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
176  {
177  QgsDebugMsg( QStringLiteral( "WMSModule::registerSelf called" ) );
178  registry.registerService( new QgsWms::Service( "1.3.0", serverIface ) );
179  }
180 };
181 
182 
183 // Entry points
185 {
186  static QgsWmsModule sModule;
187  return &sModule;
188 }
190 {
191  // Nothing to do
192 }
bool versionIsValid(const QString version) const
Returns true if version is valid, false otherwise.
void writeGetStyles(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetStyles response.
QString request() const
Returns REQUEST parameter as a string or an empty string if not defined.
Module specialized for WMS service.
Definition: qgswms.cpp:172
void writeAsDxf(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Class defining the service module interface for QGIS server services.
QString version() const override
Definition: qgswms.cpp:62
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WMS service.
Definition: qgswms.cpp:56
void writeGetFeatureInfo(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetFeatureInfo response.
Method
HTTP Method (or equivalent) used for the request.
Exception class for WMS service exceptions.
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response, bool projectSettings)
Output GetCapabilities response.
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition: qgswms.cpp:69
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswms.cpp:189
Provides an interface to retrieve and manipulate WMS parameters received from the client...
#define QSTR_COMPARE(str, lit)
Definition: qgswms.cpp:35
void writeGetContext(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetContext response.
QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
OGC web service specialized for WMS.
Definition: qgswms.cpp:47
bool allowMethod(QgsServerRequest::Method method) const override
Returns true if the given method is supported for that service.
Definition: qgswms.cpp:64
Reads and writes project states.
Definition: qgsproject.h:89
void registerService(QgsService *service)
Register a service by its name and version.
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetPrint response.
void writeGetLegendGraphics(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetLegendGRaphics response.
void writeGetStyle(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetStyle response.
Median cut implementation.
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswms.cpp:175
QgsService Class defining interfaces for QGIS server services.
Definition: qgsservice.h:39
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
QgsServiceRegistry Class defining the registry manager for QGIS server services.
void writeGetSchemaExtension(QgsServerInterface *serverIface, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetSchemaExtension response.
#define QGISEXTERN
Definition: qgis.h:643
QString name() const override
Definition: qgswms.cpp:61
QString formatAsString() const
Returns FORMAT parameter as a string.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
QString wmtver() const
Returns WMTVER parameter or an empty string if not defined.
void writeDescribeLayer(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswms.cpp:184