Skip to content

Commit a0ee81b

Browse files
committed
Server: Brut force port WMS as service module
- Compile and load as service but functionality not tested - Removed dependencies to QgsRequestHandler - Removed dependencies to QgsOWSServer - Separate requests in their own units
1 parent fcacb28 commit a0ee81b

34 files changed

+5657
-2
lines changed

src/server/qgsserverrequest.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class SERVER_EXPORT QgsServerRequest
3535
{
3636
public:
3737

38+
typedef QMap<QString, QString> Parameters;
39+
3840
enum Method
3941
{
4042
HeadMethod, PutMethod, GetMethod, PostMethod, DeleteMethod
@@ -73,7 +75,7 @@ class SERVER_EXPORT QgsServerRequest
7375
* Return a map of query parameters with keys converted
7476
* to uppercase
7577
*/
76-
QMap<QString, QString> parameters() const;
78+
Parameters parameters() const;
7779

7880
/**
7981
* Return post/put data

src/server/qgssldconfigparser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class QgsVectorLayer;
2525
class QgsRasterLayer;
2626
class QTemporaryFile;
2727

28-
class QgsSLDConfigParser : public QgsWmsConfigParser
28+
class SERVER_EXPORT QgsSLDConfigParser : public QgsWmsConfigParser
2929
{
3030
public:
3131

src/server/services/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_SERVER_MODUL
77
SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_SERVER_MODULE_SUBDIR})
88

99
ADD_SUBDIRECTORY(DummyService)
10+
ADD_SUBDIRECTORY(wms)
1011

src/server/services/qgsmodule.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgsservicemodule.h"
2222
#include "qgsserviceregistry.h"
2323
#include "qgsservice.h"
24+
#include "qgsserverinterface.h"
2425
#include "qgslogger.h"
2526
#include "qgsmessagelog.h"
2627

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
########################################################
3+
# Files
4+
5+
SET (wms_SRCS
6+
qgswms.cpp
7+
qgswmsutils.cpp
8+
qgsdxfwriter.cpp
9+
qgswmsdescribelayer.cpp
10+
qgswmsgetcapabilities.cpp
11+
qgswmsgetcontext.cpp
12+
qgswmsgetfeatureinfo.cpp
13+
qgswmsgetlegendgraphics.cpp
14+
qgswmsgetmap.cpp
15+
qgswmsgetprint.cpp
16+
qgswmsgetschemaextension.cpp
17+
qgswmsgetstyle.cpp
18+
qgswmsgetstyles.cpp
19+
qgswmsservertransitional.cpp
20+
qgsfilterrestorer.cpp
21+
)
22+
23+
########################################################
24+
# Build
25+
26+
ADD_LIBRARY (wms MODULE ${wms_SRCS})
27+
28+
29+
INCLUDE_DIRECTORIES(SYSTEM
30+
${GDAL_INCLUDE_DIR}
31+
${GEOS_INCLUDE_DIR}
32+
${PROJ_INCLUDE_DIR}
33+
${POSTGRES_INCLUDE_DIR}
34+
)
35+
36+
INCLUDE_DIRECTORIES(
37+
${CMAKE_CURRENT_BINARY_DIR}
38+
../../../core
39+
../../../core/dxf
40+
../../../core/geometry
41+
../../../core/raster
42+
../../../core/symbology-ng
43+
../../../core/composer
44+
../../../core/layertree
45+
../../../gui
46+
../../../gui/editorwidgets
47+
../../../gui/editorwidgets/core
48+
../..
49+
..
50+
.
51+
)
52+
53+
54+
#endif
55+
TARGET_LINK_LIBRARIES(wms
56+
qgis_core
57+
qgis_server
58+
)
59+
60+
61+
########################################################
62+
# Install
63+
64+
INSTALL(TARGETS wms
65+
RUNTIME DESTINATION ${QGIS_SERVER_MODULE_DIR}
66+
LIBRARY DESTINATION ${QGIS_SERVER_MODULE_DIR}
67+
)
68+
+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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 "qgswmsservertransitional.h"
21+
#include "qgsmaplayer.h"
22+
#include "qgsvectorlayer.h"
23+
#include "qgsdxfexport.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( QStringLiteral( ";" ) );
36+
QStringList::const_iterator optionsIt = optionsList.constBegin();
37+
for ( ; optionsIt != optionsList.constEnd(); ++optionsIt )
38+
{
39+
int equalIdx = optionsIt->indexOf( QLatin1String( ":" ) );
40+
if ( equalIdx > 0 && equalIdx < ( optionsIt->length() - 1 ) )
41+
{
42+
options.insert( optionsIt->left( equalIdx ).toUpper(),
43+
optionsIt->right( optionsIt->length() - equalIdx - 1 ).toUpper() );
44+
}
45+
}
46+
return options;
47+
}
48+
49+
void readDxfLayerSettings( QgsWmsServer& server, QgsWmsConfigParser* configParser,
50+
QList< QPair<QgsVectorLayer *, int > >& layers,
51+
const QMap<QString, QString>& options )
52+
{
53+
QSet<QString> wfsLayers = QSet<QString>::fromList( configParser->wfsLayerNames() );
54+
55+
QStringList layerAttributes;
56+
QMap<QString, QString>::const_iterator layerAttributesIt = options.find( QStringLiteral( "LAYERATTRIBUTES" ) );
57+
if ( layerAttributesIt != options.constEnd() )
58+
{
59+
layerAttributes = options.value( QStringLiteral( "LAYERATTRIBUTES" ) ).split( QStringLiteral( "," ) );
60+
}
61+
62+
//LAYERS and STYLES
63+
QStringList layerList, styleList;
64+
server.readLayersAndStyles( layerList, styleList );
65+
66+
for ( int i = 0; i < layerList.size(); ++i )
67+
{
68+
QString layerName = layerList.at( i );
69+
QString styleName;
70+
if ( styleList.size() > i )
71+
{
72+
styleName = styleList.at( i );
73+
}
74+
75+
QList<QgsMapLayer*> layerList = configParser->mapLayerFromStyle( layerName, styleName );
76+
QList<QgsMapLayer*>::const_iterator layerIt = layerList.constBegin();
77+
for ( ; layerIt != layerList.constEnd(); ++layerIt )
78+
{
79+
if ( !( *layerIt ) )
80+
{
81+
continue;
82+
}
83+
84+
//vector layer?
85+
if (( *layerIt )->type() != QgsMapLayer::VectorLayer )
86+
{
87+
continue;
88+
}
89+
90+
QgsVectorLayer* vlayer = static_cast<QgsVectorLayer*>( *layerIt );
91+
92+
int layerAttribute = -1;
93+
if ( layerAttributes.size() > i )
94+
{
95+
layerAttribute = vlayer->pendingFields().indexFromName( layerAttributes.at( i ) );
96+
}
97+
98+
//only wfs layers are allowed to be published
99+
if ( !wfsLayers.contains( vlayer->name() ) )
100+
{
101+
continue;
102+
}
103+
104+
layers.append( qMakePair( vlayer, layerAttribute ) );
105+
}
106+
}
107+
}
108+
109+
}
110+
111+
void writeAsDxf( QgsServerInterface* serverIface, const QString& version, const QgsServerRequest& request, QgsServerResponse& response )
112+
{
113+
Q_UNUSED( version );
114+
115+
QgsWmsConfigParser* configParser = getConfigParser( serverIface );
116+
117+
QgsDxfExport dxf;
118+
QgsServerRequest::Parameters params = request.parameters();
119+
120+
QgsRectangle extent = parseBbox( params.value( QStringLiteral( "BBOX" ) ) );
121+
dxf.setExtent( extent );
122+
123+
QMap<QString, QString> formatOptionsMap = parseFormatOptions( params.value( QStringLiteral( "FORMAT_OPTIONS" ) ) );
124+
125+
QgsWmsServer server( serverIface->configFilePath(), params,
126+
configParser,
127+
serverIface->accessControls() );
128+
129+
QList< QPair<QgsVectorLayer *, int > > layers;
130+
readDxfLayerSettings( server, configParser, layers, formatOptionsMap );
131+
dxf.addLayers( layers );
132+
133+
dxf.setLayerTitleAsName( formatOptionsMap.contains( QStringLiteral( "USE_TITLE_AS_LAYERNAME" ) ) );
134+
135+
//MODE
136+
QMap<QString, QString>::const_iterator modeIt = formatOptionsMap.find( QStringLiteral( "MODE" ) );
137+
138+
QgsDxfExport::SymbologyExport se;
139+
if ( modeIt == formatOptionsMap.constEnd() )
140+
{
141+
se = QgsDxfExport::NoSymbology;
142+
}
143+
else
144+
{
145+
if ( modeIt->compare( QLatin1String( "SymbolLayerSymbology" ), Qt::CaseInsensitive ) == 0 )
146+
{
147+
se = QgsDxfExport::SymbolLayerSymbology;
148+
}
149+
else if ( modeIt->compare( QLatin1String( "FeatureSymbology" ), Qt::CaseInsensitive ) == 0 )
150+
{
151+
se = QgsDxfExport::FeatureSymbology;
152+
}
153+
else
154+
{
155+
se = QgsDxfExport::NoSymbology;
156+
}
157+
}
158+
dxf.setSymbologyExport( se );
159+
160+
//SCALE
161+
QMap<QString, QString>::const_iterator scaleIt = formatOptionsMap.find( QStringLiteral( "SCALE" ) );
162+
if ( scaleIt != formatOptionsMap.constEnd() )
163+
{
164+
dxf.setSymbologyScaleDenominator( scaleIt->toDouble() );
165+
}
166+
167+
QString codec = QStringLiteral( "ISO-8859-1" );
168+
QMap<QString, QString>::const_iterator codecIt = formatOptionsMap.find( QStringLiteral( "CODEC" ) );
169+
if ( codecIt != formatOptionsMap.constEnd() )
170+
{
171+
codec = formatOptionsMap.value( QStringLiteral( "CODEC" ) );
172+
}
173+
174+
// Write output
175+
response.setHeader( "Content-Type", "application/dxf" );
176+
dxf.writeToFile( response.io(), codec );
177+
}
178+
179+
180+
} // samespace QgsWms
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/***************************************************************************
2+
qgsdxfexport.h
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+
18+
namespace QgsWms
19+
{
20+
21+
/** Output GetMap response in Dfx format
22+
*/
23+
void writeAsDxf( QgsServerInterface* serverIface, const QString& version, const QgsServerRequest& request,
24+
QgsServerResponse& response );
25+
26+
} // samespace QgsWms
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/***************************************************************************
2+
qgsowsserver.cpp
3+
-------------------
4+
begin : February 27, 2012
5+
copyright : (C) 2012 by René-Luc D'Hont & Marco Hugentobler
6+
email : rldhont at 3liz dot com
7+
***************************************************************************/
8+
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+
18+
#include "qgsfilterrestorer.h"
19+
#include "qgsmessagelog.h"
20+
#include "qgsvectorlayer.h"
21+
#include "qgsvectordataprovider.h"
22+
23+
//! Apply filter from AccessControl
24+
void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccessControl* accessControl, QgsMapLayer* mapLayer,
25+
QHash<QgsMapLayer*, QString>& originalLayerFilters )
26+
{
27+
if ( QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( mapLayer ) )
28+
{
29+
QString sql = accessControl->extraSubsetString( layer );
30+
if ( !sql.isEmpty() )
31+
{
32+
if ( !originalLayerFilters.contains( layer ) )
33+
{
34+
originalLayerFilters.insert( layer, layer->subsetString() );
35+
}
36+
if ( !layer->subsetString().isEmpty() )
37+
{
38+
sql.prepend( " AND " );
39+
sql.prepend( layer->subsetString() );
40+
}
41+
if ( !layer->setSubsetString( sql ) )
42+
{
43+
QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
44+
}
45+
}
46+
}
47+
}
48+
49+
//! Restore layer filter as original
50+
void QgsOWSServerFilterRestorer::restoreLayerFilters( const QHash<QgsMapLayer*, QString>& filterMap )
51+
{
52+
QHash<QgsMapLayer*, QString>::const_iterator filterIt = filterMap.constBegin();
53+
for ( ; filterIt != filterMap.constEnd(); ++filterIt )
54+
{
55+
QgsVectorLayer* filteredLayer = qobject_cast<QgsVectorLayer*>( filterIt.key() );
56+
if ( filteredLayer )
57+
{
58+
QgsVectorDataProvider* dp = filteredLayer->dataProvider();
59+
if ( dp )
60+
{
61+
dp->setSubsetString( filterIt.value() );
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)