QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgswfs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswfs.cpp
3  -------------------------
4  begin : December 20 , 2016
5  copyright : (C) 2007 by Marco Hugentobler ( parts from qgswmshandler)
6  (C) 2012 by RenĂ©-Luc D'Hont ( parts from qgswmshandler)
7  (C) 2014 by Alessandro Pasotti ( parts from qgswmshandler)
8  (C) 2016 by David Marteau
9  email : marco dot hugentobler at karto dot baug dot ethz dot ch
10  a dot pasotti at itopen dot it
11  david dot marteau at 3liz dot com
12  ***************************************************************************/
13 
14 /***************************************************************************
15  * *
16  * This program is free software; you can redistribute it and/or modify *
17  * it under the terms of the GNU General Public License as published by *
18  * the Free Software Foundation; either version 2 of the License, or *
19  * (at your option) any later version. *
20  * *
21  ***************************************************************************/
22 
23 #include "qgsmodule.h"
24 #include "qgswfsutils.h"
25 #include "qgswfsgetcapabilities.h"
27 #include "qgswfsgetfeature.h"
29 #include "qgswfstransaction.h"
31 
32 #define QSTR_COMPARE( str, lit )\
33  (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
34 
35 namespace QgsWfs
36 {
37 
44  class Service: public QgsService
45  {
46  public:
47 
53  Service( const QString &version, QgsServerInterface *serverIface )
54  : mVersion( version )
55  , mServerIface( serverIface )
56  {}
57 
58  QString name() const override { return QStringLiteral( "WFS" ); }
59  QString version() const override { return mVersion; }
60 
61  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
62  const QgsProject *project ) override
63  {
64  const QgsWfsParameters params( QUrlQuery( request.url() ) );
65 
66  // Set the default version
67  QString versionString = params.version();
68  if ( versionString.isEmpty() )
69  {
70  versionString = version(); // defined in qgswfsutils.h
71  }
72 
73  // Get the request
74  const QString req = params.request();
75  if ( req.isEmpty() )
76  {
77  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
78  QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
79  }
80 
81  if ( QSTR_COMPARE( req, "GetCapabilities" ) )
82  {
83  // Supports WFS 1.0.0
84  if ( QSTR_COMPARE( versionString, "1.0.0" ) )
85  {
86  v1_0_0::writeGetCapabilities( mServerIface, project, versionString, request, response );
87  }
88  else
89  {
90  writeGetCapabilities( mServerIface, project, versionString, request, response );
91  }
92  }
93  else if ( QSTR_COMPARE( req, "GetFeature" ) )
94  {
95  writeGetFeature( mServerIface, project, versionString, request, response );
96  }
97  else if ( QSTR_COMPARE( req, "DescribeFeatureType" ) )
98  {
99  writeDescribeFeatureType( mServerIface, project, versionString, request, response );
100  }
101  else if ( QSTR_COMPARE( req, "Transaction" ) )
102  {
103  // Supports WFS 1.0.0
104  if ( QSTR_COMPARE( versionString, "1.0.0" ) )
105  {
106  v1_0_0::writeTransaction( mServerIface, project, versionString, request, response );
107  }
108  else
109  {
110  writeTransaction( mServerIface, project, versionString, request, response );
111  }
112  }
113  else
114  {
115  // Operation not supported
116  throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
117  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
118  }
119  }
120 
121  private:
122  QString mVersion;
123  QgsServerInterface *mServerIface = nullptr;
124  };
125 
126 
127 } // namespace QgsWfs
128 
136 {
137  public:
138  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
139  {
140  QgsDebugMsg( QStringLiteral( "WFSModule::registerSelf called" ) );
141  registry.registerService( new QgsWfs::Service( QgsWfs::implementationVersion(), serverIface ) ); // 1.1.0 default version
142  registry.registerService( new QgsWfs::Service( QStringLiteral( "1.0.0" ), serverIface ) ); // second version
143  }
144 };
145 
146 
147 // Entry points
149 {
150  static QgsWfsModule module;
151  return &module;
152 }
154 {
155  // Nothing to do
156 }
QgsServiceModule
Class defining the service module interface for QGIS server services.
Definition: qgsservicemodule.h:41
qgswfsutils.h
QgsWfs::writeDescribeFeatureType
void writeDescribeFeatureType(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
Definition: qgswfsdescribefeaturetype.cpp:52
QGISEXTERN
#define QGISEXTERN
Definition: qgis.h:2834
QgsWfs::Service::version
QString version() const override
Definition: qgswfs.cpp:59
QGS_ServiceModule_Init
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswfs.cpp:148
QgsWfs::Service::name
QString name() const override
Definition: qgswfs.cpp:58
qgswfsgetfeature.h
QgsServerParameters::request
virtual QString request() const
Returns REQUEST parameter as a string or an empty string if not defined.
Definition: qgsserverparameters.cpp:625
QgsWfsModule
Module specialized for WFS service.
Definition: qgswfs.cpp:135
qgswfsgetcapabilities.h
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
QSTR_COMPARE
#define QSTR_COMPARE(str, lit)
Definition: qgswfs.cpp:32
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QGS_ServiceModule_Exit
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswfs.cpp:153
QgsServerParameters::version
virtual QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
Definition: qgsserverparameters.cpp:575
QgsWfs::writeTransaction
void writeTransaction(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS transaction response.
Definition: qgswfstransaction.cpp:71
qgswfstransaction.h
QgsWfs::QgsServiceException
Exception class for WFS service exceptions.
Definition: qgswfsserviceexception.h:47
QgsWfs::QgsWfsParameters
Provides an interface to retrieve and manipulate WFS parameters received from the client.
Definition: qgswfsparameters.h:138
QgsWfs
WMS implementation.
Definition: qgswfs.cpp:35
QgsWfs::v1_0_0::writeGetCapabilities
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
Definition: qgswfsgetcapabilities_1_0_0.cpp:75
QgsWfsModule::registerSelf
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswfs.cpp:138
QgsWfs::Service::Service
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WFS service.
Definition: qgswfs.cpp:53
QgsWfs::writeGetCapabilities
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
Definition: qgswfsgetcapabilities.cpp:57
QgsWfs::Service::executeRequest
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition: qgswfs.cpp:61
QgsWfs::implementationVersion
QString implementationVersion()
Returns the highest version supported by this implementation.
Definition: qgswfsutils.cpp:50
qgswfstransaction_1_0_0.h
QgsServiceRegistry
QgsServiceRegistry Class defining the registry manager for QGIS server services.
Definition: qgsserviceregistry.h:49
QgsWfs::v1_0_0::writeTransaction
void writeTransaction(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS transaction response.
Definition: qgswfstransaction_1_0_0.cpp:87
QgsServerRequest::url
QUrl url() const
Definition: qgsserverrequest.cpp:86
qgswfsdescribefeaturetype.h
qgsmodule.h
QgsWfs::writeGetFeature
void writeGetFeature(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetFeature response.
Definition: qgswfsgetfeature.cpp:116
QgsWfs::Service
OGC web service specialized for WFS.
Definition: qgswfs.cpp:44
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
qgswfsgetcapabilities_1_0_0.h
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:43