QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgswmsgetmap.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswmsgetmap.cpp
3 -------------------------
4 begin : December 20 , 2016
5 copyright : (C) 2007 by Marco Hugentobler (original code)
6 (C) 2014 by Alessandro Pasotti (original code)
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#include "qgswmsgetmap.h"
22
23#include "qgswmsrenderer.h"
25#include "qgswmsutils.h"
26
27#include <QImage>
28
29namespace QgsWms
30{
31
32 void writeGetMap( QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response )
33 {
34 if ( request.serverParameters().version().isEmpty() )
35 {
36 throw QgsServiceException( QgsServiceException::OGC_OperationNotSupported, QStringLiteral( "Please add the value of the VERSION parameter" ), 501 );
37 }
38
39 // prepare render context
40 QgsWmsRenderContext context( project, serverIface );
49 context.setParameters( request.wmsParameters() );
50 context.setSocketFeedback( response.feedback() );
51
52 // rendering
53 QgsRenderer renderer( context );
54 std::unique_ptr<QImage> result( renderer.getMap() );
55
56 if ( response.feedback() && response.feedback()->isCanceled() )
57 {
58 return;
59 }
60
61 if ( result )
62 {
63 const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
64 writeImage( response, *result, format, context.imageQuality() );
65 }
66 else
67 {
68 throw QgsException( QStringLiteral( "Failed to compute GetMap image" ) );
69 }
70 }
71} // namespace QgsWms
Defines a QGIS exception class.
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
Defines interfaces exposed by QGIS Server and made available to plugins.
virtual QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
QgsServerParameters serverParameters() const
Returns parameters.
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
Defines the response interface passed to QgsService.
virtual QgsFeedback * feedback() const
Returns the socket feedback if any.
Map renderer for WMS requests.
std::unique_ptr< QImage > getMap()
Returns the map as an image (or nullptr in case of error).
Exception class for WMS service exceptions.
Rendering context for the WMS renderer.
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
void setSocketFeedback(QgsFeedback *feedback)
Sets the response feedback.
int imageQuality() const
Returns the image quality to use for rendering according to the current configuration.
Defines request interfaces passed to WMS service.
const QgsWmsParameters & wmsParameters() const
Returns the parameters interpreted for the WMS service.
Median cut implementation.
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.