QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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"
27#include "qgswfsgetfeature.h"
29#include "qgswfstransaction.h"
31
32#define QSTR_COMPARE( str, lit ) \
33 ( str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0 )
34
35namespace QgsWfs
36{
37
44 class Service : public QgsService
45 {
46 public:
52 Service( const QString &version, QgsServerInterface *serverIface )
53 : mVersion( version )
54 , mServerIface( serverIface )
55 {}
56
57 QString name() const override { return QStringLiteral( "WFS" ); }
58 QString version() const override { return mVersion; }
59
60 void executeRequest( const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project ) override
61 {
62 const QgsWfsParameters params( QUrlQuery( request.url() ) );
63
64 // Set the default version
65 QString versionString = params.version();
66 if ( versionString.isEmpty() )
67 {
68 versionString = version(); // defined in qgswfsutils.h
69 }
70
71 // Get the request
72 const QString req = params.request();
73 if ( req.isEmpty() )
74 {
75 throw QgsServiceException( QStringLiteral( "OperationNotSupported" ), QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
76 }
77
78 if ( QSTR_COMPARE( req, "GetCapabilities" ) )
79 {
80 // Supports WFS 1.0.0
81 if ( QSTR_COMPARE( versionString, "1.0.0" ) )
82 {
83 v1_0_0::writeGetCapabilities( mServerIface, project, versionString, request, response );
84 }
85 else
86 {
87 writeGetCapabilities( mServerIface, project, versionString, request, response );
88 }
89 }
90 else if ( QSTR_COMPARE( req, "GetFeature" ) )
91 {
92 writeGetFeature( mServerIface, project, versionString, request, response );
93 }
94 else if ( QSTR_COMPARE( req, "DescribeFeatureType" ) )
95 {
96 writeDescribeFeatureType( mServerIface, project, versionString, request, response );
97 }
98 else if ( QSTR_COMPARE( req, "Transaction" ) )
99 {
100 // Supports WFS 1.0.0
101 if ( QSTR_COMPARE( versionString, "1.0.0" ) )
102 {
103 v1_0_0::writeTransaction( mServerIface, project, versionString, request, response );
104 }
105 else
106 {
107 writeTransaction( mServerIface, project, versionString, request, response );
108 }
109 }
110 else
111 {
112 // Operation not supported
113 throw QgsServiceException( QStringLiteral( "OperationNotSupported" ), QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
114 }
115 }
116
117 private:
118 QString mVersion;
119 QgsServerInterface *mServerIface = nullptr;
120 };
121
122
123} // namespace QgsWfs
124
132{
133 public:
134 void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
135 {
136 QgsDebugMsgLevel( QStringLiteral( "WFSModule::registerSelf called" ), 2 );
137 registry.registerService( new QgsWfs::Service( QgsWfs::implementationVersion(), serverIface ) ); // 1.1.0 default version
138 registry.registerService( new QgsWfs::Service( QStringLiteral( "1.0.0" ), serverIface ) ); // second version
139 }
140};
141
142
143// Entry points
145{
146 static QgsWfsModule module;
147 return &module;
148}
150{
151 // Nothing to do
152}
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
virtual QString request() const
Returns REQUEST parameter as a string or an empty string if not defined.
virtual QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
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:39
Module specialized for WFS service.
Definition qgswfs.cpp:132
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition qgswfs.cpp:134
Exception class for WFS service exceptions.
Provides an interface to retrieve and manipulate WFS parameters received from the client.
OGC web service specialized for WFS.
Definition qgswfs.cpp:45
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition qgswfs.cpp:60
QString name() const override
Definition qgswfs.cpp:57
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WFS service.
Definition qgswfs.cpp:52
QString version() const override
Definition qgswfs.cpp:58
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
void writeTransaction(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS transaction response.
WMS implementation.
Definition qgswfs.cpp:36
QString implementationVersion()
Returns the highest version supported by this implementation.
void writeDescribeFeatureType(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
void writeTransaction(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS transaction response.
void writeGetFeature(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetFeature response.
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output WFS GetCapabilities response.
#define QGISEXTERN
Definition qgis.h:6657
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QSTR_COMPARE(str, lit)
Definition qgswcs.cpp:26
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition qgswfs.cpp:144
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition qgswfs.cpp:149