Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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
- Loading branch information
Showing
34 changed files
with
5,657 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
######################################################## | ||
# Files | ||
|
||
SET (wms_SRCS | ||
qgswms.cpp | ||
qgswmsutils.cpp | ||
qgsdxfwriter.cpp | ||
qgswmsdescribelayer.cpp | ||
qgswmsgetcapabilities.cpp | ||
qgswmsgetcontext.cpp | ||
qgswmsgetfeatureinfo.cpp | ||
qgswmsgetlegendgraphics.cpp | ||
qgswmsgetmap.cpp | ||
qgswmsgetprint.cpp | ||
qgswmsgetschemaextension.cpp | ||
qgswmsgetstyle.cpp | ||
qgswmsgetstyles.cpp | ||
qgswmsservertransitional.cpp | ||
qgsfilterrestorer.cpp | ||
) | ||
|
||
######################################################## | ||
# Build | ||
|
||
ADD_LIBRARY (wms MODULE ${wms_SRCS}) | ||
|
||
|
||
INCLUDE_DIRECTORIES(SYSTEM | ||
${GDAL_INCLUDE_DIR} | ||
${GEOS_INCLUDE_DIR} | ||
${PROJ_INCLUDE_DIR} | ||
${POSTGRES_INCLUDE_DIR} | ||
) | ||
|
||
INCLUDE_DIRECTORIES( | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
../../../core | ||
../../../core/dxf | ||
../../../core/geometry | ||
../../../core/raster | ||
../../../core/symbology-ng | ||
../../../core/composer | ||
../../../core/layertree | ||
../../../gui | ||
../../../gui/editorwidgets | ||
../../../gui/editorwidgets/core | ||
../.. | ||
.. | ||
. | ||
) | ||
|
||
|
||
#endif | ||
TARGET_LINK_LIBRARIES(wms | ||
qgis_core | ||
qgis_server | ||
) | ||
|
||
|
||
######################################################## | ||
# Install | ||
|
||
INSTALL(TARGETS wms | ||
RUNTIME DESTINATION ${QGIS_SERVER_MODULE_DIR} | ||
LIBRARY DESTINATION ${QGIS_SERVER_MODULE_DIR} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/*************************************************************************** | ||
qgsdxfexport.cpp | ||
------------------------------------------------------------------- | ||
Date : 20 December 2016 | ||
Copyright : (C) 2015 by | ||
email : marco.hugentobler at sourcepole dot com (original code) | ||
Copyright : (C) 2016 by | ||
email : 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 "qgsmodule.h" | ||
#include "qgsdxfwriter.h" | ||
#include "qgswmsutils.h" | ||
#include "qgswmsservertransitional.h" | ||
#include "qgsmaplayer.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsdxfexport.h" | ||
|
||
namespace QgsWms | ||
{ | ||
|
||
namespace | ||
{ | ||
|
||
QMap<QString, QString> parseFormatOptions( const QString& optionString ) | ||
{ | ||
QMap<QString, QString> options; | ||
|
||
QStringList optionsList = optionString.split( QStringLiteral( ";" ) ); | ||
QStringList::const_iterator optionsIt = optionsList.constBegin(); | ||
for ( ; optionsIt != optionsList.constEnd(); ++optionsIt ) | ||
{ | ||
int equalIdx = optionsIt->indexOf( QLatin1String( ":" ) ); | ||
if ( equalIdx > 0 && equalIdx < ( optionsIt->length() - 1 ) ) | ||
{ | ||
options.insert( optionsIt->left( equalIdx ).toUpper(), | ||
optionsIt->right( optionsIt->length() - equalIdx - 1 ).toUpper() ); | ||
} | ||
} | ||
return options; | ||
} | ||
|
||
void readDxfLayerSettings( QgsWmsServer& server, QgsWmsConfigParser* configParser, | ||
QList< QPair<QgsVectorLayer *, int > >& layers, | ||
const QMap<QString, QString>& options ) | ||
{ | ||
QSet<QString> wfsLayers = QSet<QString>::fromList( configParser->wfsLayerNames() ); | ||
|
||
QStringList layerAttributes; | ||
QMap<QString, QString>::const_iterator layerAttributesIt = options.find( QStringLiteral( "LAYERATTRIBUTES" ) ); | ||
if ( layerAttributesIt != options.constEnd() ) | ||
{ | ||
layerAttributes = options.value( QStringLiteral( "LAYERATTRIBUTES" ) ).split( QStringLiteral( "," ) ); | ||
} | ||
|
||
//LAYERS and STYLES | ||
QStringList layerList, styleList; | ||
server.readLayersAndStyles( layerList, styleList ); | ||
|
||
for ( int i = 0; i < layerList.size(); ++i ) | ||
{ | ||
QString layerName = layerList.at( i ); | ||
QString styleName; | ||
if ( styleList.size() > i ) | ||
{ | ||
styleName = styleList.at( i ); | ||
} | ||
|
||
QList<QgsMapLayer*> layerList = configParser->mapLayerFromStyle( layerName, styleName ); | ||
QList<QgsMapLayer*>::const_iterator layerIt = layerList.constBegin(); | ||
for ( ; layerIt != layerList.constEnd(); ++layerIt ) | ||
{ | ||
if ( !( *layerIt ) ) | ||
{ | ||
continue; | ||
} | ||
|
||
//vector layer? | ||
if (( *layerIt )->type() != QgsMapLayer::VectorLayer ) | ||
{ | ||
continue; | ||
} | ||
|
||
QgsVectorLayer* vlayer = static_cast<QgsVectorLayer*>( *layerIt ); | ||
|
||
int layerAttribute = -1; | ||
if ( layerAttributes.size() > i ) | ||
{ | ||
layerAttribute = vlayer->pendingFields().indexFromName( layerAttributes.at( i ) ); | ||
} | ||
|
||
//only wfs layers are allowed to be published | ||
if ( !wfsLayers.contains( vlayer->name() ) ) | ||
{ | ||
continue; | ||
} | ||
|
||
layers.append( qMakePair( vlayer, layerAttribute ) ); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
void writeAsDxf( QgsServerInterface* serverIface, const QString& version, const QgsServerRequest& request, QgsServerResponse& response ) | ||
{ | ||
Q_UNUSED( version ); | ||
|
||
QgsWmsConfigParser* configParser = getConfigParser( serverIface ); | ||
|
||
QgsDxfExport dxf; | ||
QgsServerRequest::Parameters params = request.parameters(); | ||
|
||
QgsRectangle extent = parseBbox( params.value( QStringLiteral( "BBOX" ) ) ); | ||
dxf.setExtent( extent ); | ||
|
||
QMap<QString, QString> formatOptionsMap = parseFormatOptions( params.value( QStringLiteral( "FORMAT_OPTIONS" ) ) ); | ||
|
||
QgsWmsServer server( serverIface->configFilePath(), params, | ||
configParser, | ||
serverIface->accessControls() ); | ||
|
||
QList< QPair<QgsVectorLayer *, int > > layers; | ||
readDxfLayerSettings( server, configParser, layers, formatOptionsMap ); | ||
dxf.addLayers( layers ); | ||
|
||
dxf.setLayerTitleAsName( formatOptionsMap.contains( QStringLiteral( "USE_TITLE_AS_LAYERNAME" ) ) ); | ||
|
||
//MODE | ||
QMap<QString, QString>::const_iterator modeIt = formatOptionsMap.find( QStringLiteral( "MODE" ) ); | ||
|
||
QgsDxfExport::SymbologyExport se; | ||
if ( modeIt == formatOptionsMap.constEnd() ) | ||
{ | ||
se = QgsDxfExport::NoSymbology; | ||
} | ||
else | ||
{ | ||
if ( modeIt->compare( QLatin1String( "SymbolLayerSymbology" ), Qt::CaseInsensitive ) == 0 ) | ||
{ | ||
se = QgsDxfExport::SymbolLayerSymbology; | ||
} | ||
else if ( modeIt->compare( QLatin1String( "FeatureSymbology" ), Qt::CaseInsensitive ) == 0 ) | ||
{ | ||
se = QgsDxfExport::FeatureSymbology; | ||
} | ||
else | ||
{ | ||
se = QgsDxfExport::NoSymbology; | ||
} | ||
} | ||
dxf.setSymbologyExport( se ); | ||
|
||
//SCALE | ||
QMap<QString, QString>::const_iterator scaleIt = formatOptionsMap.find( QStringLiteral( "SCALE" ) ); | ||
if ( scaleIt != formatOptionsMap.constEnd() ) | ||
{ | ||
dxf.setSymbologyScaleDenominator( scaleIt->toDouble() ); | ||
} | ||
|
||
QString codec = QStringLiteral( "ISO-8859-1" ); | ||
QMap<QString, QString>::const_iterator codecIt = formatOptionsMap.find( QStringLiteral( "CODEC" ) ); | ||
if ( codecIt != formatOptionsMap.constEnd() ) | ||
{ | ||
codec = formatOptionsMap.value( QStringLiteral( "CODEC" ) ); | ||
} | ||
|
||
// Write output | ||
response.setHeader( "Content-Type", "application/dxf" ); | ||
dxf.writeToFile( response.io(), codec ); | ||
} | ||
|
||
|
||
} // samespace QgsWms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*************************************************************************** | ||
qgsdxfexport.h | ||
------------------------------------------------------------------- | ||
Date : 20 December 2016 | ||
Copyright : (C) 2015 by | ||
email : marco.hugentobler at sourcepole dot com (original code) | ||
Copyright : (C) 2016 by | ||
email : 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
namespace QgsWms | ||
{ | ||
|
||
/** Output GetMap response in Dfx format | ||
*/ | ||
void writeAsDxf( QgsServerInterface* serverIface, const QString& version, const QgsServerRequest& request, | ||
QgsServerResponse& response ); | ||
|
||
} // samespace QgsWms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*************************************************************************** | ||
qgsowsserver.cpp | ||
------------------- | ||
begin : February 27, 2012 | ||
copyright : (C) 2012 by René-Luc D'Hont & Marco Hugentobler | ||
email : rldhont 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 "qgsfilterrestorer.h" | ||
#include "qgsmessagelog.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsvectordataprovider.h" | ||
|
||
//! Apply filter from AccessControl | ||
void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccessControl* accessControl, QgsMapLayer* mapLayer, | ||
QHash<QgsMapLayer*, QString>& originalLayerFilters ) | ||
{ | ||
if ( QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( mapLayer ) ) | ||
{ | ||
QString sql = accessControl->extraSubsetString( layer ); | ||
if ( !sql.isEmpty() ) | ||
{ | ||
if ( !originalLayerFilters.contains( layer ) ) | ||
{ | ||
originalLayerFilters.insert( layer, layer->subsetString() ); | ||
} | ||
if ( !layer->subsetString().isEmpty() ) | ||
{ | ||
sql.prepend( " AND " ); | ||
sql.prepend( layer->subsetString() ); | ||
} | ||
if ( !layer->setSubsetString( sql ) ) | ||
{ | ||
QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
//! Restore layer filter as original | ||
void QgsOWSServerFilterRestorer::restoreLayerFilters( const QHash<QgsMapLayer*, QString>& filterMap ) | ||
{ | ||
QHash<QgsMapLayer*, QString>::const_iterator filterIt = filterMap.constBegin(); | ||
for ( ; filterIt != filterMap.constEnd(); ++filterIt ) | ||
{ | ||
QgsVectorLayer* filteredLayer = qobject_cast<QgsVectorLayer*>( filterIt.key() ); | ||
if ( filteredLayer ) | ||
{ | ||
QgsVectorDataProvider* dp = filteredLayer->dataProvider(); | ||
if ( dp ) | ||
{ | ||
dp->setSubsetString( filterIt.value() ); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.