QGIS API Documentation 3.99.0-Master (d270888f95f)
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"
27#include "qgswfsgetfeature.h"
28#include "qgswfstransaction.h"
30#include "qgswfsutils.h"
31
32#include <QString>
33
34using namespace Qt::StringLiterals;
35
36#define QSTR_COMPARE( str, lit ) \
37 ( str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0 )
38
39namespace QgsWfs
40{
41
48 class Service : public QgsService
49 {
50 public:
56 Service( const QString &version, QgsServerInterface *serverIface )
57 : mVersion( version )
58 , mServerIface( serverIface )
59 {}
60
61 QString name() const override { return u"WFS"_s; }
62 QString version() const override { return mVersion; }
63
64 void executeRequest( const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project ) override
65 {
66 const QgsWfsParameters params( QUrlQuery( request.url() ) );
67
68 // Set the default version
69 QString versionString = params.version();
70 if ( versionString.isEmpty() )
71 {
72 versionString = version(); // defined in qgswfsutils.h
73 }
74
75 // Get the request
76 const QString req = params.request();
77 if ( req.isEmpty() )
78 {
79 throw QgsServiceException( u"OperationNotSupported"_s, u"Please add or check the value of the REQUEST parameter"_s, 501 );
80 }
81
82 if ( QSTR_COMPARE( req, "GetCapabilities" ) )
83 {
84 // Supports WFS 1.0.0
85 if ( QSTR_COMPARE( versionString, "1.0.0" ) )
86 {
87 v1_0_0::writeGetCapabilities( mServerIface, project, versionString, request, response );
88 }
89 else
90 {
91 writeGetCapabilities( mServerIface, project, versionString, request, response );
92 }
93 }
94 else if ( QSTR_COMPARE( req, "GetFeature" ) )
95 {
96 writeGetFeature( mServerIface, project, versionString, request, response );
97 }
98 else if ( QSTR_COMPARE( req, "DescribeFeatureType" ) )
99 {
100 writeDescribeFeatureType( mServerIface, project, versionString, request, response );
101 }
102 else if ( QSTR_COMPARE( req, "Transaction" ) )
103 {
104 // Supports WFS 1.0.0
105 if ( QSTR_COMPARE( versionString, "1.0.0" ) )
106 {
107 v1_0_0::writeTransaction( mServerIface, project, versionString, request, response );
108 }
109 else
110 {
111 writeTransaction( mServerIface, project, versionString, request, response );
112 }
113 }
114 else
115 {
116 // Operation not supported
117 throw QgsServiceException( u"OperationNotSupported"_s, u"Request %1 is not supported"_s.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 QgsDebugMsgLevel( u"WFSModule::registerSelf called"_s, 2 );
141 registry.registerService( new QgsWfs::Service( QgsWfs::implementationVersion(), serverIface ) ); // 1.1.0 default version
142 registry.registerService( new QgsWfs::Service( u"1.0.0"_s, 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}
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:112
Defines 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.
Defines requests passed to QgsService classes.
QUrl url() const
Returns the request URL as seen by QGIS server.
Defines the response interface passed to QgsService.
Defines the service module interface for QGIS server services.
QgsServiceModule()=default
A registry manager for QGIS server services.
void registerService(QgsService *service)
Register a service by its name and version.
QgsService()
Constructor.
Module specialized for WFS service.
Definition qgswfs.cpp:136
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition qgswfs.cpp:138
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:49
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Executes the requests and sets result in QgsServerRequest.
Definition qgswfs.cpp:64
QString name() const override
Returns the name of the service.
Definition qgswfs.cpp:61
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WFS service.
Definition qgswfs.cpp:56
QString version() const override
Returns the version of the service.
Definition qgswfs.cpp:62
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:40
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:7465
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63
#define QSTR_COMPARE(str, lit)
Definition qgswcs.cpp:30
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition qgswfs.cpp:148
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition qgswfs.cpp:153