QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgswms.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswms.cpp
3 -------------------------
4 begin : December 20 , 2016
5 copyright : (C) 2007 by Marco Hugentobler ( parts from qgswmshandler)
6 (C) 2014 by Alessandro Pasotti ( parts from qgswmshandler)
7 (C) 2016 by David Marteau
8 email : marco dot hugentobler at karto dot baug dot ethz dot ch
9 a dot pasotti at itopen dot it
10 david dot marteau at 3liz dot com
11 ***************************************************************************/
12
13/***************************************************************************
14 * *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
19 * *
20 ***************************************************************************/
21
22#include "qgsdxfwriter.h"
23#include "qgsmodule.h"
24#include "qgspdfwriter.h"
25#include "qgswmsdescribelayer.h"
27#include "qgswmsgetcontext.h"
30#include "qgswmsgetmap.h"
31#include "qgswmsgetprint.h"
33#include "qgswmsgetstyles.h"
34#include "qgswmsparameters.h"
35#include "qgswmsrequest.h"
37#include "qgswmsutils.h"
38
39#include <QString>
40
41using namespace Qt::StringLiterals;
42
43#define QSTR_COMPARE( str, lit ) \
44 ( str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0 )
45
46namespace QgsWms
47{
48
55 class Service : public QgsService
56 {
57 public:
63 Service( const QString &version, QgsServerInterface *serverIface )
64 : mVersion( version )
65 , mServerIface( serverIface )
66 {}
67
68 QString name() const override { return u"WMS"_s; }
69 QString version() const override { return mVersion; }
70
71 void executeRequest( const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project ) override
72 {
73 // Get the request
74 const QgsWmsRequest wmsRequest( request );
75 const QString req = wmsRequest.wmsParameters().request();
76
77 if ( req.isEmpty() )
78 {
79 throw QgsServiceException( QgsServiceException::OGC_OperationNotSupported, u"Please add or check the value of the REQUEST parameter"_s, 501 );
80 }
81
82 if ( QSTR_COMPARE( req, "GetCapabilities" ) )
83 {
84 writeGetCapabilities( mServerIface, project, wmsRequest, response );
85 }
86 else if ( QSTR_COMPARE( req, "GetProjectSettings" ) )
87 {
88 writeGetCapabilities( mServerIface, project, request, response, true );
89 }
90 else if ( QSTR_COMPARE( req, "GetMap" ) )
91 {
92 if QSTR_COMPARE ( wmsRequest.wmsParameters().formatAsString(), "application/dxf" )
93 {
94 writeAsDxf( mServerIface, project, request, response );
95 }
96 else if QSTR_COMPARE ( wmsRequest.wmsParameters().formatAsString(), "application/pdf" )
97 {
98 writeAsPdf( mServerIface, project, request, response );
99 }
100 else
101 {
102 writeGetMap( mServerIface, project, request, response );
103 }
104 }
105 else if ( QSTR_COMPARE( req, "GetFeatureInfo" ) )
106 {
107 writeGetFeatureInfo( mServerIface, project, request, response );
108 }
109 else if ( QSTR_COMPARE( req, "GetContext" ) )
110 {
111 writeGetContext( mServerIface, project, request, response );
112 }
113 else if ( QSTR_COMPARE( req, "GetSchemaExtension" ) )
114 {
115 writeGetSchemaExtension( response );
116 }
117 else if ( QSTR_COMPARE( req, "GetStyle" ) || QSTR_COMPARE( req, "GetStyles" ) )
118 {
119 writeGetStyles( mServerIface, project, request, response );
120 }
121 else if ( QSTR_COMPARE( req, "DescribeLayer" ) )
122 {
123 writeDescribeLayer( mServerIface, project, request, response );
124 }
125 else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
126 {
127 writeGetLegendGraphics( mServerIface, project, request, response );
128 }
129 else if ( QSTR_COMPARE( req, "GetPrint" ) )
130 {
131 if ( mServerIface->serverSettings() && mServerIface->serverSettings()->getPrintDisabled() )
132 {
133 // GetPrint has been disabled
134 QgsDebugError( u"WMS GetPrint request called, but it has been disabled."_s );
135 throw QgsServiceException( QgsServiceException::OGC_OperationNotSupported, u"Request %1 is not supported"_s.arg( req ), 501 );
136 }
137 writeGetPrint( mServerIface, project, request, response );
138 }
139 else
140 {
141 // Operation not supported
142 throw QgsServiceException( QgsServiceException::OGC_OperationNotSupported, u"Request %1 is not supported"_s.arg( req ), 501 );
143 }
144 }
145
146 private:
147 QString mVersion;
148 QgsServerInterface *mServerIface = nullptr;
149 };
150} // namespace QgsWms
151
159{
160 public:
161 void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
162 {
163 QgsDebugMsgLevel( u"WMSModule::registerSelf called"_s, 2 );
164 registry.registerService( new QgsWms::Service( QgsWms::implementationVersion(), serverIface ) ); // 1.3.0 default version
165 registry.registerService( new QgsWms::Service( u"1.1.1"_s, serverIface ) ); // second supported version
166 }
167};
168
169
170// Entry points
172{
173 static QgsWmsModule sModule;
174 return &sModule;
175}
177{
178 // Nothing to do
179}
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.
Defines requests passed to QgsService classes.
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 WMS service.
Definition qgswms.cpp:159
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition qgswms.cpp:161
Exception class for WMS service exceptions.
QString formatAsString() const
Returns FORMAT parameter as a string.
QString request() const override
Returns REQUEST parameter as a string or an empty string if not defined.
Defines request interfaces passed to WMS service.
const QgsWmsParameters & wmsParameters() const
Returns the parameters interpreted for the WMS service.
OGC web service specialized for WMS.
Definition qgswms.cpp:56
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WMS service.
Definition qgswms.cpp:63
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Executes the requests and sets result in QgsServerRequest.
Definition qgswms.cpp:71
QString version() const override
Returns the version of the service.
Definition qgswms.cpp:69
QString name() const override
Returns the name of the service.
Definition qgswms.cpp:68
Median cut implementation.
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response, bool projectSettings)
Output GetCapabilities response.
void writeAsPdf(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in PDF format.
void writeDescribeLayer(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
void writeGetLegendGraphics(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetLegendGRaphics response.
void writeGetSchemaExtension(QgsServerResponse &response)
Output GetSchemaExtension response.
void writeAsDxf(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
QString implementationVersion()
Returns the highest version supported by this implementation.
void writeGetContext(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetContext response.
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetPrint response.
void writeGetStyles(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetStyles response.
void writeGetFeatureInfo(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetFeatureInfo response.
#define QGISEXTERN
Definition qgis.h:7465
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63
#define QgsDebugError(str)
Definition qgslogger.h:59
#define QSTR_COMPARE(str, lit)
Definition qgswcs.cpp:30
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition qgswms.cpp:171
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition qgswms.cpp:176