QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 "qgswmsutils.h"
22 #include "qgswmsgetmap.h"
23 #include "qgswmsrenderer.h"
24 #include "qgswmsserviceexception.h"
25 
26 #include <QImage>
27 
28 namespace QgsWms
29 {
30 
31  void writeGetMap( QgsServerInterface *serverIface, const QgsProject *project,
32  const QString &, const QgsServerRequest &request,
33  QgsServerResponse &response )
34  {
35  // get wms parameters from query
36  const QgsWmsParameters parameters( QUrlQuery( request.url() ) );
37 
38  // prepare render context
39  QgsWmsRenderContext context( project, serverIface );
48  context.setParameters( parameters );
49 
50  // rendering
51  QgsRenderer renderer( context );
52  std::unique_ptr<QImage> result( renderer.getMap() );
53 
54  if ( result )
55  {
56  const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
57  writeImage( response, *result, format, context.imageQuality() );
58  }
59  else
60  {
61  throw QgsException( QStringLiteral( "Failed to compute GetMap image" ) );
62  }
63  }
64 } // namespace QgsWms
QgsWms::writeGetMap
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgswmsgetmap.cpp:31
QgsWms::QgsWmsRenderContext::UpdateExtent
@ UpdateExtent
Definition: qgswmsrendercontext.h:45
QgsServerRequest::parameters
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
Definition: qgsserverrequest.cpp:85
qgswmsrenderer.h
QgsWms::QgsWmsParameters
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Definition: qgswmsparameters.h:324
QgsException
Defines a QGIS exception class.
Definition: qgsexception.h:35
qgswmsutils.h
QgsWms::QgsWmsRenderContext::UseFilter
@ UseFilter
Definition: qgswmsrendercontext.h:42
QgsWms::QgsWmsRenderContext::setFlag
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
Definition: qgswmsrendercontext.cpp:55
QgsWms::QgsWmsRenderContext::setParameters
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
Definition: qgswmsrendercontext.cpp:41
QgsWms::writeImage
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
Definition: qgswmsutils.cpp:107
QgsWms::QgsWmsRenderContext::AddHighlightLayers
@ AddHighlightLayers
Definition: qgswmsrendercontext.h:44
QgsServerRequest
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Definition: qgsserverrequest.h:39
QgsWms::QgsWmsRenderContext
Rendering context for the WMS renderer.
Definition: qgswmsrendercontext.h:35
QgsWms::QgsWmsRenderContext::imageQuality
int imageQuality() const
Returns the image quality to use for rendering according to the current configuration.
Definition: qgswmsrendercontext.cpp:129
QgsWms::QgsWmsRenderContext::AddExternalLayers
@ AddExternalLayers
Definition: qgswmsrendercontext.h:49
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsWms::QgsRenderer::getMap
QImage * getMap()
Returns the map as an image (or nullptr in case of error).
Definition: qgswmsrenderer.cpp:784
QgsWms::QgsWmsRenderContext::SetAccessControl
@ SetAccessControl
Definition: qgswmsrendercontext.h:46
qgswmsgetmap.h
QgsWms
Median cut implementation.
Definition: qgsdxfwriter.cpp:23
QgsServerRequest::url
QUrl url() const
Definition: qgsserverrequest.cpp:65
QgsWms::QgsRenderer
Map renderer for WMS requests.
Definition: qgswmsrenderer.h:64
qgswmsserviceexception.h
QgsWms::QgsWmsRenderContext::UseSelection
@ UseSelection
Definition: qgswmsrendercontext.h:43
QgsWms::QgsWmsRenderContext::UseTileBuffer
@ UseTileBuffer
Definition: qgswmsrendercontext.h:51
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:61
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:44
QgsWms::QgsWmsRenderContext::UseOpacity
@ UseOpacity
Definition: qgswmsrendercontext.h:41