QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 ) ( str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0 )
37
38namespace QgsWfs
39{
40
47 class Service : public QgsService
48 {
49 public:
55 Service( const QString &version, QgsServerInterface *serverIface )
56 : mVersion( version )
57 , mServerIface( serverIface )
58 {}
59
60 QString name() const override { return u"WFS"_s; }
61 QString version() const override { return mVersion; }
62
63 void executeRequest( const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project ) override
64 {
65 const QgsWfsParameters params( QUrlQuery( request.url() ) );
66
67 // Set the default version
68 QString versionString = params.version();
69 if ( versionString.isEmpty() )
70 {
71 versionString = version(); // defined in qgswfsutils.h
72 }
73
74 // Get the request
75 const QString req = params.request();
76 if ( req.isEmpty() )
77 {
78 throw QgsServiceException( u"OperationNotSupported"_s, u"Please add or check the value of the REQUEST parameter"_s, 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( u"OperationNotSupported"_s, u"Request %1 is not supported"_s.arg( req ), 501 );
117 }
118 }
119
120 private:
121 QString mVersion;
122 QgsServerInterface *mServerIface = nullptr;
123 };
124
125
126} // namespace QgsWfs
127
135{
136 public:
137 void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
138 {
139 QgsDebugMsgLevel( u"WFSModule::registerSelf called"_s, 2 );
140 registry.registerService( new QgsWfs::Service( QgsWfs::implementationVersion(), serverIface ) ); // 1.1.0 default version
141 registry.registerService( new QgsWfs::Service( u"1.0.0"_s, serverIface ) ); // second version
142 }
143};
144
145
146// Entry points
148{
149 static QgsWfsModule module;
150 return &module;
151}
153{
154 // Nothing to do
155}
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:113
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:135
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition qgswfs.cpp:137
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:48
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Executes the requests and sets result in QgsServerRequest.
Definition qgswfs.cpp:63
QString name() const override
Returns the name of the service.
Definition qgswfs.cpp:60
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WFS service.
Definition qgswfs.cpp:55
QString version() const override
Returns the version of the service.
Definition qgswfs.cpp:61
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:39
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:7518
#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:147
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition qgswfs.cpp:152