QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
54  const QgsProject *project ) override
55  {
56  Q_UNUSED( project )
57 
58  const QgsServerRequest::Parameters params = request.parameters();
59  QString versionString = params.value( "VERSION" );
60 
61  // Set the default version
62  if ( versionString.isEmpty() )
63  {
64  versionString = version();
65  }
66 
67  // Get the request
68  const QString req = params.value( QStringLiteral( "REQUEST" ) );
69  if ( req.isEmpty() )
70  {
71  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
72  QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
73  }
74 
75  if ( QSTR_COMPARE( req, "GetCapabilities" ) )
76  {
77  writeGetCapabilities( mServerIface, project, versionString, request, response );
78  }
79  else if ( QSTR_COMPARE( req, "DescribeCoverage" ) )
80  {
81  writeDescribeCoverage( mServerIface, project, versionString, request, response );
82  }
83  else if ( QSTR_COMPARE( req, "GetCoverage" ) )
84  {
85  writeGetCoverage( mServerIface, project, versionString, request, response );
86  }
87  else
88  {
89  // Operation not supported
90  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
91  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
92  }
93  }
94 
95  private:
96  QgsServerInterface *mServerIface = nullptr;
97  };
98 
99 
100 } // namespace QgsWcs
101 
109 {
110  public:
111  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
112  {
113  QgsDebugMsg( QStringLiteral( "WCSModule::registerSelf called" ) );
114  registry.registerService( new QgsWcs::Service( serverIface ) );
115  }
116 };
117 
118 
119 // Entry points
121 {
122  static QgsWcsModule module;
123  return &module;
124 }
126 {
127  // Nothing to do
128 }
QgsServerRequest::parameters
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
Definition: qgsserverrequest.cpp:116
QgsServiceModule
Class defining the service module interface for QGIS server services.
Definition: qgsservicemodule.h:41
QGISEXTERN
#define QGISEXTERN
Definition: qgis.h:2834
qgswcsutils.h
QSTR_COMPARE
#define QSTR_COMPARE(str, lit)
Definition: qgswcs.cpp:26
QgsWcs::Service::executeRequest
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition: qgswcs.cpp:53
QGS_ServiceModule_Exit
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswcs.cpp:125
QgsWcs::Service
OGC web service specialized for WCS.
Definition: qgswcs.cpp:38
QGS_ServiceModule_Init
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswcs.cpp:120
QgsWcs::Service::name
QString name() const override
Definition: qgswcs.cpp:50
QgsWcs::Service::version
QString version() const override
Definition: qgswcs.cpp:51
QgsService
QgsService Class defining interfaces for QGIS server services.
Definition: qgsservice.h:39
QgsServiceRegistry::registerService
void registerService(QgsService *service)
Register a service by its name and version.
Definition: qgsserviceregistry.cpp:120
QgsServerRequest
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Definition: qgsserverrequest.h:38
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
qgswcsdescribecoverage.h
QgsWcs::writeDescribeCoverage
void writeDescribeCoverage(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WCS DescribeCoverage response.
Definition: qgswcsdescribecoverage.cpp:48
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsServerRequest::Parameters
QMap< QString, QString > Parameters
Definition: qgsserverrequest.h:59
QgsWcsModule::registerSelf
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswcs.cpp:111
QgsWcsModule
Service module specialized for WCS.
Definition: qgswcs.cpp:108
qgswcsgetcapabilities.h
QgsWcs::QgsServiceException
Exception class for WFS services.
Definition: qgswcsserviceexception.h:47
QgsWcs::implementationVersion
QString implementationVersion()
Returns the highest version supported by this implementation.
Definition: qgswcsutils.cpp:43
QgsWcs::writeGetCoverage
void writeGetCoverage(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WCS DescribeCoverage response.
Definition: qgswcsgetcoverage.cpp:55
QgsServiceRegistry
QgsServiceRegistry Class defining the registry manager for QGIS server services.
Definition: qgsserviceregistry.h:49
qgsmodule.h
QgsWcs::writeGetCapabilities
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WCS GetCapabilities response.
Definition: qgswcsgetcapabilities.cpp:47
QgsWcs::Service::Service
Service(QgsServerInterface *serverIface)
Constructor for WCS service.
Definition: qgswcs.cpp:46
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
qgswcsgetcoverage.h
QgsWcs
WCS implementation.
Definition: qgswcs.cpp:29
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:43