23QString QgsDxfExportAlgorithm::name()
const
25 return QStringLiteral(
"dxfexport" );
28QString QgsDxfExportAlgorithm::displayName()
const
30 return QObject::tr(
"Export layers to DXF" );
33QStringList QgsDxfExportAlgorithm::tags()
const
35 return QObject::tr(
"layer,export,dxf,cad,dwg" ).split(
',' );
38QString QgsDxfExportAlgorithm::group()
const
40 return QObject::tr(
"Vector general" );
43QString QgsDxfExportAlgorithm::groupId()
const
45 return QStringLiteral(
"vectorgeneral" );
48QString QgsDxfExportAlgorithm::shortHelpString()
const
50 return QObject::tr(
"Exports layers to DXF file. For each layer, you can choose a field whose values are used to split features in generated destination layers in the DXF output.\n\n"
51 "If no field is chosen, you can still override the output layer name by directly entering a new output layer name in the Configure Layer panel or by preferring layer title (set in layer properties) to layer name." );
54QgsDxfExportAlgorithm *QgsDxfExportAlgorithm::createInstance()
const
56 return new QgsDxfExportAlgorithm();
59void QgsDxfExportAlgorithm::initAlgorithm(
const QVariantMap & )
62 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"SYMBOLOGY_MODE" ), QObject::tr(
"Symbology mode" ), QStringList() << QObject::tr(
"No Symbology" ) << QObject::tr(
"Feature Symbology" ) << QObject::tr(
"Symbol Layer Symbology" ),
false, 0 ) );
64 auto mapThemeParam = std::make_unique<QgsProcessingParameterMapTheme>( QStringLiteral(
"MAP_THEME" ), QObject::tr(
"Map theme" ), QVariant(),
true );
65 mapThemeParam->setHelp( QObject::tr(
"Match layer styling to the provided map theme" ) );
66 addParameter( mapThemeParam.release() );
68 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"ENCODING" ), QObject::tr(
"Encoding" ), encodings,
false, encodings.at( 0 ),
false,
true ) );
69 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"CRS" ), QObject::tr(
"CRS" ), QStringLiteral(
"EPSG:4326" ) ) );
70 auto extentParam = std::make_unique<QgsProcessingParameterExtent>( QStringLiteral(
"EXTENT" ), QObject::tr(
"Extent" ), QVariant(),
true );
71 extentParam->setHelp( QObject::tr(
"Limit exported features to those with geometries intersecting the provided extent" ) );
72 addParameter( extentParam.release() );
73 addParameter(
new QgsProcessingParameterBoolean( QStringLiteral(
"SELECTED_FEATURES_ONLY" ), QObject::tr(
"Use only selected features" ),
false ) );
74 auto useTitleParam = std::make_unique<QgsProcessingParameterBoolean>( QStringLiteral(
"USE_LAYER_TITLE" ), QObject::tr(
"Use layer title as name" ),
false );
75 useTitleParam->setHelp( QObject::tr(
"If no attribute is chosen and layer name is not being overridden, prefer layer title (set in layer properties) to layer name" ) );
76 addParameter( useTitleParam.release() );
79 addParameter(
new QgsProcessingParameterBoolean( QStringLiteral(
"EXPORT_LINES_WITH_ZERO_WIDTH" ), QObject::tr(
"Export lines with zero width" ) ),
false );
86 const QString mapTheme = parameterAsString( parameters, QStringLiteral(
"MAP_THEME" ), context );
102 QList<QgsVectorLayer *> mapLayers;
104 const QVariant layersVariant = parameters.value( parameterDefinition( QStringLiteral(
"LAYERS" ) )->name() );
108 if ( !layer.layer() )
111 mapLayers.push_back( layer.layer() );
115 const double symbologyScale = parameterAsDouble( parameters, QStringLiteral(
"SYMBOLOGY_SCALE" ), context );
116 const QString encoding = parameterAsEnumString( parameters, QStringLiteral(
"ENCODING" ), context );
118 const bool selectedFeaturesOnly = parameterAsBool( parameters, QStringLiteral(
"SELECTED_FEATURES_ONLY" ), context );
119 const bool useLayerTitle = parameterAsBool( parameters, QStringLiteral(
"USE_LAYER_TITLE" ), context );
120 const bool useMText = parameterAsBool( parameters, QStringLiteral(
"MTEXT" ), context );
121 const bool force2D = parameterAsBool( parameters, QStringLiteral(
"FORCE_2D" ), context );
122 const bool exportLinesWithZeroWidth = parameterAsBool( parameters, QStringLiteral(
"EXPORT_LINES_WITH_ZERO_WIDTH" ), context );
125 if ( parameters.value( QStringLiteral(
"EXTENT" ) ).isValid() )
127 extent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context,
crs );
130 const QString outputFile = parameterAsFileOutput( parameters, QStringLiteral(
"OUTPUT" ), context );
150 if ( selectedFeaturesOnly )
152 if ( exportLinesWithZeroWidth )
156 QFile dxfFile( outputFile );
157 switch ( dxfExport.
writeToFile( &dxfFile, encoding ) )
164 feedback->
pushInfo( QObject::tr(
"DXF export completed" ) );
181 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
FeatureSymbologyExport
Options for exporting features considering their symbology.
Represents a coordinate reference system (CRS).
Exports QGIS layers to the DXF format.
void setForce2d(bool force2d)
Force 2d output (eg.
@ DeviceNotWritableError
Device not writable error.
@ Success
Successful export.
@ EmptyExtentError
Empty extent, no extent given and no extent could be derived from layers.
@ InvalidDeviceError
Invalid device error.
ExportResult writeToFile(QIODevice *d, const QString &codec)
Export to a dxf file in the given encoding.
void setFlags(QgsDxfExport::Flags flags)
Sets the export flags.
@ FlagHairlineWidthExport
@ FlagOnlySelectedFeatures
Use only selected features for the export.
@ FlagNoMText
Export text as TEXT elements. If not set, text will be exported as MTEXT elements.
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Set destination CRS.
void addLayers(const QList< QgsDxfExport::DxfLayer > &layers)
Add layers to export.
void setSymbologyScale(double scale)
Set reference scale for output.
const QString feedbackMessage() const
Returns any feedback message produced while export to dxf file.
void setExtent(const QgsRectangle &r)
Set extent of area to export.
void setSymbologyExport(Qgis::FeatureSymbologyExport e)
Set symbology export mode.
static QStringList encodings()
Returns list of available DXF encodings.
void setMapSettings(const QgsMapSettings &settings)
Set map settings and assign layer name attributes.
void setLayerTitleAsName(bool layerTitleAsName)
Enable use of title (where set) instead of layer name, when attribute index of corresponding layer in...
Contains configuration for rendering maps.
void setScaleMethod(Qgis::ScaleCalculationMethod method)
Sets the method to use for scale calculations for the map.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the map of map layer style overrides (key: layer ID, value: style name) where a different style ...
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
bool hasMapTheme(const QString &name) const
Returns whether a map theme with a matching name exists.
QMap< QString, QString > mapThemeStyleOverrides(const QString &name)
Gets layer style overrides (for QgsMapSettings) of the visible layers for given map theme.
Contains information about the context in which a processing algorithm is executed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
A boolean parameter for processing algorithms.
A coordinate reference system parameter for processing algorithms.
A parameter for Processing algorithms that need a list of input vector layers to export as DXF file.
static QList< QgsDxfExport::DxfLayer > parameterAsLayers(const QVariant &layersVariant, QgsProcessingContext &context)
Converts a QVariant value (a QVariantList) to a list of input layers.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
A double numeric parameter for map scale values.
QgsMapThemeCollection * mapThemeCollection
Qgis::ScaleCalculationMethod scaleMethod
A rectangle specified with double values.
const QgsCoordinateReferenceSystem & crs
Layers and optional attribute index to split into multiple layers using attribute value as layer name...