Skip to content
Permalink
Browse files

Update getDxf with render context

  • Loading branch information
pblottiere committed Mar 25, 2019
1 parent 24f3f97 commit 66d4de64f797b07444d4ec1c6565fdb01da74ef7
Showing with 18 additions and 47 deletions.
  1. +12 −5 src/server/services/wms/qgsdxfwriter.cpp
  2. +6 −42 src/server/services/wms/qgswmsrenderer.cpp
@@ -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
@@ -801,33 +801,13 @@ namespace QgsWms

QgsDxfExport QgsRenderer::getDxf()
{
QgsDxfExport dxf;

// set extent
QgsRectangle extent = mWmsParameters.bboxAsRectangle();
dxf.setExtent( extent );

// get layers parameters
QList<QgsMapLayer *> layers;
QList<QgsWmsParametersLayer> params = mWmsParameters.layersParameters();

// init layer restorer before doing anything
std::unique_ptr<QgsLayerRestorer> restorer;
restorer.reset( new QgsLayerRestorer( mNicknameLayers.values() ) );

// init stylized layers according to LAYERS/STYLES or SLD
QString sld = mWmsParameters.sldBody();
if ( !sld.isEmpty() )
{
layers = sldStylizedLayers( sld );
}
else
{
layers = stylizedLayers( params );
}
restorer.reset( new QgsLayerRestorer( mContext.layers() ) );

// only wfs layers are allowed to be published
QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *mProject );
// configure layers
QList<QgsMapLayer *> layers = mContext.layersToRender();
configureLayers( layers );

// get dxf layers
const QStringList attributes = mWmsParameters.dxfLayerAttributes();
@@ -838,24 +818,6 @@ namespace QgsWms
layerIdx++;
if ( layer->type() != QgsMapLayerType::VectorLayer )
continue;
if ( !wfsLayerIds.contains( layer->id() ) )
continue;

checkLayerReadPermissions( layer );

for ( const QgsWmsParametersLayer &param : params )
{
if ( param.mNickname == layerNickname( *layer ) )
{
setLayerOpacity( layer, param.mOpacity );

setLayerFilter( layer, param.mFilter );

break;
}
}

setLayerAccessControlFilter( layer );

// cast for dxf layers
QgsVectorLayer *vlayer = static_cast<QgsVectorLayer *>( layer );
@@ -871,6 +833,8 @@ namespace QgsWms
}

// add layers to dxf
QgsDxfExport dxf;
dxf.setExtent( mWmsParameters.bboxAsRectangle() );
dxf.addLayers( dxfLayers );
dxf.setLayerTitleAsName( mWmsParameters.dxfUseLayerTitleAsName() );
dxf.setSymbologyExport( mWmsParameters.dxfMode() );

0 comments on commit 66d4de6

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