QGIS API Documentation  3.6.0-Noosa (5873452)
qgsdxfwriter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdxfexport.cpp
3  -------------------------------------------------------------------
4 Date : 20 December 2016
5 Copyright : (C) 2015 by
6 email : marco.hugentobler at sourcepole dot com (original code)
7 Copyright : (C) 2016 by
8 email : 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 
22 namespace QgsWms
23 {
24 
25  namespace
26  {
27 
28  QMap<QString, QString> parseFormatOptions( const QString &optionString )
29  {
30  QMap<QString, QString> options;
31 
32  QStringList optionsList = optionString.split( ';' );
33  for ( auto optionsIt = optionsList.constBegin(); optionsIt != optionsList.constEnd(); ++optionsIt )
34  {
35  int equalIdx = optionsIt->indexOf( ':' );
36  if ( equalIdx > 0 && equalIdx < ( optionsIt->length() - 1 ) )
37  {
38  options.insert( optionsIt->left( equalIdx ).toUpper(),
39  optionsIt->right( optionsIt->length() - equalIdx - 1 ).toUpper() );
40  }
41  }
42  return options;
43  }
44 
45  }
46 
47  void writeAsDxf( QgsServerInterface *serverIface, const QgsProject *project,
48  const QString &version, const QgsServerRequest &request,
49  QgsServerResponse &response )
50  {
51  Q_UNUSED( version );
52 
53  QgsServerRequest::Parameters params = request.parameters();
54 
55  QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
56  QgsRenderer renderer( serverIface, project, wmsParameters );
57 
58  QMap<QString, QString> formatOptionsMap = parseFormatOptions( params.value( QStringLiteral( "FORMAT_OPTIONS" ) ) );
59 
60  QgsDxfExport dxf = renderer.getDxf( formatOptionsMap );
61 
62  QString codec = QStringLiteral( "ISO-8859-1" );
63  QMap<QString, QString>::const_iterator codecIt = formatOptionsMap.find( QStringLiteral( "CODEC" ) );
64  if ( codecIt != formatOptionsMap.constEnd() )
65  {
66  codec = formatOptionsMap.value( QStringLiteral( "CODEC" ) );
67  }
68 
69  // Write output
70  response.setHeader( "Content-Type", "application/dxf" );
71  dxf.writeToFile( response.io(), codec );
72  }
73 
74 
75 } // namespace QgsWms
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...
void writeAsDxf(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
QgsDxfExport getDxf(const QMap< QString, QString > &options)
Returns the map as DXF data.
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.
virtual QIODevice * io()=0
Returns the underlying QIODevice.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
QMap< QString, QString > Parameters