Skip to content
Permalink
Browse files

Merge pull request #9624 from pblottiere/server_context_3

[server] Add a WMS render context
  • Loading branch information
pblottiere committed Mar 28, 2019
2 parents 5b5cc50 + 131b659 commit d7f12ea5b42b07cbe6a13bbe210b59b92f88fb26
@@ -20,6 +20,7 @@ SET (wms_SRCS
qgswmsrenderer.cpp
qgswmsparameters.cpp
qgslayerrestorer.cpp
qgswmsrendercontext.cpp
)

SET (wms_MOC_HDRS
@@ -22,17 +22,24 @@ email : david dot marteau at 3liz dot com
namespace QgsWms
{
void writeAsDxf( QgsServerInterface *serverIface, const QgsProject *project,
const QString &version, const QgsServerRequest &request,
const QString &, const QgsServerRequest &request,
QgsServerResponse &response )
{
Q_UNUSED( version );
// get wms parameters from query
QgsWmsParameters parameters( QUrlQuery( request.url() ) );

QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
QgsRenderer renderer( serverIface, project, wmsParameters );
// prepare render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::UseWfsLayersOnly );
context.setFlag( QgsWmsRenderContext::UseOpacity );
context.setFlag( QgsWmsRenderContext::UseFilter );
context.setFlag( QgsWmsRenderContext::SetAccessControl );
context.setParameters( parameters );

// Write output
QgsRenderer renderer( context );
QgsDxfExport dxf = renderer.getDxf();
response.setHeader( "Content-Type", "application/dxf" );
dxf.writeToFile( response.io(), wmsParameters.dxfCodec() );
dxf.writeToFile( response.io(), parameters.dxfCodec() );
}
} // namespace QgsWms
@@ -24,26 +24,25 @@

namespace QgsWms
{

void writeGetFeatureInfo( QgsServerInterface *serverIface, const QgsProject *project,
const QString &version, const QgsServerRequest &request,
QgsServerResponse &response )
{
Q_UNUSED( version );
QgsServerRequest::Parameters params = request.parameters();

QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
QgsRenderer renderer( serverIface, project, wmsParameters );

QString infoFormat = params.value( QStringLiteral( "INFO_FORMAT" ), QStringLiteral( "text/plain" ) );

// get wms parameters from query
QgsWmsParameters parameters( QUrlQuery( request.url() ) );

// prepare render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::AddQueryLayers );
context.setFlag( QgsWmsRenderContext::UseFilter );
context.setFlag( QgsWmsRenderContext::UseScaleDenominator );
context.setFlag( QgsWmsRenderContext::SetAccessControl );
context.setParameters( parameters );

const QString infoFormat = request.parameters().value( QStringLiteral( "INFO_FORMAT" ), QStringLiteral( "text/plain" ) );
response.setHeader( QStringLiteral( "Content-Type" ), infoFormat + QStringLiteral( "; charset=utf-8" ) );

QgsRenderer renderer( context );
response.write( renderer.getFeatureInfo( version ) );
}


} // namespace QgsWms




@@ -26,19 +26,20 @@

namespace QgsWms
{

void writeGetLegendGraphics( QgsServerInterface *serverIface, const QgsProject *project,
const QString &version, const QgsServerRequest &request,
const QString &, const QgsServerRequest &request,
QgsServerResponse &response )
{
Q_UNUSED( version );

QgsServerRequest::Parameters params = request.parameters();
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
// get parameters from query
QgsWmsParameters parameters( QUrlQuery( request.url() ) );

QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
// init render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::UseScaleDenominator );
context.setParameters( parameters );

// Get cached image
const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
QgsAccessControl *accessControl = nullptr;
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
@@ -79,13 +80,12 @@ namespace QgsWms
}
}

QgsRenderer renderer( serverIface, project, wmsParameters );

QgsRenderer renderer( context );
std::unique_ptr<QImage> result( renderer.getLegendGraphics() );

if ( result )
{
writeImage( response, *result, format, renderer.imageQuality() );
writeImage( response, *result, format, context.imageQuality() );
if ( cacheManager )
{
QByteArray content = response.data();
@@ -99,10 +99,4 @@ namespace QgsWms
QStringLiteral( "Failed to compute GetLegendGraphics image" ) );
}
}


} // namespace QgsWms




@@ -28,31 +28,36 @@ namespace QgsWms
{

void writeGetMap( QgsServerInterface *serverIface, const QgsProject *project,
const QString &version, const QgsServerRequest &request,
const QString &, const QgsServerRequest &request,
QgsServerResponse &response )
{
Q_UNUSED( version );

QgsServerRequest::Parameters params = request.parameters();

QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
QgsRenderer renderer( serverIface, project, wmsParameters );

// get wms parameters from query
const QgsWmsParameters parameters( QUrlQuery( request.url() ) );

// prepare render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::UpdateExtent );
context.setFlag( QgsWmsRenderContext::UseOpacity );
context.setFlag( QgsWmsRenderContext::UseFilter );
context.setFlag( QgsWmsRenderContext::UseSelection );
context.setFlag( QgsWmsRenderContext::AddHighlightLayers );
context.setFlag( QgsWmsRenderContext::AddExternalLayers );
context.setFlag( QgsWmsRenderContext::SetAccessControl );
context.setParameters( parameters );

// rendering
QgsRenderer renderer( context );
std::unique_ptr<QImage> result( renderer.getMap() );

if ( result )
{
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
writeImage( response, *result, format, renderer.imageQuality() );
const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
writeImage( response, *result, format, context.imageQuality() );
}
else
{
throw QgsServiceException( QStringLiteral( "UnknownError" ),
QStringLiteral( "Failed to compute GetMap image" ) );
}
}

} // namespace QgsWms




@@ -28,13 +28,12 @@ namespace QgsWms
const QString &, const QgsServerRequest &request,
QgsServerResponse &response )
{
// get wms parameters from query
const QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
QgsRenderer renderer( serverIface, project, wmsParameters );

// GetPrint supports svg/png/pdf
const QgsWmsParameters::Format format = wmsParameters.format();
QString contentType;

// GetPrint supports svg/png/pdf
switch ( format )
{
case QgsWmsParameters::PNG:
@@ -55,8 +54,20 @@ namespace QgsWms
break;
}

// prepare render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::UpdateExtent );
context.setFlag( QgsWmsRenderContext::UseOpacity );
context.setFlag( QgsWmsRenderContext::UseFilter );
context.setFlag( QgsWmsRenderContext::UseSelection );
context.setFlag( QgsWmsRenderContext::SetAccessControl );
context.setFlag( QgsWmsRenderContext::AddHighlightLayers );
context.setFlag( QgsWmsRenderContext::AddExternalLayers );
context.setParameters( wmsParameters );

// rendering
QgsRenderer renderer( context );
response.setHeader( QStringLiteral( "Content-Type" ), contentType );
response.write( renderer.getPrint() );
}

} // namespace QgsWms
@@ -1534,10 +1534,12 @@ namespace QgsWms

QList<QgsWmsParametersExternalLayer> QgsWmsParameters::externalLayersParameters() const
{
auto notExternalLayer = []( const QString & name ) { return ! QgsWmsParameters::isExternalLayer( name ); };

QList<QgsWmsParametersExternalLayer> externalLayers;

QStringList layers = allLayersNickname();
QStringList::const_iterator rit = std::remove_if( layers.begin(), layers.end(), QgsWmsParameters::isExternalLayer );
QStringList::const_iterator rit = std::remove_if( layers.begin(), layers.end(), notExternalLayer );

for ( QStringList::const_iterator it = layers.begin(); it != rit; ++it )
{

0 comments on commit d7f12ea

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