Skip to content
Permalink
Browse files

Update getDxf service

  • Loading branch information
pblottiere committed Mar 19, 2019
1 parent 3953608 commit 5c359a3ab251bbac060994f436565bd598093011
@@ -50,26 +50,12 @@ namespace QgsWms
{
Q_UNUSED( version );

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

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

QMap<QString, QString> formatOptionsMap = parseFormatOptions( params.value( QStringLiteral( "FORMAT_OPTIONS" ) ) );

QgsDxfExport dxf = renderer.getDxf( formatOptionsMap );

QString codec = QStringLiteral( "ISO-8859-1" );
QMap<QString, QString>::const_iterator codecIt = formatOptionsMap.find( QStringLiteral( "CODEC" ) );
if ( codecIt != formatOptionsMap.constEnd() )
{
codec = formatOptionsMap.value( QStringLiteral( "CODEC" ) );
}

// Write output
QgsDxfExport dxf = renderer.getDxf();
response.setHeader( "Content-Type", "application/dxf" );
dxf.writeToFile( response.io(), codec );
dxf.writeToFile( response.io(), wmsParameters.dxfCodec() );
}


} // namespace QgsWms
@@ -892,7 +892,7 @@ namespace QgsWms
return image.release();
}

QgsDxfExport QgsRenderer::getDxf( const QMap<QString, QString> &options )
QgsDxfExport QgsRenderer::getDxf()
{
QgsDxfExport dxf;

@@ -919,18 +919,11 @@ namespace QgsWms
layers = stylizedLayers( params );
}

// layer attributes options
QStringList layerAttributes;
QMap<QString, QString>::const_iterator layerAttributesIt = options.find( QStringLiteral( "LAYERATTRIBUTES" ) );
if ( layerAttributesIt != options.constEnd() )
{
layerAttributes = options.value( QStringLiteral( "LAYERATTRIBUTES" ) ).split( ',' );
}

// only wfs layers are allowed to be published
QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *mProject );

// get dxf layers
const QStringList attributes = mWmsParameters.dxfLayerAttributes();
QList< QgsDxfExport::DxfLayer > dxfLayers;
int layerIdx = -1;
for ( QgsMapLayer *layer : layers )
@@ -962,49 +955,21 @@ namespace QgsWms

// get the layer attribute used in dxf
int layerAttribute = -1;
if ( layerAttributes.size() > layerIdx )
if ( attributes.size() > layerIdx )
{
layerAttribute = vlayer->fields().indexFromName( layerAttributes.at( layerIdx ) );
layerAttribute = vlayer->fields().indexFromName( attributes[ layerIdx ] );
}

dxfLayers.append( QgsDxfExport::DxfLayer( vlayer, layerAttribute ) );
}

// add layers to dxf
dxf.addLayers( dxfLayers );

dxf.setLayerTitleAsName( options.contains( QStringLiteral( "USE_TITLE_AS_LAYERNAME" ) ) );

//MODE
QMap<QString, QString>::const_iterator modeIt = options.find( QStringLiteral( "MODE" ) );

QgsDxfExport::SymbologyExport se;
if ( modeIt == options.constEnd() )
{
se = QgsDxfExport::NoSymbology;
}
else
{
if ( modeIt->compare( QStringLiteral( "SymbolLayerSymbology" ), Qt::CaseInsensitive ) == 0 )
{
se = QgsDxfExport::SymbolLayerSymbology;
}
else if ( modeIt->compare( QStringLiteral( "FeatureSymbology" ), Qt::CaseInsensitive ) == 0 )
{
se = QgsDxfExport::FeatureSymbology;
}
else
{
se = QgsDxfExport::NoSymbology;
}
}
dxf.setSymbologyExport( se );

//SCALE
QMap<QString, QString>::const_iterator scaleIt = options.find( QStringLiteral( "SCALE" ) );
if ( scaleIt != options.constEnd() )
dxf.setLayerTitleAsName( mWmsParameters.dxfUseLayerTitleAsName() );
dxf.setSymbologyExport( mWmsParameters.dxfMode() );
if ( mWmsParameters.dxfFormatOptions().contains( QgsWmsParameters::DxfFormatOption::SCALE ) )
{
dxf.setSymbologyScale( scaleIt->toDouble() );
dxf.setSymbologyScale( mWmsParameters.dxfScale() );
}

return dxf;
@@ -95,7 +95,7 @@ namespace QgsWms
* \returns the map as DXF data
* \since QGIS 3.0
*/
QgsDxfExport getDxf( const QMap<QString, QString> &options );
QgsDxfExport getDxf();

/**
* Returns printed page as binary

0 comments on commit 5c359a3

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