QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 QgsWmsRequest &request,
33  QgsServerResponse &response )
34  {
35  if ( request.serverParameters().version().isEmpty() )
36  {
37  throw QgsServiceException( QgsServiceException::OGC_OperationNotSupported,
38  QStringLiteral( "Please add the value of the VERSION parameter" ), 501 );
39  }
40 
41  // prepare render context
42  QgsWmsRenderContext context( project, serverIface );
43  context.setFlag( QgsWmsRenderContext::UpdateExtent );
44  context.setFlag( QgsWmsRenderContext::UseOpacity );
45  context.setFlag( QgsWmsRenderContext::UseFilter );
46  context.setFlag( QgsWmsRenderContext::UseSelection );
47  context.setFlag( QgsWmsRenderContext::AddHighlightLayers );
49  context.setFlag( QgsWmsRenderContext::SetAccessControl );
50  context.setFlag( QgsWmsRenderContext::UseTileBuffer );
51  context.setParameters( request.wmsParameters() );
52 
53  // rendering
54  QgsRenderer renderer( context );
55  std::unique_ptr<QImage> result( renderer.getMap() );
56 
57  if ( result )
58  {
59  const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
60  writeImage( response, *result, format, context.imageQuality() );
61  }
62  else
63  {
64  throw QgsException( QStringLiteral( "Failed to compute GetMap image" ) );
65  }
66  }
67 } // namespace QgsWms
QgsWms::QgsWmsRenderContext::UpdateExtent
@ UpdateExtent
Definition: qgswmsrendercontext.h:58
qgswmsrenderer.h
QgsException
Defines a QGIS exception class.
Definition: qgsexception.h:34
QgsWms::writeGetMap
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgswmsgetmap.cpp:48
qgswmsutils.h
QgsWms::QgsWmsRenderContext::UseFilter
@ UseFilter
Definition: qgswmsrendercontext.h:55
QgsWms::writeImage
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
Definition: qgswmsutils.cpp:128
QgsWms::QgsWmsRenderContext::AddHighlightLayers
@ AddHighlightLayers
Definition: qgswmsrendercontext.h:57
QgsWms::QgsWmsRenderContext::AddExternalLayers
@ AddExternalLayers
Definition: qgswmsrendercontext.h:62
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsWms::QgsWmsRenderContext::SetAccessControl
@ SetAccessControl
Definition: qgswmsrendercontext.h:59
qgswmsgetmap.h
QgsWms
Median cut implementation.
Definition: qgsdxfwriter.cpp:22
QgsWms::QgsServiceException::OGC_OperationNotSupported
@ OGC_OperationNotSupported
Definition: qgswmsserviceexception.h:73
QgsWms::QgsRenderer
Map renderer for WMS requests.
Definition: qgswmsrenderer.h:66
qgswmsserviceexception.h
QgsWms::QgsWmsRenderContext::UseSelection
@ UseSelection
Definition: qgswmsrendercontext.h:56
QgsWms::QgsWmsRenderContext::UseTileBuffer
@ UseTileBuffer
Definition: qgswmsrendercontext.h:64
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:43
QgsWms::QgsWmsRenderContext::UseOpacity
@ UseOpacity
Definition: qgswmsrendercontext.h:54