Skip to content
Permalink
Browse files

[Server][Feature][needs-docs] Add WMTS service

This commit contains the first line of code for WMTS service in QGIS server.
The implementation is mainly for standard implementation.
  • Loading branch information
rldhont committed Jul 25, 2018
1 parent 732b96e commit 6d1a45b73893d00e4ca7e0cee9e86c478d4208d8
@@ -10,4 +10,5 @@ ADD_SUBDIRECTORY(DummyService)
ADD_SUBDIRECTORY(wms)
ADD_SUBDIRECTORY(wfs)
ADD_SUBDIRECTORY(wcs)
ADD_SUBDIRECTORY(wmts)

@@ -0,0 +1,57 @@

########################################################
# Files

SET (wmts_SRCS
qgswmts.cpp
qgswmtsutils.cpp
qgswmtsgetcapabilities.cpp
qgswmtsgettile.cpp
)

########################################################
# Build

ADD_LIBRARY (wmts MODULE ${wmts_SRCS})


INCLUDE_DIRECTORIES(SYSTEM
${GDAL_INCLUDE_DIR}
${POSTGRES_INCLUDE_DIR}
)

INCLUDE_DIRECTORIES(
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/python
${CMAKE_BINARY_DIR}/src/analysis
${CMAKE_BINARY_DIR}/src/server
${CMAKE_CURRENT_BINARY_DIR}
../wms
../../../core
../../../core/dxf
../../../core/expression
../../../core/geometry
../../../core/metadata
../../../core/raster
../../../core/symbology
../../../core/layertree
../..
..
.
)


TARGET_LINK_LIBRARIES(wmts
qgis_core
qgis_server
)


########################################################
# Install

INSTALL(TARGETS wmts
RUNTIME DESTINATION ${QGIS_SERVER_MODULE_DIR}
LIBRARY DESTINATION ${QGIS_SERVER_MODULE_DIR}
)

@@ -0,0 +1,126 @@
/***************************************************************************
qgswmts.cpp
-------------------------
begin : July 23 , 2018
copyright : (C) 2018 by René-Luc D'Hont
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 "qgsmodule.h"
#include "qgswmtsutils.h"
#include "qgswmtsgetcapabilities.h"
#include "qgswmtsgettile.h"

#define QSTR_COMPARE( str, lit )\
(str.compare( QStringLiteral( lit ), Qt::CaseInsensitive ) == 0)

namespace QgsWmts
{

/**
* \ingroup server
* \class QgsWmts::Service
* \brief OGC web service specialized for WMTS
* \since QGIS 3.0
*/
class Service: public QgsService
{
public:

/**
* Constructor for WMTS service.
* \param serverIface Interface for plugins.
*/
Service( QgsServerInterface *serverIface )
: mServerIface( serverIface )
{}

QString name() const override { return QStringLiteral( "WMTS" ); }
QString version() const override { return implementationVersion(); }

bool allowMethod( QgsServerRequest::Method method ) const override
{
return method == QgsServerRequest::GetMethod || method == QgsServerRequest::PostMethod;
}

void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
const QgsProject *project ) override
{
Q_UNUSED( project );

QgsServerRequest::Parameters params = request.parameters();
QString versionString = params.value( "VERSION" );

// Set the default version
if ( versionString.isEmpty() )
{
versionString = version();
}

// Get the request
QString req = params.value( QStringLiteral( "REQUEST" ) );
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
}

if ( QSTR_COMPARE( req, "GetCapabilities" ) )
{
writeGetCapabilities( mServerIface, project, versionString, request, response );
}
else if ( QSTR_COMPARE( req, "GetTile" ) )
{
writeGetTile( mServerIface, project, versionString, request, response );
}
else
{
// Operation not supported
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Request %1 is not supported" ).arg( req ) );
}
}

private:
QgsServerInterface *mServerIface = nullptr;
};


} // namespace QgsWmts

/**
* \ingroup server
* \class QgsWmtsModule
* \brief Service module specialized for WMTS
* \since QGIS 3.4
*/
class QgsWmtsModule: public QgsServiceModule
{
public:
void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
{
QgsDebugMsg( "WMTSModule::registerSelf called" );
registry.registerService( new QgsWmts::Service( serverIface ) );
}
};


// Entry points
QGISEXTERN QgsServiceModule *QGS_ServiceModule_Init()
{
static QgsWmtsModule module;
return &module;
}
QGISEXTERN void QGS_ServiceModule_Exit( QgsServiceModule * )
{
// Nothing to do
}

0 comments on commit 6d1a45b

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