Class: QgsDxfExport

class qgis.core.QgsDxfExport

Bases: sip.wrapper

Constructor for QgsDxfExport.

Enums

ExportResult

Bases: enum.IntEnum

HAlign

Bases: enum.IntEnum

VAlign

Bases: enum.IntEnum

Methods

addLayers

Add layers to export

clipValueToMapUnitScale

Clips value to scale minimum/maximum

closestColorMatch

Gets DXF palette index of nearest entry for given color

destinationCrs

Returns the destination CRS, or an invalid CRS if no reprojection will be done.

dxfEncoding

Returns DXF encoding for Qt encoding

dxfLayerName

Returns cleaned layer name for use in DXF

encodings

Returns list of available DXF encodings

extent

Gets extent of area to export

flags

Returns the export flags.

force2d

Retrieve whether the output should be forced to 2d

layerName

Gets layer name for feature

layerTitleAsName

Retrieve whether layer title (where set) instead of name shall be use

mapUnitScaleFactor

Returns scale factor for conversion to map units

mapUnits

Retrieve map units

registerDxfLayer

Register name of layer for feature

setDestinationCrs

Set destination CRS

setExtent

Set extent of area to export

setFlags

Sets the export flags.

setForce2d

Force 2d output (eg.

setLayerTitleAsName

Enable use of title (where set) instead of layer name, when attribute index of corresponding layer index is -1

setMapSettings

Set map settings and assign layer name attributes

setSymbologyExport

Set symbology export mode

setSymbologyScale

Set reference scale for output.

symbologyExport

Gets symbology export mode

symbologyScale

Returns the reference scale for output.

writeCircleV2

Write circle (as polyline)

writeDouble

Write a floating point value

writeFillCircleV2

Write filled circle (as hatch)

writeGroup

Write a group code with a string value

writeGroupCode

Write a group code

writeGroupDouble

Write a group code with a floating point value

writeGroupInt

Write a tuple of group code and integer value

writeGroupPointV2

Write a group code with a point

writeHandle

Write a tuple of group code and a handle

writeInt

Write an integer value

writeLine

Write line (as a polyline)

writeMText

Write mtext (MTEXT)

writePointV2

Write point

writeString

Write a string value

writeTextV2

Write text (TEXT)

writeToFile

param d

Attributes

FeatureSymbology

FlagNoMText

NoSymbology

SymbolLayerSymbology

class DxfLayer(vl: QgsVectorLayer, layerOutputAttributeIndex: int = -1)

Bases: sip.wrapper

QgsDxfExport.DxfLayer(QgsDxfExport.DxfLayer)

Parameters
layer(self) → QgsVectorLayer

Returns the layer

Return type

QgsVectorLayer

layerOutputAttributeIndex(self) → int

Returns the attribute index used to split into multiple layers. The attribute value is used for layer names.

Return type

int

splitLayerAttribute(self) → str

If the split layer attribute is set, the vector layer will be split into several dxf layers, one per each unique value.

New in version 3.12.

Return type

str

class ExportResult

Bases: enum.IntEnum

The result of an export as dxf operation

New in version 3.10.1.

  • Success: Successful export

  • InvalidDeviceError: Invalid device error

  • DeviceNotWritableError: Device not writable error

  • EmptyExtentError: Empty extent, no extent given and no extent could be derived from layers

DeviceNotWritableError = 2
EmptyExtentError = 3
InvalidDeviceError = 1
Success = 0
FeatureSymbology = 1
class Flag

Bases: int

FlagNoMText = 2
class Flags

Bases: sip.wrapper

QgsDxfExport.Flags(Union[QgsDxfExport.Flags, QgsDxfExport.Flag]) QgsDxfExport.Flags(QgsDxfExport.Flags)

class HAlign

Bases: enum.IntEnum

Horizontal alignments.

  • HLeft: Left (0)

  • HCenter: Centered (1)

  • HRight: Right (2)

  • HAligned: Aligned = (3) (if VAlign==0)

  • HMiddle: Middle = (4) (if VAlign==0)

  • HFit: Fit into point = (5) (if VAlign==0)

  • Undefined: Undefined

HAligned = 3
HCenter = 1
HFit = 5
HLeft = 0
HMiddle = 4
HRight = 2
Undefined = 9999
NoSymbology = 0
SymbolLayerSymbology = 2
class SymbologyExport

Bases: int

class VAlign

Bases: enum.IntEnum

Vertical alignments.

  • VBaseLine: Top (0)

  • VBottom: Bottom (1)

  • VMiddle: Middle (2)

  • VTop: Top (3)

  • Undefined: Undefined

Undefined = 9999
VBaseLine = 0
VBottom = 1
VMiddle = 2
VTop = 3
addLayers(self, layers: Iterable[QgsDxfExport.DxfLayer])

Add layers to export

Parameters

layers (Iterable[QgsDxfExport.DxfLayer]) – list of layers and corresponding attribute indexes that determine the layer name (-1 for original layer name or title)

clipValueToMapUnitScale(self, scale: QgsMapUnitScale, pixelToMMFactor: float) → float

Clips value to scale minimum/maximum

Parameters
  • value – the value to clip

  • scale (QgsMapUnitScale) – the scale dependent minimum/maximum values

  • pixelToMMFactor (float) – pixels per mm

Return type

float

closestColorMatch(color: int) → int

Gets DXF palette index of nearest entry for given color

Parameters

color (int) –

Return type

int

destinationCrs(self) → QgsCoordinateReferenceSystem

Returns the destination CRS, or an invalid CRS if no reprojection will be done.

New in version 3.0.

Return type

QgsCoordinateReferenceSystem

dxfEncoding(name: str) → str

Returns DXF encoding for Qt encoding

Parameters

name (str) –

Return type

str

dxfLayerName(name: str) → str

Returns cleaned layer name for use in DXF

Parameters

name (str) –

Return type

str

encodings() → List[str]

Returns list of available DXF encodings

Return type

List[str]

extent(self) → QgsRectangle

Gets extent of area to export

Return type

QgsRectangle

Returns

area to export

See also

setExtent()

flags(self) → QgsDxfExport.Flags

Returns the export flags.

See also

setFlags()

New in version 3.0.

Return type

QgsDxfExport.Flags

force2d(self) → bool

Retrieve whether the output should be forced to 2d

Return type

bool

Returns

flag

See also

setForce2d()

layerName(self, id: str, f: QgsFeature) → str

Gets layer name for feature

Parameters
  • id (str) – layer id of layer

  • f (QgsFeature) – feature of layer

Returns

layer name for feature

layerName(self, vl: QgsVectorLayer) -> str Gets name for layer respecting the use layer title as layer name mode

Parameters

vl – the vector layer

Return type

str

Returns

name of layer

layerTitleAsName(self) → bool

Retrieve whether layer title (where set) instead of name shall be use

Return type

bool

Returns

flag

mapUnitScaleFactor(scale: float, symbolUnits: QgsUnitTypes.RenderUnit, mapUnits: QgsUnitTypes.DistanceUnit, mapUnitsPerPixel: float = 1) → float

Returns scale factor for conversion to map units

Parameters
Return type

float

mapUnits(self) → QgsUnitTypes.DistanceUnit

Retrieve map units

Return type

QgsUnitTypes.DistanceUnit

Returns

unit

registerDxfLayer(self, layerId: str, fid: int, layer: str)

Register name of layer for feature

Parameters
  • layerId (str) – id of layer

  • fid (int) – id of feature

  • layer (str) – dxf layer of feature

setDestinationCrs(self, crs: QgsCoordinateReferenceSystem)

Set destination CRS

See also

destinationCrs()

New in version 3.0.

Parameters

crs (QgsCoordinateReferenceSystem) –

setExtent(self, r: QgsRectangle)

Set extent of area to export

Parameters

r (QgsRectangle) – area to export

setFlags(self, flags: Union[QgsDxfExport.Flags, QgsDxfExport.Flag])

Sets the export flags.

See also

flags()

New in version 3.0.

Parameters

flags (Union[QgsDxfExport.Flags) –

setForce2d(self, force2d: bool)

Force 2d output (eg. to support linewidth in polylines)

Parameters

force2d (bool) – flag

See also

force2d()

setLayerTitleAsName(self, layerTitleAsName: bool)

Enable use of title (where set) instead of layer name, when attribute index of corresponding layer index is -1

Parameters

layerTitleAsName (bool) – flag

See also

addLayers()

setMapSettings(self, settings: QgsMapSettings)

Set map settings and assign layer name attributes

Parameters

settings (QgsMapSettings) – map settings to apply

setSymbologyExport(self, e: QgsDxfExport.SymbologyExport)

Set symbology export mode

Parameters

e (QgsDxfExport.SymbologyExport) – the mode

setSymbologyScale(self, scale: float)

Set reference scale for output. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

See also

symbologyScale()

New in version 3.0.

Parameters

scale (float) –

symbologyExport(self) → QgsDxfExport.SymbologyExport

Gets symbology export mode

Return type

QgsDxfExport.SymbologyExport

Returns

mode

symbologyScale(self) → float

Returns the reference scale for output. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

New in version 3.0.

Return type

float

writeCircleV2(self, layer: str, color: Union[QColor, Qt.GlobalColor, QGradient], pt: QgsPoint, radius: float, lineStyleName: str, width: float)

Write circle (as polyline)

Note

available in Python bindings as writeCircleV2

New in version 2.15.

Parameters
  • layer (str) –

  • color (Union[QColor) –

  • pt (QgsPoint) –

  • radius (float) –

  • lineStyleName (str) –

  • width (float) –

writeDouble(self, d: float)

Write a floating point value

Parameters

d (float) – floating point value

writeFillCircleV2(self, layer: str, color: Union[QColor, Qt.GlobalColor, QGradient], pt: QgsPoint, radius: float)

Write filled circle (as hatch)

Note

available in Python bindings as writePointV2

New in version 2.15.

Parameters
  • layer (str) –

  • color (Union[QColor) –

  • pt (QgsPoint) –

  • radius (float) –

writeGroup(self, code: int, s: str)

Write a group code with a string value

Parameters
  • code (int) – group code

  • s (str) – string value

writeGroup(self, color: Union[QColor, Qt.GlobalColor, QGradient], exactMatch: int = 62, rgbCode: int = 420, transparencyCode: int = 440) Write a group code with color value

Parameters
  • color – color

  • exactMatch – group code to use if the color has an exact match in the dxf palette

  • rgbCode – group code to use if the color doesn’t have an exact match or has a transparency component

  • transparencyCode – group code to use for transparency component

Note

available in Python bindings as writeGroupPoint

writeGroupCode(self, code: int)

Write a group code

Parameters

code (int) – group code value

writeGroupDouble(self, code: int, d: float)

Write a group code with a floating point value

Parameters
  • code (int) – group code

  • d (float) – floating point value

Note

available in Python bindings as writeGroupDouble

writeGroupInt(self, code: int, i: int)

Write a tuple of group code and integer value

Parameters
  • code (int) – group code

  • i (int) – integer value

Note

available in Python bindings as writeGroupInt

writeGroupPointV2(self, code: int, p: QgsPoint)

Write a group code with a point

Parameters
  • code (int) – group code

  • p (QgsPoint) – point value

Note

available in Python bindings as writeGroupPointV2

New in version 2.15.

writeHandle(self, code: int = 5, handle: int = 0) → int

Write a tuple of group code and a handle

Parameters
  • code (int = 5) – group code to use

  • handle (int = 0) – handle to use (0 generates a new handle)

Return type

int

Returns

the used handle

writeInt(self, i: int)

Write an integer value

Parameters

i (int) – integer value

writeLine(self, pt1: QgsPoint, pt2: QgsPoint, layer: str, lineStyleName: str, color: Union[QColor, Qt.GlobalColor, QGradient], width: float = -1)

Write line (as a polyline)

New in version 2.15.

Parameters
  • pt1 (QgsPoint) –

  • pt2 (QgsPoint) –

  • layer (str) –

  • lineStyleName (str) –

  • color (Union[QColor) –

  • width (float = -1) –

writeMText(self, layer: str, text: str, pt: QgsPoint, width: float, angle: float, color: Union[QColor, Qt.GlobalColor, QGradient])

Write mtext (MTEXT)

Note

available in Python bindings as writeMTextV2

New in version 2.15.

Parameters
  • layer (str) –

  • text (str) –

  • pt (QgsPoint) –

  • width (float) –

  • angle (float) –

  • color (Union[QColor) –

writePointV2(self, layer: str, color: Union[QColor, Qt.GlobalColor, QGradient], pt: QgsPoint)

Write point

Note

available in Python bindings as writePointV2

New in version 2.15.

Parameters
  • layer (str) –

  • color (Union[QColor) –

  • pt (QgsPoint) –

writeString(self, s: str)

Write a string value

Parameters

s (str) – string value

writeTextV2(self, layer: str, text: str, pt: QgsPoint, size: float, angle: float, color: Union[QColor, Qt.GlobalColor, QGradient], hali: QgsDxfExport.HAlign = QgsDxfExport.HAlign.Undefined, vali: QgsDxfExport.VAlign = QgsDxfExport.VAlign.Undefined)

Write text (TEXT)

Note

available in Python bindings as writeTextV2

New in version 2.15.

Parameters
  • layer (str) –

  • text (str) –

  • pt (QgsPoint) –

  • size (float) –

  • angle (float) –

  • color (Union[QColor) –

  • hali (QgsDxfExport.HAlign = QgsDxfExport.HAlign.Undefined) –

  • vali (QgsDxfExport.VAlign = QgsDxfExport.VAlign.Undefined) –

writeToFile(self, d: QIODevice, codec: str) → QgsDxfExport.ExportResult
Parameters
  • d (QIODevice) –

  • codec (str) –

Return type

QgsDxfExport.ExportResult