QGIS API Documentation  3.6.0-Noosa (5873452)
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 
25 #include <QImage>
26 
27 namespace QgsWms
28 {
29 
30  void writeGetMap( QgsServerInterface *serverIface, const QgsProject *project,
31  const QString &version, const QgsServerRequest &request,
32  QgsServerResponse &response )
33  {
34  Q_UNUSED( version );
35 
36  QgsServerRequest::Parameters params = request.parameters();
37 
38  QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
39  QgsRenderer renderer( serverIface, project, wmsParameters );
40 
41  std::unique_ptr<QImage> result( renderer.getMap() );
42  if ( result )
43  {
44  QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
45  writeImage( response, *result, format, renderer.getImageQuality() );
46  }
47  else
48  {
49  throw QgsServiceException( QStringLiteral( "UnknownError" ),
50  QStringLiteral( "Failed to compute GetMap image" ) );
51  }
52  }
53 
54 } // namespace QgsWms
55 
56 
57 
58 
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
int getImageQuality() const
Returns the image quality to use for getMap request.
Exception class for WMS service exceptions.
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
QImage * getMap(HitTest *hitTest=nullptr)
Returns the map as an image (or a null pointer in case of error).
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
Provides an interface to retrieve and manipulate WMS parameters received from the client...
Reads and writes project states.
Definition: qgsproject.h:89
Median cut implementation.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins...
Map renderer for WMS requests.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
QMap< QString, QString > Parameters