QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 "qgswmsutils.h"
20 #include "qgsmaplayer.h"
21 #include "qgsvectorlayer.h"
22 #include "qgsdxfexport.h"
23 #include "qgswmsrenderer.h"
24 
25 namespace QgsWms
26 {
27 
28  namespace
29  {
30 
31  QMap<QString, QString> parseFormatOptions( const QString &optionString )
32  {
33  QMap<QString, QString> options;
34 
35  QStringList optionsList = optionString.split( ';' );
36  for ( auto optionsIt = optionsList.constBegin(); optionsIt != optionsList.constEnd(); ++optionsIt )
37  {
38  int equalIdx = optionsIt->indexOf( ':' );
39  if ( equalIdx > 0 && equalIdx < ( optionsIt->length() - 1 ) )
40  {
41  options.insert( optionsIt->left( equalIdx ).toUpper(),
42  optionsIt->right( optionsIt->length() - equalIdx - 1 ).toUpper() );
43  }
44  }
45  return options;
46  }
47 
48  }
49 
50  void writeAsDxf( QgsServerInterface *serverIface, const QgsProject *project,
51  const QString &version, const QgsServerRequest &request,
52  QgsServerResponse &response )
53  {
54  Q_UNUSED( version );
55 
56  QgsServerRequest::Parameters params = request.parameters();
57 
58  QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
59  QgsRenderer renderer( serverIface, project, wmsParameters );
60 
61  QMap<QString, QString> formatOptionsMap = parseFormatOptions( params.value( QStringLiteral( "FORMAT_OPTIONS" ) ) );
62 
63  QgsDxfExport dxf = renderer.getDxf( formatOptionsMap );
64 
65  QString codec = QStringLiteral( "ISO-8859-1" );
66  QMap<QString, QString>::const_iterator codecIt = formatOptionsMap.find( QStringLiteral( "CODEC" ) );
67  if ( codecIt != formatOptionsMap.constEnd() )
68  {
69  codec = formatOptionsMap.value( QStringLiteral( "CODEC" ) );
70  }
71 
72  // Write output
73  response.setHeader( "Content-Type", "application/dxf" );
74  dxf.writeToFile( response.io(), codec );
75  }
76 
77 
78 } // 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.
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...
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
QMap< QString, QString > Parameters