QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgsmodule.h"
23#include "qgsdxfwriter.h"
24#include "qgspdfwriter.h"
27#include "qgswmsgetmap.h"
28#include "qgswmsgetstyles.h"
29#include "qgswmsgetcontext.h"
31#include "qgswmsgetprint.h"
33#include "qgswmsdescribelayer.h"
35#include "qgswmsparameters.h"
36#include "qgswmsrequest.h"
37#include "qgswmsutils.h"
38
39#define QSTR_COMPARE( str, lit )\
40 (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
41
42namespace QgsWms
43{
44
51 class Service: public QgsService
52 {
53 public:
54
60 Service( const QString &version, QgsServerInterface *serverIface )
61 : mVersion( version )
62 , mServerIface( serverIface )
63 {}
64
65 QString name() const override { return QStringLiteral( "WMS" ); }
66 QString version() const override { return mVersion; }
67
68 void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
69 const QgsProject *project ) override
70 {
71 // Get the request
72 const QgsWmsRequest wmsRequest( request );
73 const QString req = wmsRequest.wmsParameters().request();
74
75 if ( req.isEmpty() )
76 {
78 QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
79 }
80
81 if ( QSTR_COMPARE( req, "GetCapabilities" ) )
82 {
83 writeGetCapabilities( mServerIface, project, wmsRequest, response );
84 }
85 else if ( QSTR_COMPARE( req, "GetProjectSettings" ) )
86 {
87 writeGetCapabilities( mServerIface, project, request, response, true );
88 }
89 else if ( QSTR_COMPARE( req, "GetMap" ) )
90 {
91 if QSTR_COMPARE( wmsRequest.wmsParameters().formatAsString(), "application/dxf" )
92 {
93 writeAsDxf( mServerIface, project, request, response );
94 }
95 else if QSTR_COMPARE( wmsRequest.wmsParameters().formatAsString(), "application/pdf" )
96 {
97 writeAsPdf( mServerIface, project, request, response );
98 }
99 else
100 {
101 writeGetMap( mServerIface, project, request, response );
102 }
103 }
104 else if ( QSTR_COMPARE( req, "GetFeatureInfo" ) )
105 {
106 writeGetFeatureInfo( mServerIface, project, request, response );
107 }
108 else if ( QSTR_COMPARE( req, "GetContext" ) )
109 {
110 writeGetContext( mServerIface, project, request, response );
111 }
112 else if ( QSTR_COMPARE( req, "GetSchemaExtension" ) )
113 {
114 writeGetSchemaExtension( response );
115 }
116 else if ( QSTR_COMPARE( req, "GetStyle" ) || QSTR_COMPARE( req, "GetStyles" ) )
117 {
118 writeGetStyles( mServerIface, project, request, response );
119 }
120 else if ( QSTR_COMPARE( req, "DescribeLayer" ) )
121 {
122 writeDescribeLayer( mServerIface, project, request, response );
123 }
124 else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
125 {
126 writeGetLegendGraphics( mServerIface, project, request, response );
127 }
128 else if ( QSTR_COMPARE( req, "GetPrint" ) )
129 {
130 if ( mServerIface->serverSettings() && mServerIface->serverSettings()->getPrintDisabled() )
131 {
132 // GetPrint has been disabled
133 QgsDebugError( QStringLiteral( "WMS GetPrint request called, but it has been disabled." ) );
135 QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
136 }
137 writeGetPrint( mServerIface, project, request, response );
138 }
139 else
140 {
141 // Operation not supported
143 QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
144 }
145 }
146
147 private:
148 QString mVersion;
149 QgsServerInterface *mServerIface = nullptr;
150 };
151} // namespace QgsWms
152
160{
161 public:
162 void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
163 {
164 QgsDebugMsgLevel( QStringLiteral( "WMSModule::registerSelf called" ), 2 );
165 registry.registerService( new QgsWms::Service( QgsWms::implementationVersion(), serverIface ) ); // 1.3.0 default version
166 registry.registerService( new QgsWms::Service( QStringLiteral( "1.1.1" ), serverIface ) ); // second supported version
167 }
168};
169
170
171// Entry points
173{
174 static QgsWmsModule sModule;
175 return &sModule;
176}
178{
179 // Nothing to do
180}
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 QgsServerSettings * serverSettings()=0
Returns the server settings.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
bool getPrintDisabled() const
Returns true if WMS GetPrint request is disabled and the project's reading flag QgsProject::ReadFlag:...
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 WMS service.
Definition qgswms.cpp:160
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition qgswms.cpp:162
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.
Class defining request interface 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:52
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WMS service.
Definition qgswms.cpp:60
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition qgswms.cpp:68
QString version() const override
Definition qgswms.cpp:66
QString name() const override
Definition qgswms.cpp:65
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:6508
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38
#define QSTR_COMPARE(str, lit)
Definition qgswcs.cpp:26
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition qgswms.cpp:172
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition qgswms.cpp:177