-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgswmsgetlegendgraphics.cpp
60 lines (46 loc) · 2.35 KB
/
qgswmsgetlegendgraphics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/***************************************************************************
qgswmsgetlegendgraphics.cpp
-------------------------
begin : December 20 , 2016
copyright : (C) 2007 by Marco Hugentobler (original code)
(C) 2014 by Alessandro Pasotti (original code)
(C) 2016 by David Marteau
email : marco dot hugentobler at karto dot baug dot ethz dot ch
a dot pasotti at itopen dot it
david dot marteau at 3liz dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgswmsutils.h"
#include "qgswmsgetlegendgraphics.h"
#include "qgswmsrenderer.h"
#include <QImage>
namespace QgsWms
{
void writeGetLegendGraphics( QgsServerInterface *serverIface, const QgsProject *project,
const QString &version, const QgsServerRequest &request,
QgsServerResponse &response )
{
Q_UNUSED( version );
QgsServerRequest::Parameters params = request.parameters();
QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
QgsRenderer renderer( serverIface, project, wmsParameters );
std::unique_ptr<QImage> result( renderer.getLegendGraphics() );
if ( result )
{
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
writeImage( response, *result, format, renderer.getImageQuality() );
}
else
{
throw QgsServiceException( QStringLiteral( "UnknownError" ),
QStringLiteral( "Failed to compute GetLegendGraphics image" ) );
}
}
} // samespace QgsWms