Skip to content

Commit e17a7d4

Browse files
committedJan 17, 2017
Move wcs as service module
1 parent 56b2f08 commit e17a7d4

35 files changed

+1026
-886
lines changed
 

‎doc/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,16 @@ IF(WITH_APIDOC)
8484
${DOXYGEN_INPUT}
8585
${CMAKE_SOURCE_DIR}/src/server/qgsserver.h
8686
${CMAKE_SOURCE_DIR}/src/server/qgscapabilitiescache.h
87-
${CMAKE_SOURCE_DIR}/src/server/qgsmapserviceexception.h
87+
${CMAKE_SOURCE_DIR}/src/server/qgsserverexception.h
8888
${CMAKE_SOURCE_DIR}/src/server/qgsrequesthandler.h
8989
${CMAKE_SOURCE_DIR}/src/server/qgsserverfilter.h
9090
${CMAKE_SOURCE_DIR}/src/server/qgsaccesscontrolfilter.h
9191
${CMAKE_SOURCE_DIR}/src/server/qgsserverinterface.h
92+
${CMAKE_SOURCE_DIR}/src/server/qgsserverrequest.h
93+
${CMAKE_SOURCE_DIR}/src/server/qgsserverresponse.h
94+
${CMAKE_SOURCE_DIR}/src/server/qgsserverrequest.h
95+
${CMAKE_SOURCE_DIR}/src/server/qgsservice.h
96+
${CMAKE_SOURCE_DIR}/src/server/qgsserviceregistry.h
9297
)
9398
ENDIF(WITH_SERVER_PLUGINS)
9499

‎doc/api_break.dox

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,13 @@ optional property map passing down layer level properties to the SLD encoders. I
18981898
- usedAttributes is now a const method and returns QSet<QString> instead of QStringList
18991899

19001900

1901+
QgsRequestHandler {#qgis_api_break_3_0_QgsRequestHandler}
1902+
-----------------
1903+
1904+
- Removed infoFormat and setInfoFormat methods: the format of the response is given and set with the "Content-Type" header.
1905+
- Removed setCoverageResponse
1906+
1907+
19011908
Processing {#qgis_api_break_3_0_Processing}
19021909
----------
19031910

‎python/server/qgsrequesthandler.sip

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class QgsRequestHandler /Abstract/
2929
/** Allow plugins to return a QgsServerException*/
3030
void setServiceException( const QgsServerException& ex );
3131

32-
//! @note not available in Python bindings
33-
void setGetCoverageResponse( QByteArray* ba );
34-
3532
/** Set an HTTP header*/
3633
void setHeader( const QString &name, const QString &value );
3734

@@ -50,9 +47,6 @@ class QgsRequestHandler /Abstract/
5047
/** Append the bytestream to response body*/
5148
void appendBody( const QByteArray &body );
5249

53-
/** Set the info format string such as "text/xml"*/
54-
void setInfoFormat( const QString &format );
55-
5650
/** Send out HTTP headers and flush output buffer*/
5751
void sendResponse();
5852

@@ -77,9 +71,6 @@ class QgsRequestHandler /Abstract/
7771
/** Return the requested format string*/
7872
QString format() const;
7973

80-
/** Return the mime type for the response*/
81-
QString infoFormat() const;
82-
8374
/** Return true if the HTTP headers were already sent to the client*/
8475
bool headersSent() const;
8576
};

‎python/server/qgsserverexception.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class QgsOgcServiceException
4747
QString message() const;
4848
QString code() const;
4949
QString locator() const;
50+
QString version() const;
5051

5152
virtual QByteArray formatResponse( QString& responseFormat / Out / ) const;
5253
};

‎python/server/qgsserverrequest.sip

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ class QgsServerRequest
7979
*/
8080
QMap<QString, QString> parameters() const;
8181

82+
/**
83+
* Set a parameter
84+
*/
85+
void setParameter( const QString& key, const QString& value );
86+
87+
/**
88+
* Get a parameter value
89+
*/
90+
QString getParameter( const QString& key ) const;
91+
92+
/**
93+
* Remove a parameter
94+
*/
95+
void removeParameter( const QString& key );
96+
8297
/**
8398
* Return post/put data
8499
* Check for QByteArray::isNull() to check if data

‎src/server/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ SET ( qgis_mapserv_SRCS
2424
qgscapabilitiescache.cpp
2525
qgsconfigcache.cpp
2626
qgsrequesthandler.cpp
27-
qgsowsserver.cpp
28-
qgswcsserver.cpp
2927
qgsserversettings.cpp
3028
qgsserverexception.cpp
3129
qgsmslayercache.cpp

‎src/server/qgsowsserver.cpp

Lines changed: 0 additions & 66 deletions
This file was deleted.

‎src/server/qgsowsserver.h

Lines changed: 0 additions & 110 deletions
This file was deleted.

‎src/server/qgsrequesthandler.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@ QMap<QString, QString> QgsRequestHandler::parameterMap() const
5353
return mRequest.parameters();
5454
}
5555

56-
void QgsRequestHandler::setHttpResponse( const QByteArray& ba, const QString &format )
57-
{
58-
QgsMessageLog::logMessage( QStringLiteral( "Checking byte array is ok to set..." ) );
59-
60-
if ( ba.size() < 1 )
61-
{
62-
return;
63-
}
64-
65-
QgsMessageLog::logMessage( QStringLiteral( "Byte array looks good, setting response..." ) );
66-
appendBody( ba );
67-
setInfoFormat( format );
68-
}
69-
7056
bool QgsRequestHandler::exceptionRaised() const
7157
{
7258
return mExceptionRaised;
@@ -107,70 +93,19 @@ void QgsRequestHandler::appendBody( const QByteArray &body )
10793
mResponse.write( body );
10894
}
10995

110-
void QgsRequestHandler::setInfoFormat( const QString &format )
111-
{
112-
mInfoFormat = format;
113-
114-
// Update header
115-
QString fmt = mInfoFormat;
116-
if ( mInfoFormat.startsWith( QLatin1String( "text/" ) ) || mInfoFormat.startsWith( QLatin1String( "application/vnd.ogc.gml" ) ) )
117-
{
118-
fmt.append( "; charset=utf-8" );
119-
}
120-
setHeader( QStringLiteral( "Content-Type" ), fmt );
121-
122-
}
123-
12496
void QgsRequestHandler::sendResponse()
12597
{
12698
// Send data to output
12799
mResponse.flush();
128100
}
129101

130-
131-
132-
QString QgsRequestHandler::formatToMimeType( const QString& format ) const
133-
{
134-
if ( format.compare( QLatin1String( "png" ), Qt::CaseInsensitive ) == 0 )
135-
{
136-
return QStringLiteral( "image/png" );
137-
}
138-
else if ( format.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0 )
139-
{
140-
return QStringLiteral( "image/jpeg" );
141-
}
142-
else if ( format.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
143-
{
144-
return QStringLiteral( "image/svg+xml" );
145-
}
146-
else if ( format.compare( QLatin1String( "pdf" ), Qt::CaseInsensitive ) == 0 )
147-
{
148-
return QStringLiteral( "application/pdf" );
149-
}
150-
return format;
151-
}
152-
153-
void QgsRequestHandler::setGetCapabilitiesResponse( const QDomDocument& doc )
154-
{
155-
QByteArray ba = doc.toByteArray();
156-
setHttpResponse( ba, QStringLiteral( "text/xml" ) );
157-
}
158-
159102
void QgsRequestHandler::setServiceException( const QgsServerException& ex )
160103
{
161104
// Safety measure to avoid potential leaks if called repeatedly
162105
mExceptionRaised = true;
163106
mResponse.write( ex );
164107
}
165108

166-
void QgsRequestHandler::setGetCoverageResponse( QByteArray* ba )
167-
{
168-
if ( ba )
169-
{
170-
setHttpResponse( *ba, QStringLiteral( "image/tiff" ) );
171-
}
172-
}
173-
174109
void QgsRequestHandler::setupParameters()
175110
{
176111
const QgsServerRequest::Parameters parameters = mRequest.parameters();

‎src/server/qgsrequesthandler.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,9 @@ class SERVER_EXPORT QgsRequestHandler
5454
explicit QgsRequestHandler( QgsServerRequest& request, QgsServerResponse& response );
5555
~QgsRequestHandler();
5656

57-
//! @note not available in Python bindings
58-
void setGetCapabilitiesResponse( const QDomDocument& doc );
59-
6057
//! Allow plugins to return a QgsMapServiceException
6158
void setServiceException( const QgsServerException &ex );
6259

63-
//! @note not available in Python bindings
64-
void setGetCoverageResponse( QByteArray* ba );
65-
6660
/** Send out HTTP headers and flush output buffer
6761
*
6862
* This method is intended only for streaming
@@ -88,9 +82,6 @@ class SERVER_EXPORT QgsRequestHandler
8882
//! Set the info format string such as "text/xml"
8983
void appendBody( const QByteArray &body );
9084

91-
//! Set the info format string such as "text/xml"
92-
void setInfoFormat( const QString &format );
93-
9485
//! Pointer to last raised exception
9586
bool exceptionRaised() const;
9687

@@ -117,19 +108,9 @@ class SERVER_EXPORT QgsRequestHandler
117108
//! Return the requested format string
118109
QString format() const { return mFormat; }
119110

120-
//! Return the mime type for the response
121-
QString infoFormat() const { return mInfoFormat; }
122-
123111
//! Return true if the HTTP headers were already sent to the client
124112
bool headersSent() const;
125113

126-
private:
127-
void setHttpResponse( const QByteArray& ba, const QString &format );
128-
129-
/** Converts format to official mimetype (e.g. 'jpg' to 'image/jpeg')
130-
@return mime string (or the entered string if not found)*/
131-
QString formatToMimeType( const QString& format ) const;
132-
133114
private:
134115

135116
void setupParameters();
@@ -138,7 +119,6 @@ class SERVER_EXPORT QgsRequestHandler
138119
QString mFormat;
139120
QString mFormatString; //format string as it is passed in the request (with base)
140121
QString mService;
141-
QString mInfoFormat;
142122
bool mExceptionRaised;
143123

144124
QgsServerRequest& mRequest;

‎src/server/qgsserver.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "qgsconfig.h"
2323
#include "qgsserver.h"
2424
#include "qgsmslayercache.h"
25-
2625
#include "qgsmapsettings.h"
2726
#include "qgsauthmanager.h"
2827
#include "qgscapabilitiescache.h"
@@ -31,7 +30,6 @@
3130
#include "qgsproject.h"
3231
#include "qgsproviderregistry.h"
3332
#include "qgslogger.h"
34-
#include "qgswcsserver.h"
3533
#include "qgsmapserviceexception.h"
3634
#include "qgspallabeling.h"
3735
#include "qgsnetworkaccessmanager.h"
@@ -403,8 +401,6 @@ void QgsServer::handleRequest( QgsServerRequest& request, QgsServerResponse& res
403401
QMap<QString, QString> parameterMap = request.parameters();
404402
printRequestParameters( parameterMap, logLevel );
405403

406-
QgsAccessControl* accessControl = sServerInterface->accessControls();
407-
408404
//Config file path
409405
QString configFilePath = configPath( *sConfigFilePath, parameterMap );
410406

@@ -438,31 +434,6 @@ void QgsServer::handleRequest( QgsServerRequest& request, QgsServerResponse& res
438434
{
439435
service->executeRequest( request, theResponse );
440436
}
441-
else if ( serviceString == QLatin1String( "WCS" ) )
442-
{
443-
444-
QgsWCSProjectParser* p = QgsConfigCache::instance()->wcsConfiguration(
445-
configFilePath
446-
, accessControl
447-
);
448-
if ( !p )
449-
{
450-
theRequestHandler.setServiceException( QgsMapServiceException( QStringLiteral( "Project file error" ),
451-
QStringLiteral( "Error reading the project file" ) ) );
452-
}
453-
else
454-
{
455-
QgsWCSServer wcsServer(
456-
configFilePath
457-
, sSettings
458-
, parameterMap
459-
, p
460-
, &theRequestHandler
461-
, accessControl
462-
);
463-
wcsServer.executeRequest();
464-
}
465-
}
466437
else
467438
{
468439
throw QgsOgcServiceException( QStringLiteral( "Service configuration error" ),

‎src/server/qgsserverexception.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727
/** \ingroup server
2828
* \class QgsServerException
2929
* \brief Exception base class for server exceptions.
30+
*
31+
* @note added in QGIS 3.0
3032
*/
3133
class SERVER_EXPORT QgsServerException : public QgsException
3234
{
3335
public:
36+
//! Constructor
3437
QgsServerException( const QString& message, int responseCode = 500 );
3538

3639
/**
@@ -52,32 +55,41 @@ class SERVER_EXPORT QgsServerException : public QgsException
5255
};
5356

5457
/** \ingroup server
55-
* \class QgsOcgServiceException
58+
* \class QgsOgcServiceException
5659
* \brief Exception base class for service exceptions.
5760
*
58-
* Note that this exception is assaciated with a default return code 200 which may be
61+
* Note that this exception is associated with a default return code 200 which may be
5962
* not appropriate in some situations.
63+
*
64+
* @note added in QGIS 3.0
6065
*/
6166
class SERVER_EXPORT QgsOgcServiceException : public QgsServerException
6267
{
6368
public:
69+
//! Construction
6470
QgsOgcServiceException( const QString& code, const QString& message, const QString& locator = QString(),
6571
int responseCode = 200, const QString& version = QStringLiteral( "1.3.0" ) );
6672

73+
//! @return message
6774
QString message() const { return mMessage; }
75+
76+
//! @return code
6877
QString code() const { return mCode; }
78+
79+
//! @return locator
6980
QString locator() const { return mLocator; }
81+
82+
//!return exception version
7083
QString version() const { return mVersion; }
7184

85+
//! Overrided from QgsServerException
7286
virtual QByteArray formatResponse( QString& responseFormat ) const override;
7387

7488
private:
7589
QString mCode;
7690
QString mMessage;
7791
QString mLocator;
7892
QString mVersion;
79-
80-
8193
};
8294

8395
#endif

‎src/server/qgsserverrequest.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
* \ingroup server
2828
* QgsServerRequest
2929
* Class defining request interface passed to services QgsService::executeRequest() method
30+
*
31+
* @note added in QGIS 3.0
3032
*/
3133

3234
// Note about design: this interface must be passed along to python and thus signatures methods must be
@@ -38,6 +40,9 @@ class SERVER_EXPORT QgsServerRequest
3840

3941
typedef QMap<QString, QString> Parameters;
4042

43+
/**
44+
* HTTP Method (or equivalent) used for the request
45+
*/
4146
enum Method
4247
{
4348
HeadMethod, PutMethod, GetMethod, PostMethod, DeleteMethod

‎src/server/qgsserverresponse.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class QgsServerException;
3030
* \ingroup server
3131
* QgsServerResponse
3232
* Class defining response interface passed to services QgsService::executeRequest() method
33+
*
34+
* @note added in QGIS 3.0
3335
*/
3436

3537
// Note:

‎src/server/qgsservice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class QgsProject;
3535
* This class provides methods for executing server requests
3636
* They are registered at runtime for a given service name.
3737
*
38+
* @note added in QGIS 3.0
3839
*/
3940
class SERVER_EXPORT QgsService
4041
{

‎src/server/qgsserviceregistry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class QgsServerInterface;
4141
* IMPORTANT: The registry hold ownership of registered services and
4242
* will call 'delete' on cleanup
4343
*
44+
* @note added in QGIS 3.0
4445
*/
4546
class SERVER_EXPORT QgsServiceRegistry
4647
{

‎src/server/qgswcsserver.cpp

Lines changed: 0 additions & 493 deletions
This file was deleted.

‎src/server/qgswcsserver.h

Lines changed: 0 additions & 73 deletions
This file was deleted.

‎src/server/services/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_SERVER_MODUL
99
ADD_SUBDIRECTORY(DummyService)
1010
ADD_SUBDIRECTORY(wms)
1111
ADD_SUBDIRECTORY(wfs)
12+
ADD_SUBDIRECTORY(wcs)
1213

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
########################################################
3+
# Files
4+
5+
SET (wcs_SRCS
6+
qgswcs.cpp
7+
qgswcsutils.cpp
8+
qgswcsgetcapabilities.cpp
9+
qgswcsdescribecoverage.cpp
10+
qgswcsgetcoverage.cpp
11+
)
12+
13+
########################################################
14+
# Build
15+
16+
ADD_LIBRARY (wcs MODULE ${wcs_SRCS})
17+
18+
19+
INCLUDE_DIRECTORIES(SYSTEM
20+
${GDAL_INCLUDE_DIR}
21+
${GEOS_INCLUDE_DIR}
22+
${PROJ_INCLUDE_DIR}
23+
${POSTGRES_INCLUDE_DIR}
24+
)
25+
26+
INCLUDE_DIRECTORIES(
27+
${CMAKE_BINARY_DIR}/src/core
28+
${CMAKE_BINARY_DIR}/src/python
29+
${CMAKE_BINARY_DIR}/src/analysis
30+
${CMAKE_BINARY_DIR}/src/server
31+
${CMAKE_CURRENT_BINARY_DIR}
32+
../../../core
33+
../../../core/dxf
34+
../../../core/geometry
35+
../../../core/raster
36+
../../../core/symbology-ng
37+
../../../core/composer
38+
../../../core/layertree
39+
../..
40+
..
41+
.
42+
)
43+
44+
45+
#endif
46+
TARGET_LINK_LIBRARIES(wcs
47+
qgis_core
48+
qgis_server
49+
)
50+
51+
52+
########################################################
53+
# Install
54+
55+
INSTALL(TARGETS wcs
56+
RUNTIME DESTINATION ${QGIS_SERVER_MODULE_DIR}
57+
LIBRARY DESTINATION ${QGIS_SERVER_MODULE_DIR}
58+
)
59+

‎src/server/services/wcs/qgswcs.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/***************************************************************************
2+
qgswcs.cpp
3+
-------------------------
4+
begin : January 16 , 2017
5+
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
6+
(C) 2017 by David Marteau
7+
email : rldhont at 3liz dot com
8+
david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
20+
#include "qgsmodule.h"
21+
#include "qgswcsutils.h"
22+
#include "qgswcsgetcapabilities.h"
23+
#include "qgswcsdescribecoverage.h"
24+
#include "qgswcsgetcoverage.h"
25+
26+
#define QSTR_COMPARE( str, lit )\
27+
(str.compare( QStringLiteral( lit ), Qt::CaseInsensitive ) == 0)
28+
29+
namespace QgsWcs
30+
{
31+
32+
class Service: public QgsService
33+
{
34+
public:
35+
// Constructor
36+
Service( QgsServerInterface* serverIface )
37+
: mServerIface( serverIface )
38+
{}
39+
40+
QString name() const { return QStringLiteral( "WCS" ); }
41+
QString version() const { return implementationVersion(); }
42+
43+
bool allowMethod( QgsServerRequest::Method method ) const
44+
{
45+
return method == QgsServerRequest::GetMethod || method == QgsServerRequest::PostMethod;
46+
}
47+
48+
void executeRequest( const QgsServerRequest& request, QgsServerResponse& response,
49+
QgsProject* project )
50+
{
51+
Q_UNUSED( project );
52+
53+
QgsServerRequest::Parameters params = request.parameters();
54+
QString versionString = params.value( "VERSION" );
55+
56+
// Set the default version
57+
if ( versionString.isEmpty() )
58+
{
59+
versionString = version();
60+
}
61+
62+
// Get the request
63+
QString req = params.value( QStringLiteral( "REQUEST" ) );
64+
if ( req.isEmpty() )
65+
{
66+
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
67+
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
68+
}
69+
70+
if ( QSTR_COMPARE( req, "GetCapabilities" ) )
71+
{
72+
writeGetCapabilities( mServerIface, versionString, request, response );
73+
}
74+
else if ( QSTR_COMPARE( req, "DescribeCoverage" ) )
75+
{
76+
writeDescribeCoverage( mServerIface, versionString, request, response );
77+
}
78+
else if ( QSTR_COMPARE( req, "GetCoverage" ) )
79+
{
80+
writeGetCoverage( mServerIface, versionString, request, response );
81+
}
82+
else
83+
{
84+
// Operation not supported
85+
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
86+
QStringLiteral( "Request %1 is not supported" ).arg( req ) );
87+
}
88+
}
89+
90+
private:
91+
QgsServerInterface* mServerIface;
92+
};
93+
94+
95+
} // namespace QgsWfs
96+
97+
98+
// Module
99+
class QgsWcsModule: public QgsServiceModule
100+
{
101+
public:
102+
void registerSelf( QgsServiceRegistry& registry, QgsServerInterface* serverIface )
103+
{
104+
QgsDebugMsg( "WCSModule::registerSelf called" );
105+
registry.registerService( new QgsWcs::Service( serverIface ) );
106+
}
107+
};
108+
109+
110+
// Entry points
111+
QGISEXTERN QgsServiceModule* QGS_ServiceModule_Init()
112+
{
113+
static QgsWcsModule module;
114+
return &module;
115+
}
116+
QGISEXTERN void QGS_ServiceModule_Exit( QgsServiceModule* )
117+
{
118+
// Nothing to do
119+
}
120+
121+
122+
123+
124+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/***************************************************************************
2+
qgswcsdescribecoverage.cpp
3+
-------------------------
4+
begin : January 16 , 2017
5+
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
6+
(C) 2017 by David Marteau
7+
email : rldhont at 3liz dot com
8+
david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
#include "qgswcsutils.h"
20+
#include "qgswcsdescribecoverage.h"
21+
22+
namespace QgsWcs
23+
{
24+
25+
/**
26+
* Output WCS DescribeCoverage response
27+
*/
28+
void writeDescribeCoverage( QgsServerInterface* serverIface, const QString& version,
29+
const QgsServerRequest& request, QgsServerResponse& response )
30+
{
31+
QDomDocument doc = createDescribeCoverageDocument( serverIface, version, request );
32+
33+
response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
34+
response.write( doc.toByteArray() );
35+
}
36+
37+
38+
QDomDocument createDescribeCoverageDocument( QgsServerInterface* serverIface, const QString& version,
39+
const QgsServerRequest& request )
40+
{
41+
Q_UNUSED( version );
42+
43+
QDomDocument doc;
44+
45+
QgsServerRequest::Parameters parameters = request.parameters();
46+
47+
QgsWCSProjectParser* configParser = getConfigParser( serverIface );
48+
49+
//wcs:WCS_Capabilities element
50+
QDomElement coveDescElement = doc.createElement( QStringLiteral( "CoverageDescription" )/*wcs:CoverageDescription*/ );
51+
coveDescElement.setAttribute( QStringLiteral( "xmlns" ), WCS_NAMESPACE );
52+
coveDescElement.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
53+
coveDescElement.setAttribute( QStringLiteral( "xsi:schemaLocation" ), WCS_NAMESPACE + " http://schemas.opengis.net/wcs/1.0.0/describeCoverage.xsd" );
54+
coveDescElement.setAttribute( QStringLiteral( "xmlns:gml" ), GML_NAMESPACE );
55+
coveDescElement.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
56+
coveDescElement.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0.0" ) );
57+
coveDescElement.setAttribute( QStringLiteral( "updateSequence" ), QStringLiteral( "0" ) );
58+
doc.appendChild( coveDescElement );
59+
60+
//defining coverage name
61+
QString coveName;
62+
//read COVERAGE
63+
QMap<QString, QString>::const_iterator cove_name_it = parameters.constFind( QStringLiteral( "COVERAGE" ) );
64+
if ( cove_name_it != parameters.constEnd() )
65+
{
66+
coveName = cove_name_it.value();
67+
}
68+
if ( coveName.isEmpty() )
69+
{
70+
QMap<QString, QString>::const_iterator cove_name_it = parameters.constFind( QStringLiteral( "IDENTIFIER" ) );
71+
if ( cove_name_it != parameters.constEnd() )
72+
{
73+
coveName = cove_name_it.value();
74+
}
75+
}
76+
configParser->describeCoverage( coveName, coveDescElement, doc );
77+
return doc;
78+
}
79+
80+
} // namespace QgsWcs
81+
82+
83+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/***************************************************************************
2+
qgswcsdescribecoverage.h
3+
-------------------------
4+
begin : January 16 , 2017
5+
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
6+
(C) 2017 by David Marteau
7+
email : rldhont at 3liz dot com
8+
david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
#ifndef QGSWCSDESCRIBECOVERAGE_H
20+
#define QGSWCSDESCRIBECOVERAGE_H
21+
22+
#include <QDomDocument>
23+
24+
namespace QgsWcs
25+
{
26+
27+
/**
28+
* Create describe coverage document
29+
*/
30+
QDomDocument createDescribeCoverageDocument( QgsServerInterface* serverIface, const QString& version,
31+
const QgsServerRequest& request );
32+
33+
/** Output WCS DescribeCoverage response
34+
*/
35+
void writeDescribeCoverage( QgsServerInterface* serverIface, const QString& version,
36+
const QgsServerRequest& request, QgsServerResponse& response );
37+
38+
} // samespace QgsWcs
39+
40+
#endif
41+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/***************************************************************************
2+
qgswcsgecapabilities.cpp
3+
-------------------------
4+
begin : January 16 , 2017
5+
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
6+
(C) 2017 by David Marteau
7+
email : rldhont at 3liz dot com
8+
david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
#include "qgswcsutils.h"
20+
#include "qgswcsgetcapabilities.h"
21+
22+
namespace QgsWcs
23+
{
24+
25+
/**
26+
* Output WCS GetCapabilities response
27+
*/
28+
void writeGetCapabilities( QgsServerInterface* serverIface, const QString& version,
29+
const QgsServerRequest& request, QgsServerResponse& response )
30+
{
31+
QDomDocument doc = createGetCapabilitiesDocument( serverIface, version, request );
32+
33+
response.setHeader( "Content-Type", "text/xml; charset=utf-8" );
34+
response.write( doc.toByteArray() );
35+
}
36+
37+
38+
QDomDocument createGetCapabilitiesDocument( QgsServerInterface* serverIface, const QString& version,
39+
const QgsServerRequest& request )
40+
{
41+
Q_UNUSED( version );
42+
43+
QDomDocument doc;
44+
45+
QgsWCSProjectParser* configParser = getConfigParser( serverIface );
46+
47+
//wcs:WCS_Capabilities element
48+
QDomElement wcsCapabilitiesElement = doc.createElement( QStringLiteral( "WCS_Capabilities" )/*wcs:WCS_Capabilities*/ );
49+
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns" ), WCS_NAMESPACE );
50+
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
51+
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xsi:schemaLocation" ), WCS_NAMESPACE + " http://schemas.opengis.net/wcs/1.0.0/wcsCapabilities.xsd" );
52+
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns:gml" ), GML_NAMESPACE );
53+
wcsCapabilitiesElement.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
54+
wcsCapabilitiesElement.setAttribute( QStringLiteral( "version" ), implementationVersion() );
55+
wcsCapabilitiesElement.setAttribute( QStringLiteral( "updateSequence" ), QStringLiteral( "0" ) );
56+
doc.appendChild( wcsCapabilitiesElement );
57+
58+
configParser->serviceCapabilities( wcsCapabilitiesElement, doc );
59+
60+
//INSERT Service
61+
62+
//wcs:Capability element
63+
QDomElement capabilityElement = doc.createElement( QStringLiteral( "Capability" )/*wcs:Capability*/ );
64+
wcsCapabilitiesElement.appendChild( capabilityElement );
65+
66+
//wcs:Request element
67+
QDomElement requestElement = doc.createElement( QStringLiteral( "Request" )/*wcs:Request*/ );
68+
capabilityElement.appendChild( requestElement );
69+
70+
//wcs:GetCapabilities
71+
QDomElement getCapabilitiesElement = doc.createElement( QStringLiteral( "GetCapabilities" )/*wcs:GetCapabilities*/ );
72+
requestElement.appendChild( getCapabilitiesElement );
73+
74+
QDomElement dcpTypeElement = doc.createElement( QStringLiteral( "DCPType" )/*wcs:DCPType*/ );
75+
getCapabilitiesElement.appendChild( dcpTypeElement );
76+
QDomElement httpElement = doc.createElement( QStringLiteral( "HTTP" )/*wcs:HTTP*/ );
77+
dcpTypeElement.appendChild( httpElement );
78+
79+
//Prepare url
80+
QString hrefString = serviceUrl( request, configParser );
81+
82+
QDomElement getElement = doc.createElement( QStringLiteral( "Get" )/*wcs:Get*/ );
83+
httpElement.appendChild( getElement );
84+
QDomElement onlineResourceElement = doc.createElement( QStringLiteral( "OnlineResource" )/*wcs:OnlineResource*/ );
85+
onlineResourceElement.setAttribute( QStringLiteral( "xlink:type" ), QStringLiteral( "simple" ) );
86+
onlineResourceElement.setAttribute( QStringLiteral( "xlink:href" ), hrefString );
87+
getElement.appendChild( onlineResourceElement );
88+
89+
QDomElement getCapabilitiesDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
90+
getCapabilitiesDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
91+
getCapabilitiesElement.appendChild( getCapabilitiesDhcTypePostElement );
92+
93+
QDomElement describeCoverageElement = getCapabilitiesElement.cloneNode().toElement();//this is the same as 'GetCapabilities'
94+
describeCoverageElement.setTagName( QStringLiteral( "DescribeCoverage" ) );
95+
requestElement.appendChild( describeCoverageElement );
96+
97+
QDomElement getCoverageElement = getCapabilitiesElement.cloneNode().toElement();//this is the same as 'GetCapabilities'
98+
getCoverageElement.setTagName( QStringLiteral( "GetCoverage" ) );
99+
requestElement.appendChild( getCoverageElement );
100+
101+
/*
102+
* Adding layer list in ContentMetadata
103+
*/
104+
QDomElement contentMetadataElement = doc.createElement( QStringLiteral( "ContentMetadata" )/*wcs:ContentMetadata*/ );
105+
wcsCapabilitiesElement.appendChild( contentMetadataElement );
106+
/*
107+
* Adding layer list in contentMetadataElement
108+
*/
109+
if ( configParser )
110+
{
111+
configParser->wcsContentMetadata( contentMetadataElement, doc );
112+
}
113+
114+
return doc;
115+
116+
}
117+
118+
} // namespace QgsWcs
119+
120+
121+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/***************************************************************************
2+
qgswcsgecapabilities.h
3+
-------------------------
4+
begin : January 16 , 2017
5+
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
6+
(C) 2017 by David Marteau
7+
email : rldhont at 3liz dot com
8+
david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
#ifndef QGSWCSGETCAPABILITIES_H
20+
#define QGSWCSGETCAPABILITIES_H
21+
22+
#include <QDomDocument>
23+
24+
namespace QgsWcs
25+
{
26+
27+
/**
28+
* Create get capabilities document
29+
*/
30+
QDomDocument createGetCapabilitiesDocument( QgsServerInterface* serverIface, const QString& version,
31+
const QgsServerRequest& request );
32+
33+
/** Output WCS GetCapabilities response
34+
*/
35+
void writeGetCapabilities( QgsServerInterface* serverIface, const QString& version,
36+
const QgsServerRequest& request, QgsServerResponse& response );
37+
38+
} // samespace QgsWcs
39+
40+
#endif
41+
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/***************************************************************************
2+
qgswcsgetcoverage.cpp
3+
-------------------------
4+
begin : January 16 , 2017
5+
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
6+
(C) 2017 by David Marteau
7+
email : rldhont at 3liz dot com
8+
david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
#include "qgswcsutils.h"
20+
#include "qgsrasterlayer.h"
21+
#include "qgsrasterdataprovider.h"
22+
#include "qgsrasterpipe.h"
23+
#include "qgsrasterprojector.h"
24+
#include "qgsrasterfilewriter.h"
25+
#include "qgswcsgetcoverage.h"
26+
27+
#include <QTemporaryFile>
28+
29+
namespace QgsWcs
30+
{
31+
32+
/**
33+
* Output WCS DescribeCoverage response
34+
*/
35+
void writeGetCoverage( QgsServerInterface* serverIface, const QString& version,
36+
const QgsServerRequest& request, QgsServerResponse& response )
37+
{
38+
Q_UNUSED( version );
39+
40+
response.write( getCoverageData( serverIface, request ) );
41+
response.setHeader( "Content-Type", "image/tiff" );
42+
}
43+
44+
QByteArray getCoverageData( QgsServerInterface* serverIface, const QgsServerRequest& request )
45+
{
46+
QgsWCSProjectParser* configParser = getConfigParser( serverIface );
47+
48+
QgsAccessControl* accessControl = serverIface->accessControls();
49+
50+
QStringList wcsLayersId = configParser->wcsLayers();
51+
52+
QList<QgsMapLayer*> layerList;
53+
54+
QgsServerRequest::Parameters parameters = request.parameters();
55+
56+
//defining coverage name
57+
QString coveName;
58+
//read COVERAGE
59+
QMap<QString, QString>::const_iterator cove_name_it = parameters.constFind( QStringLiteral( "COVERAGE" ) );
60+
if ( cove_name_it != parameters.constEnd() )
61+
{
62+
coveName = cove_name_it.value();
63+
}
64+
if ( coveName.isEmpty() )
65+
{
66+
QMap<QString, QString>::const_iterator cove_name_it = parameters.constFind( QStringLiteral( "IDENTIFIER" ) );
67+
if ( cove_name_it != parameters.constEnd() )
68+
{
69+
coveName = cove_name_it.value();
70+
}
71+
}
72+
73+
if ( coveName.isEmpty() )
74+
{
75+
throw QgsRequestNotWellFormedException( QStringLiteral( "COVERAGE is mandatory" ) );
76+
}
77+
78+
layerList = configParser->mapLayerFromCoverage( coveName );
79+
if ( layerList.size() < 1 )
80+
{
81+
throw QgsRequestNotWellFormedException( QStringLiteral( "The layer for the COVERAGE '%1' is not found" ).arg( coveName ) );
82+
}
83+
84+
double minx = 0.0, miny = 0.0, maxx = 0.0, maxy = 0.0;
85+
// WIDTh and HEIGHT
86+
int width = 0, height = 0;
87+
// CRS
88+
QString crs;
89+
90+
// read BBOX
91+
QgsRectangle bbox = parseBbox( parameters.value( QStringLiteral( "BBOX" ) ) );
92+
if ( !bbox.isEmpty() )
93+
{
94+
minx = bbox.xMinimum();
95+
miny = bbox.yMinimum();
96+
maxx = bbox.xMaximum();
97+
maxy = bbox.yMaximum();
98+
}
99+
else
100+
{
101+
throw QgsRequestNotWellFormedException( QStringLiteral( "The BBOX is mandatory and has to be xx.xxx,yy.yyy,xx.xxx,yy.yyy" ) );
102+
}
103+
104+
// read WIDTH
105+
bool conversionSuccess = false;
106+
width = parameters.value( QStringLiteral( "WIDTH" ), QStringLiteral( "0" ) ).toInt( &conversionSuccess );
107+
if ( !conversionSuccess )
108+
{
109+
width = 0;
110+
}
111+
// read HEIGHT
112+
height = parameters.value( QStringLiteral( "HEIGHT" ), QStringLiteral( "0" ) ).toInt( &conversionSuccess );
113+
if ( !conversionSuccess )
114+
{
115+
height = 0;
116+
}
117+
118+
if ( width < 0 || height < 0 )
119+
{
120+
throw QgsRequestNotWellFormedException( QStringLiteral( "The WIDTH and HEIGHT are mandatory and have to be integer" ) );
121+
}
122+
123+
crs = parameters.value( QStringLiteral( "CRS" ) );
124+
if ( crs.isEmpty() )
125+
{
126+
throw QgsRequestNotWellFormedException( QStringLiteral( "The CRS is mandatory" ) );
127+
}
128+
129+
QgsCoordinateReferenceSystem requestCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
130+
if ( !requestCRS.isValid() )
131+
{
132+
throw QgsRequestNotWellFormedException( QStringLiteral( "Invalid CRS" ) );
133+
}
134+
135+
QgsRectangle rect( minx, miny, maxx, maxy );
136+
137+
QgsMapLayer* layer = layerList.at( 0 );
138+
QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( layer );
139+
if ( rLayer && wcsLayersId.contains( rLayer->id() ) )
140+
{
141+
#ifdef HAVE_SERVER_PYTHON_PLUGINS
142+
if ( !accessControl->layerReadPermission( rLayer ) )
143+
{
144+
throw QgsSecurityAccessException( QStringLiteral( "You are not allowed to access to this coverage" ) );
145+
}
146+
#endif
147+
148+
// RESPONSE_CRS
149+
QgsCoordinateReferenceSystem responseCRS = rLayer->crs();
150+
crs = parameters.value( QStringLiteral( "RESPONSE_CRS" ) );
151+
if ( crs.isEmpty() )
152+
{
153+
responseCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
154+
if ( !responseCRS.isValid() )
155+
{
156+
responseCRS = rLayer->crs();
157+
}
158+
}
159+
160+
// transform rect
161+
if ( requestCRS != rLayer->crs() )
162+
{
163+
QgsCoordinateTransform t( requestCRS, rLayer->crs() );
164+
rect = t.transformBoundingBox( rect );
165+
}
166+
167+
QTemporaryFile tempFile;
168+
tempFile.open();
169+
QgsRasterFileWriter fileWriter( tempFile.fileName() );
170+
171+
// clone pipe/provider
172+
QgsRasterPipe pipe;
173+
if ( !pipe.set( rLayer->dataProvider()->clone() ) )
174+
{
175+
throw QgsRequestNotWellFormedException( QStringLiteral( "Cannet set pipe provider" ) );
176+
}
177+
178+
// add projector if necessary
179+
if ( responseCRS != rLayer->crs() )
180+
{
181+
QgsRasterProjector * projector = new QgsRasterProjector;
182+
projector->setCrs( rLayer->crs(), responseCRS );
183+
if ( !pipe.insert( 2, projector ) )
184+
{
185+
throw QgsRequestNotWellFormedException( QStringLiteral( "Cannot set pipe projector" ) );
186+
}
187+
}
188+
189+
QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( &pipe, width, height, rect, responseCRS );
190+
if ( err != QgsRasterFileWriter::NoError )
191+
{
192+
throw QgsRequestNotWellFormedException( QStringLiteral( "Cannot write raster error code: %1" ).arg( err ) );
193+
}
194+
return tempFile.readAll();
195+
}
196+
else
197+
{
198+
return QByteArray();
199+
}
200+
}
201+
202+
} // namespace QgsWcs
203+
204+
205+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
qgswcsgetcoverage.h
3+
-------------------------
4+
begin : January 16 , 2017
5+
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
6+
(C) 2017 by David Marteau
7+
email : rldhont at 3liz dot com
8+
david dot marteau at 3liz dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
#ifndef QGSWCSGETCOVERAGE_H
20+
#define QGSWCSGETCOVERAGE_H
21+
22+
#include <QByteArray>
23+
24+
namespace QgsWcs
25+
{
26+
27+
/** Output WCS GetCoverage response
28+
*/
29+
void writeGetCoverage( QgsServerInterface* serverIface, const QString& version,
30+
const QgsServerRequest& request, QgsServerResponse& response );
31+
32+
/**
33+
* Compute coverage data
34+
*/
35+
QByteArray getCoverageData( QgsServerInterface* serverIface, const QgsServerRequest& request );
36+
37+
} // samespace QgsWcs
38+
39+
#endif
40+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/***************************************************************************
2+
qgswcsserviceexception.h
3+
------------------------
4+
begin : January 17, 2017
5+
copyright : (C) 2017 by David Marteau
6+
email : david dot marteau 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+
#ifndef QGSWCSSERVICEEXCEPTION_H
19+
#define QGSWCSSERVICEEXCEPTION_H
20+
21+
#include <QString>
22+
23+
#include "qgsserverexception.h"
24+
25+
namespace QgsWcs
26+
{
27+
28+
/** \ingroup server
29+
* \class QgsserviceException
30+
* \brief Exception class for WFS service exceptions.
31+
*/
32+
class QgsServiceException : public QgsOgcServiceException
33+
{
34+
public:
35+
QgsServiceException( const QString& code, const QString& message,
36+
int responseCode = 200 )
37+
: QgsOgcServiceException( code, message, QString(), responseCode, QStringLiteral( "1.2.0" ) )
38+
{}
39+
40+
QgsServiceException( const QString& code, const QString& message, const QString& locator,
41+
int responseCode = 200 )
42+
: QgsOgcServiceException( code, message, locator, responseCode, QStringLiteral( "1.2.0" ) )
43+
{}
44+
45+
};
46+
47+
48+
/** \ingroup server
49+
* \class QgsSecurityAccessException
50+
* \brief Exception thrown when data access violates access controls
51+
*/
52+
class QgsSecurityAccessException: public QgsServiceException
53+
{
54+
public:
55+
QgsSecurityAccessException( const QString& message, const QString& locator = QString() )
56+
: QgsServiceException( QStringLiteral( "Security" ), message, locator, 403 )
57+
{}
58+
};
59+
60+
/** \ingroup server
61+
* \class QgsRequestNotWellFormedException
62+
* \brief Exception thrown in case of malformed request
63+
*/
64+
class QgsRequestNotWellFormedException: public QgsServiceException
65+
{
66+
public:
67+
QgsRequestNotWellFormedException( const QString& message, const QString& locator = QString() )
68+
: QgsServiceException( QStringLiteral( "RequestNotWellFormed" ), message, locator, 400 )
69+
{}
70+
};
71+
72+
73+
74+
75+
76+
77+
} // namespace QgsWcs
78+
79+
#endif
80+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/***************************************************************************
2+
qgswcsutils.cpp
3+
-------------------------
4+
begin : December 9, 2013
5+
copyright : (C) 2013 by René-Luc D'Hont
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 "qgswcsutils.h"
19+
#include "qgsconfigcache.h"
20+
21+
namespace QgsWcs
22+
{
23+
QString implementationVersion()
24+
{
25+
return QStringLiteral( "1.0.0" );
26+
}
27+
28+
// Return the wms config parser (Transitional)
29+
QgsWCSProjectParser* getConfigParser( QgsServerInterface* serverIface )
30+
{
31+
QString configFilePath = serverIface->configFilePath();
32+
33+
QgsWCSProjectParser* parser = QgsConfigCache::instance()->wcsConfiguration( configFilePath, serverIface->accessControls() );
34+
if ( !parser )
35+
{
36+
throw QgsServiceException(
37+
QStringLiteral( "WFS configuration error" ),
38+
QStringLiteral( "There was an error reading the project file or the SLD configuration" ) );
39+
}
40+
return parser;
41+
}
42+
43+
QString serviceUrl( const QgsServerRequest& request, QgsWCSProjectParser* parser )
44+
{
45+
QString href;
46+
if ( parser )
47+
{
48+
href = parser->wcsServiceUrl();
49+
if ( href.isEmpty() )
50+
{
51+
href = parser->serviceUrl();
52+
}
53+
}
54+
55+
// Build default url
56+
if ( href.isEmpty() )
57+
{
58+
QUrl url = request.url();
59+
QUrlQuery q( url );
60+
61+
q.removeAllQueryItems( QStringLiteral( "REQUEST" ) );
62+
q.removeAllQueryItems( QStringLiteral( "VERSION" ) );
63+
q.removeAllQueryItems( QStringLiteral( "SERVICE" ) );
64+
q.removeAllQueryItems( QStringLiteral( "_DC" ) );
65+
66+
url.setQuery( q );
67+
href = url.toString( QUrl::FullyDecoded );
68+
69+
}
70+
71+
return href;
72+
}
73+
74+
QgsRectangle parseBbox( const QString& bboxStr )
75+
{
76+
QStringList lst = bboxStr.split( QStringLiteral( "," ) );
77+
if ( lst.count() != 4 )
78+
return QgsRectangle();
79+
80+
double d[4];
81+
bool ok;
82+
for ( int i = 0; i < 4; i++ )
83+
{
84+
lst[i].replace( QLatin1String( " " ), QLatin1String( "+" ) );
85+
d[i] = lst[i].toDouble( &ok );
86+
if ( !ok )
87+
return QgsRectangle();
88+
}
89+
return QgsRectangle( d[0], d[1], d[2], d[3] );
90+
}
91+
92+
} // namespace QgsWfs
93+
94+

‎src/server/services/wcs/qgswcsutils.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/***************************************************************************
2+
qgswcsutils.h
3+
4+
Define WCS service utility functions
5+
------------------------------------
6+
begin : January 16 , 2017
7+
copyright : (C) 2013 by René-Luc D'Hont ( parts from qgswcsserver )
8+
(C) 2017 by David Marteau
9+
email : rldhont at 3liz dot com
10+
david dot marteau at 3liz dot com
11+
***************************************************************************/
12+
13+
/***************************************************************************
14+
* *
15+
* This program is free software; you can redistribute it and/or modify *
16+
* it under the terms of the GNU General Public License as published by *
17+
* the Free Software Foundation; either version 2 of the License, or *
18+
* (at your option) any later version. *
19+
* *
20+
***************************************************************************/
21+
#ifndef QGSWCSUTILS_H
22+
#define QGSWCSUTILS_H
23+
24+
#include "qgsmodule.h"
25+
#include "qgswcsprojectparser.h"
26+
#include "qgswcsserviceexception.h"
27+
28+
/**
29+
* \ingroup server
30+
* WCS implementation
31+
*/
32+
33+
//! WCS implementation
34+
namespace QgsWcs
35+
{
36+
37+
/**
38+
* Return the highest version supported by this implementation
39+
*/
40+
QString implementationVersion();
41+
42+
/**
43+
* Return the wms config parser (Transitional)
44+
*
45+
* XXX This is needed in the current implementation.
46+
* This should disappear as soon we get rid of singleton.
47+
*/
48+
QgsWCSProjectParser* getConfigParser( QgsServerInterface* serverIface );
49+
50+
/**
51+
* Service URL string
52+
*/
53+
QString serviceUrl( const QgsServerRequest& request, QgsWCSProjectParser* parser = nullptr );
54+
55+
/**
56+
* Parse bounding box
57+
*/
58+
//XXX At some point, should be moved to common library
59+
QgsRectangle parseBbox( const QString& bboxStr );
60+
61+
// Define namespaces used in WFS documents
62+
const QString WCS_NAMESPACE = QStringLiteral( "http://www.opengis.net/wcs" );
63+
const QString GML_NAMESPACE = QStringLiteral( "http://www.opengis.net/gml" );
64+
const QString OGC_NAMESPACE = QStringLiteral( "http://www.opengis.net/ogc" );
65+
66+
} // namespace QgsWcs
67+
68+
#endif
69+
70+

‎src/server/services/wfs/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ INCLUDE_DIRECTORIES(SYSTEM
2626

2727
INCLUDE_DIRECTORIES(
2828
${CMAKE_BINARY_DIR}/src/core
29-
${CMAKE_BINARY_DIR}/src/gui
3029
${CMAKE_BINARY_DIR}/src/python
3130
${CMAKE_BINARY_DIR}/src/analysis
3231
${CMAKE_BINARY_DIR}/src/server
@@ -38,9 +37,6 @@ INCLUDE_DIRECTORIES(
3837
../../../core/symbology-ng
3938
../../../core/composer
4039
../../../core/layertree
41-
../../../gui
42-
../../../gui/editorwidgets
43-
../../../gui/editorwidgets/core
4440
../..
4541
..
4642
.

‎src/server/services/wfs/qgswfsdescribefeaturetype.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
namespace QgsWfs
2727
{
28+
2829
/**
2930
* Create get capabilities document
3031
*/

‎src/server/services/wfs/qgswfsgetcapabilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
namespace QgsWfs
2727
{
28+
2829
/**
2930
* Create get capabilities document
3031
*/

‎src/server/services/wfs/qgswfsutils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
//! WMS implementation
3636
namespace QgsWfs
3737
{
38+
3839
/** Return the highest version supported by this implementation
3940
*/
4041
QString implementationVersion();

‎src/server/services/wms/qgswms.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ namespace QgsWms
8888
{
8989
writeGetCapabilities( mServerIface, versionString, request, response, false );
9090
}
91-
else if( QSTR_COMPARE( req, "GetProjectSettings" ) )
91+
else if ( QSTR_COMPARE( req, "GetProjectSettings" ) )
9292
{
9393
//getProjectSettings extends WMS 1.3.0 capabilities
9494
versionString = QStringLiteral( "1.3.0" );
9595
writeGetCapabilities( mServerIface, versionString, request, response, true );
9696
}
97-
else if( QSTR_COMPARE( req, "GetMap" ) )
97+
else if ( QSTR_COMPARE( req, "GetMap" ) )
9898
{
9999
QString format = params.value( QStringLiteral( "FORMAT" ) );
100100
if QSTR_COMPARE( format, "application/dxf" )
@@ -106,35 +106,35 @@ namespace QgsWms
106106
writeGetMap( mServerIface, versionString, request, response );
107107
}
108108
}
109-
else if( QSTR_COMPARE( req, "GetFeatureInfo" ) )
109+
else if ( QSTR_COMPARE( req, "GetFeatureInfo" ) )
110110
{
111111
writeGetFeatureInfo( mServerIface, versionString, request, response );
112112
}
113-
else if( QSTR_COMPARE( req, "GetContext" ) )
113+
else if ( QSTR_COMPARE( req, "GetContext" ) )
114114
{
115115
writeGetContext( mServerIface, versionString, request, response );
116116
}
117-
else if( QSTR_COMPARE( req, "GetSchemaExtension" ) )
117+
else if ( QSTR_COMPARE( req, "GetSchemaExtension" ) )
118118
{
119119
writeGetSchemaExtension( mServerIface, versionString, request, response );
120120
}
121-
else if( QSTR_COMPARE( req, "GetStyle" ) )
121+
else if ( QSTR_COMPARE( req, "GetStyle" ) )
122122
{
123123
writeGetStyle( mServerIface, versionString, request, response );
124124
}
125-
else if( QSTR_COMPARE( req, "GetStyles" ) )
125+
else if ( QSTR_COMPARE( req, "GetStyles" ) )
126126
{
127127
writeGetStyles( mServerIface, versionString, request, response );
128128
}
129-
else if( QSTR_COMPARE( req, "DescribeLayer" ) )
129+
else if ( QSTR_COMPARE( req, "DescribeLayer" ) )
130130
{
131131
writeDescribeLayer( mServerIface, versionString, request, response );
132132
}
133-
else if( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
133+
else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
134134
{
135135
writeGetLegendGraphics( mServerIface, versionString, request, response );
136136
}
137-
else if( QSTR_COMPARE( req, "GetPrint" ) )
137+
else if ( QSTR_COMPARE( req, "GetPrint" ) )
138138
{
139139
writeGetPrint( mServerIface, versionString, request, response );
140140
}

0 commit comments

Comments
 (0)
Please sign in to comment.