/
qgswcs.cpp
133 lines (114 loc) · 4.33 KB
/
qgswcs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/***************************************************************************
qgswcs.cpp
-------------------------
begin : January 16 , 2017
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
(C) 2017 by David Marteau
email : rldhont at 3liz dot com
david dot marteau at 3liz dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsmodule.h"
#include "qgswcsutils.h"
#include "qgswcsgetcapabilities.h"
#include "qgswcsdescribecoverage.h"
#include "qgswcsgetcoverage.h"
#define QSTR_COMPARE( str, lit )\
(str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
namespace QgsWcs
{
/**
* \ingroup server
* \class QgsWcs::Service
* \brief OGC web service specialized for WCS
* \since QGIS 3.0
*/
class Service: public QgsService
{
public:
/**
* Constructor for WCS service.
* \param serverIface Interface for plugins.
*/
Service( QgsServerInterface *serverIface )
: mServerIface( serverIface )
{}
QString name() const override { return QStringLiteral( "WCS" ); }
QString version() const override { return implementationVersion(); }
bool allowMethod( QgsServerRequest::Method method ) const override
{
return method == QgsServerRequest::GetMethod || method == QgsServerRequest::PostMethod;
}
void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
const QgsProject *project ) override
{
Q_UNUSED( project )
QgsServerRequest::Parameters params = request.parameters();
QString versionString = params.value( "VERSION" );
// Set the default version
if ( versionString.isEmpty() )
{
versionString = version();
}
// Get the request
QString req = params.value( QStringLiteral( "REQUEST" ) );
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
}
if ( QSTR_COMPARE( req, "GetCapabilities" ) )
{
writeGetCapabilities( mServerIface, project, versionString, request, response );
}
else if ( QSTR_COMPARE( req, "DescribeCoverage" ) )
{
writeDescribeCoverage( mServerIface, project, versionString, request, response );
}
else if ( QSTR_COMPARE( req, "GetCoverage" ) )
{
writeGetCoverage( mServerIface, project, versionString, request, response );
}
else
{
// Operation not supported
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
}
}
private:
QgsServerInterface *mServerIface = nullptr;
};
} // namespace QgsWcs
/**
* \ingroup server
* \class QgsWcsModule
* \brief Service module specialized for WCS
* \since QGIS 3.0
*/
class QgsWcsModule: public QgsServiceModule
{
public:
void registerSelf( QgsServiceRegistry ®istry, QgsServerInterface *serverIface ) override
{
QgsDebugMsg( QStringLiteral( "WCSModule::registerSelf called" ) );
registry.registerService( new QgsWcs::Service( serverIface ) );
}
};
// Entry points
QGISEXTERN QgsServiceModule *QGS_ServiceModule_Init()
{
static QgsWcsModule module;
return &module;
}
QGISEXTERN void QGS_ServiceModule_Exit( QgsServiceModule * )
{
// Nothing to do
}