Skip to content
Permalink
Browse files

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
dmarteau committed Jan 10, 2017
1 parent fcacb28 commit a0ee81b9fe1c9d6ac7ac061ac66ec57f43e06b61
Showing with 5,657 additions and 2 deletions.
  1. +3 −1 src/server/qgsserverrequest.h
  2. +1 −1 src/server/qgssldconfigparser.h
  3. +1 −0 src/server/services/CMakeLists.txt
  4. +1 −0 src/server/services/qgsmodule.h
  5. +68 −0 src/server/services/wms/CMakeLists.txt
  6. +180 −0 src/server/services/wms/qgsdxfwriter.cpp
  7. +26 −0 src/server/services/wms/qgsdxfwriter.h
  8. +65 −0 src/server/services/wms/qgsfilterrestorer.cpp
  9. +64 −0 src/server/services/wms/qgsfilterrestorer.h
  10. +181 −0 src/server/services/wms/qgswms.cpp
  11. +53 −0 src/server/services/wms/qgswmsdescribelayer.cpp
  12. +34 −0 src/server/services/wms/qgswmsdescribelayer.h
  13. +88 −0 src/server/services/wms/qgswmsgetcapabilities.cpp
  14. +35 −0 src/server/services/wms/qgswmsgetcapabilities.h
  15. +53 −0 src/server/services/wms/qgswmsgetcontext.cpp
  16. +34 −0 src/server/services/wms/qgswmsgetcontext.h
  17. +185 −0 src/server/services/wms/qgswmsgetfeatureinfo.cpp
  18. +34 −0 src/server/services/wms/qgswmsgetfeatureinfo.h
  19. +63 −0 src/server/services/wms/qgswmsgetlegendgraphics.cpp
  20. +34 −0 src/server/services/wms/qgswmsgetlegendgraphics.h
  21. +63 −0 src/server/services/wms/qgswmsgetmap.cpp
  22. +34 −0 src/server/services/wms/qgswmsgetmap.h
  23. +81 −0 src/server/services/wms/qgswmsgetprint.cpp
  24. +34 −0 src/server/services/wms/qgswmsgetprint.h
  25. +53 −0 src/server/services/wms/qgswmsgetschemaextension.cpp
  26. +34 −0 src/server/services/wms/qgswmsgetschemaextension.h
  27. +54 −0 src/server/services/wms/qgswmsgetstyle.cpp
  28. +34 −0 src/server/services/wms/qgswmsgetstyle.h
  29. +53 −0 src/server/services/wms/qgswmsgetstyles.cpp
  30. +34 −0 src/server/services/wms/qgswmsgetstyles.h
  31. +3,103 −0 src/server/services/wms/qgswmsservertransitional.cpp
  32. +305 −0 src/server/services/wms/qgswmsservertransitional.h
  33. +482 −0 src/server/services/wms/qgswmsutils.cpp
  34. +90 −0 src/server/services/wms/qgswmsutils.h
@@ -35,6 +35,8 @@ class SERVER_EXPORT QgsServerRequest
{
public:

typedef QMap<QString, QString> Parameters;

enum Method
{
HeadMethod, PutMethod, GetMethod, PostMethod, DeleteMethod
@@ -73,7 +75,7 @@ class SERVER_EXPORT QgsServerRequest
* Return a map of query parameters with keys converted
* to uppercase
*/
QMap<QString, QString> parameters() const;
Parameters parameters() const;

/**
* Return post/put data
@@ -25,7 +25,7 @@ class QgsVectorLayer;
class QgsRasterLayer;
class QTemporaryFile;

class QgsSLDConfigParser : public QgsWmsConfigParser
class SERVER_EXPORT QgsSLDConfigParser : public QgsWmsConfigParser
{
public:

@@ -7,4 +7,5 @@ SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_SERVER_MODUL
SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_SERVER_MODULE_SUBDIR})

ADD_SUBDIRECTORY(DummyService)
ADD_SUBDIRECTORY(wms)

@@ -21,6 +21,7 @@
#include "qgsservicemodule.h"
#include "qgsserviceregistry.h"
#include "qgsservice.h"
#include "qgsserverinterface.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"

@@ -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}
)

@@ -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
@@ -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
@@ -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() );
}
}
}
}

0 comments on commit a0ee81b

Please sign in to comment.
You can’t perform that action at this time.