QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsdxfwriter.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdxfexport.cpp
3 -------------------------------------------------------------------
4Date : 20 December 2016
5Copyright : (C) 2015 by
6email : marco.hugentobler at sourcepole dot com (original code)
7Copyright : (C) 2016 by
8email : david dot marteau at 3liz dot com
9 ***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#include "qgsmodule.h"
18#include "qgsdxfwriter.h"
19#include "qgsdxfexport.h"
20#include "qgswmsrenderer.h"
21#include "qgswmsrestorer.h"
22
23namespace QgsWms
24{
25 void writeAsDxf( QgsServerInterface *serverIface, const QgsProject *project,
26 const QgsWmsRequest &request,
27 QgsServerResponse &response )
28 {
29 // prepare render context
30 QgsWmsRenderContext context( project, serverIface );
35 context.setParameters( request.wmsParameters() );
36 context.setSocketFeedback( response.feedback() );
37
38 // Write output
39 QgsRenderer renderer( context );
40
41 //Layer settings need to be kept until QgsDxfExport::writeToFile has finished
42 std::unique_ptr<QgsWmsRestorer> restorer = std::make_unique<QgsWmsRestorer>( context );
43 restorer.reset( new QgsWmsRestorer( context ) );
44
45 std::unique_ptr<QgsDxfExport> dxf = renderer.getDxf();
46 response.setHeader( "Content-Type", "application/dxf" );
47 dxf->writeToFile( response.io(), request.wmsParameters().dxfCodec() );
48 }
49} // namespace QgsWms
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
virtual QgsFeedback * feedback() const
Returns the socket feedback if any.
virtual QIODevice * io()=0
Returns the underlying QIODevice.
Map renderer for WMS requests.
std::unique_ptr< QgsDxfExport > getDxf()
Returns the map as DXF data.
QString dxfCodec() const
Returns the DXF CODEC parameter.
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.
Class defining request interface passed to WMS service.
const QgsWmsParameters & wmsParameters() const
Returns the parameters interpreted for the WMS service.
RAII class to restore the rendering context configuration on destruction.
Median cut implementation.
void writeAsDxf(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.