QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgswcs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswcs.cpp
3  -------------------------
4  begin : January 16 , 2017
5  copyright : (C) 2013 by RenĂ©-Luc D'Hont ( parts from qgswcsserver )
6  (C) 2017 by David Marteau
7  email : rldhont at 3liz dot com
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 #include "qgsmodule.h"
21 #include "qgswcsutils.h"
22 #include "qgswcsgetcapabilities.h"
23 #include "qgswcsdescribecoverage.h"
24 #include "qgswcsgetcoverage.h"
25 
26 #define QSTR_COMPARE( str, lit )\
27  (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
28 
29 namespace QgsWcs
30 {
31 
38  class Service: public QgsService
39  {
40  public:
41 
46  Service( QgsServerInterface *serverIface )
47  : mServerIface( serverIface )
48  {}
49 
50  QString name() const override { return QStringLiteral( "WCS" ); }
51  QString version() const override { return implementationVersion(); }
52 
53  bool allowMethod( QgsServerRequest::Method method ) const override
54  {
55  return method == QgsServerRequest::GetMethod || method == QgsServerRequest::PostMethod;
56  }
57 
58  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
59  const QgsProject *project ) override
60  {
61  Q_UNUSED( project )
62 
63  QgsServerRequest::Parameters params = request.parameters();
64  QString versionString = params.value( "VERSION" );
65 
66  // Set the default version
67  if ( versionString.isEmpty() )
68  {
69  versionString = version();
70  }
71 
72  // Get the request
73  QString req = params.value( QStringLiteral( "REQUEST" ) );
74  if ( req.isEmpty() )
75  {
76  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
77  QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
78  }
79 
80  if ( QSTR_COMPARE( req, "GetCapabilities" ) )
81  {
82  writeGetCapabilities( mServerIface, project, versionString, request, response );
83  }
84  else if ( QSTR_COMPARE( req, "DescribeCoverage" ) )
85  {
86  writeDescribeCoverage( mServerIface, project, versionString, request, response );
87  }
88  else if ( QSTR_COMPARE( req, "GetCoverage" ) )
89  {
90  writeGetCoverage( mServerIface, project, versionString, request, response );
91  }
92  else
93  {
94  // Operation not supported
95  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
96  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
97  }
98  }
99 
100  private:
101  QgsServerInterface *mServerIface = nullptr;
102  };
103 
104 
105 } // namespace QgsWcs
106 
114 {
115  public:
116  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
117  {
118  QgsDebugMsg( QStringLiteral( "WCSModule::registerSelf called" ) );
119  registry.registerService( new QgsWcs::Service( serverIface ) );
120  }
121 };
122 
123 
124 // Entry points
126 {
127  static QgsWcsModule module;
128  return &module;
129 }
131 {
132  // Nothing to do
133 }
Service(QgsServerInterface *serverIface)
Constructor for WCS service.
Definition: qgswcs.cpp:46
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition: qgswcs.cpp:58
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswcs.cpp:116
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswcs.cpp:125
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
Class defining the service module interface for QGIS server services.
QString version() const override
Definition: qgswcs.cpp:51
OGC web service specialized for WCS.
Definition: qgswcs.cpp:38
void writeDescribeCoverage(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WCS DescribeCoverage response.
Method
HTTP Method (or equivalent) used for the request.
QString name() const override
Definition: qgswcs.cpp:50
#define QSTR_COMPARE(str, lit)
Definition: qgswcs.cpp:26
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswcs.cpp:130
bool allowMethod(QgsServerRequest::Method method) const override
Returns true if the given method is supported for that service.
Definition: qgswcs.cpp:53
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
Reads and writes project states.
Definition: qgsproject.h:89
void registerService(QgsService *service)
Register a service by its name and version.
Service module specialized for WCS.
Definition: qgswcs.cpp:113
QgsService Class defining interfaces for QGIS server services.
Definition: qgsservice.h:39
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QString implementationVersion()
Returns the highest version supported by this implementation.
Definition: qgswcsutils.cpp:30
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
void writeGetCoverage(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WCS DescribeCoverage response.
QgsServiceRegistry Class defining the registry manager for QGIS server services.
#define QGISEXTERN
Definition: qgis.h:643
Exception class for WFS services.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
WCS implementation.
Definition: qgswcs.cpp:29
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WCS GetCapabilities response.
QMap< QString, QString > Parameters