Skip to content
Permalink
Browse files

Add QgsOWSServer class, move code from qgis_map_serv.cpp into exectio…

…n() functions
  • Loading branch information
mhugent committed Mar 24, 2014
1 parent dcda258 commit 0e113e15916259dc961a3cec82d2d338631eb50c

Large diffs are not rendered by default.

@@ -0,0 +1,43 @@
/***************************************************************************
qgsowsserver.h
--------------
begin : March 24, 2014
copyright : (C) 2006 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#ifndef QGSOWSSERVER_H
#define QGSOWSSERVER_H

#include "qgsconfigparser.h"
#include "qgsrequesthandler.h"

class QgsOWSServer
{
public:
QgsOWSServer( const QString& configFilePath, const QMap<QString, QString>& parameters, QgsConfigParser* cp, QgsRequestHandler* rh ):
mParameters( parameters ), mConfigParser( cp ), mRequestHandler( rh ), mConfigFilePath( configFilePath ) {}
virtual ~QgsOWSServer() { delete mRequestHandler; }

virtual void executeRequest() = 0;

private:
QgsOWSServer() {}

protected:
QMap<QString, QString> mParameters;
QgsConfigParser* mConfigParser;
QgsRequestHandler* mRequestHandler;
QString mConfigFilePath;
};

#endif // QGSOWSSERVER_H
@@ -36,20 +36,83 @@ static const QString WCS_NAMESPACE = "http://www.opengis.net/wcs";
static const QString GML_NAMESPACE = "http://www.opengis.net/gml";
static const QString OGC_NAMESPACE = "http://www.opengis.net/ogc";

QgsWCSServer::QgsWCSServer( QMap<QString, QString> parameters )
: mParameterMap( parameters )
, mConfigParser( 0 )
QgsWCSServer::QgsWCSServer( const QString& configFilePath, QMap<QString, QString> parameters, QgsConfigParser* cp,
QgsRequestHandler* rh ): QgsOWSServer( configFilePath, parameters, cp, rh )
{
}

QgsWCSServer::~QgsWCSServer()
{
}

QgsWCSServer::QgsWCSServer()
QgsWCSServer::QgsWCSServer(): QgsOWSServer( QString(), QMap<QString, QString>(), 0, 0 )
{
}

void QgsWCSServer::executeRequest()
{
//request type
QString request = mParameters.value( "REQUEST" );
if ( request.isEmpty() )
{
//do some error handling
QgsDebugMsg( "unable to find 'REQUEST' parameter, exiting..." );
mRequestHandler->sendServiceException( QgsMapServiceException( "OperationNotSupported", "Please check the value of the REQUEST parameter" ) );
return;
}

if ( request.compare( "GetCapabilities", Qt::CaseInsensitive ) == 0 )
{
QDomDocument capabilitiesDocument;
try
{
capabilitiesDocument = getCapabilities();
}
catch ( QgsMapServiceException& ex )
{
mRequestHandler->sendServiceException( ex );
return;
}
QgsDebugMsg( "sending GetCapabilities response" );
mRequestHandler->sendGetCapabilitiesResponse( capabilitiesDocument );
return;
}
else if ( request.compare( "DescribeCoverage", Qt::CaseInsensitive ) == 0 )
{
QDomDocument describeDocument;
try
{
describeDocument = describeCoverage();
}
catch ( QgsMapServiceException& ex )
{
mRequestHandler->sendServiceException( ex );
return;
}
QgsDebugMsg( "sending GetCapabilities response" );
mRequestHandler->sendGetCapabilitiesResponse( describeDocument );
return;
}
else if ( request.compare( "GetCoverage", Qt::CaseInsensitive ) == 0 )
{
QByteArray* coverageOutput;
try
{
coverageOutput = getCoverage();
}
catch ( QgsMapServiceException& ex )
{
mRequestHandler->sendServiceException( ex );
return;
}
if ( coverageOutput )
{
mRequestHandler->sendGetCoverageResponse( coverageOutput );
}
return;
}
}

QDomDocument QgsWCSServer::getCapabilities()
{
QgsDebugMsg( "Entering." );
@@ -153,15 +216,15 @@ QDomDocument QgsWCSServer::describeCoverage()
//defining coverage name
QString coveName = "";
//read COVERAGE
QMap<QString, QString>::const_iterator cove_name_it = mParameterMap.find( "COVERAGE" );
if ( cove_name_it != mParameterMap.end() )
QMap<QString, QString>::const_iterator cove_name_it = mParameters.find( "COVERAGE" );
if ( cove_name_it != mParameters.end() )
{
coveName = cove_name_it.value();
}
if ( coveName == "" )
{
QMap<QString, QString>::const_iterator cove_name_it = mParameterMap.find( "IDENTIFIER" );
if ( cove_name_it != mParameterMap.end() )
QMap<QString, QString>::const_iterator cove_name_it = mParameters.find( "IDENTIFIER" );
if ( cove_name_it != mParameters.end() )
{
coveName = cove_name_it.value();
}
@@ -181,15 +244,15 @@ QByteArray* QgsWCSServer::getCoverage()
//defining coverage name
QString coveName = "";
//read COVERAGE
QMap<QString, QString>::const_iterator cove_name_it = mParameterMap.find( "COVERAGE" );
if ( cove_name_it != mParameterMap.end() )
QMap<QString, QString>::const_iterator cove_name_it = mParameters.find( "COVERAGE" );
if ( cove_name_it != mParameters.end() )
{
coveName = cove_name_it.value();
}
if ( coveName == "" )
{
QMap<QString, QString>::const_iterator cove_name_it = mParameterMap.find( "IDENTIFIER" );
if ( cove_name_it != mParameterMap.end() )
QMap<QString, QString>::const_iterator cove_name_it = mParameters.find( "IDENTIFIER" );
if ( cove_name_it != mParameters.end() )
{
coveName = cove_name_it.value();
}
@@ -216,8 +279,8 @@ QByteArray* QgsWCSServer::getCoverage()
QString crs = "";

// read BBOX
QMap<QString, QString>::const_iterator bbIt = mParameterMap.find( "BBOX" );
if ( bbIt == mParameterMap.end() )
QMap<QString, QString>::const_iterator bbIt = mParameters.find( "BBOX" );
if ( bbIt == mParameters.end() )
{
minx = 0; miny = 0; maxx = 0; maxy = 0;
}
@@ -240,11 +303,11 @@ QByteArray* QgsWCSServer::getCoverage()
}

// read WIDTH
width = mParameterMap.value( "WIDTH", "0" ).toInt( &conversionSuccess );
width = mParameters.value( "WIDTH", "0" ).toInt( &conversionSuccess );
if ( !conversionSuccess )
width = 0;
// read HEIGHT
height = mParameterMap.value( "HEIGHT", "0" ).toInt( &conversionSuccess );
height = mParameters.value( "HEIGHT", "0" ).toInt( &conversionSuccess );
if ( !conversionSuccess )
{
height = 0;
@@ -255,7 +318,7 @@ QByteArray* QgsWCSServer::getCoverage()
mErrors << QString( "The WIDTH and HEIGHT are mandatory and have to be integer" );
}

crs = mParameterMap.value( "CRS", "" );
crs = mParameters.value( "CRS", "" );
if ( crs == "" )
{
mErrors << QString( "The CRS is mandatory" );
@@ -281,7 +344,7 @@ QByteArray* QgsWCSServer::getCoverage()
{
// RESPONSE_CRS
QgsCoordinateReferenceSystem responseCRS = rLayer->crs();
crs = mParameterMap.value( "RESPONSE_CRS", "" );
crs = mParameters.value( "RESPONSE_CRS", "" );
if ( crs != "" )
{
responseCRS = QgsCRSCache::instance()->crsByAuthId( crs );
@@ -23,6 +23,7 @@
#include <QString>
#include <map>
#include "qgis.h"
#include "qgsowsserver.h"

class QgsConfigParser;
class QgsRequestHandler;
@@ -31,12 +32,16 @@ class QgsRequestHandler;
a map<QString, QString>. This map is usually generated by a subclass of QgsWMSRequestHandler, which makes QgsWCSServer
independent from any server side technology*/

class QgsWCSServer
class QgsWCSServer: public QgsOWSServer
{
public:
/**Constructor. Takes parameter map and a pointer to a renderer object (does not take ownership)*/
QgsWCSServer( QMap<QString, QString> parameters );
QgsWCSServer( const QString& configFilePath, QMap<QString, QString> parameters, QgsConfigParser* cp,
QgsRequestHandler* rh );
~QgsWCSServer();

void executeRequest();

/**Returns an XML file with the capabilities description (as described in the WFS specs)*/
QDomDocument getCapabilities();

@@ -55,10 +60,6 @@ class QgsWCSServer

/**Get service address from REQUEST_URI if not specified in the configuration*/
QString serviceUrl() const;

/**Map containing the WMS parameters*/
QMap<QString, QString> mParameterMap;
QgsConfigParser* mConfigParser;
};

#endif

0 comments on commit 0e113e1

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