Driver short name

DXF

DXF is an ASCII format used for interchanging AutoCAD drawings between different software packages. OGR supports reading DXF files generated by all recent versions of AutoCAD, and writing DXF files that are compatible with AutoCAD 2004 and later.

DXF files are considered to have no georeferencing information through OGR.

By default, the entire contents of the file are represented as a single OGR layer named “entities”. Features will all have the following generic fields:

• Layer: The name of the DXF layer. The default layer is “0”.

• PaperSpace: 1 if the entity is located on a layout (paper space), NULL otherwise.

• SubClasses: Where available, a list of classes to which an entity belongs.

• ExtendedEntity (GDAL <= 2.2.x): The values of extended entity attributes all appended to form a single text field, where available.

• RawCodeValues (GDAL >= 2.3.0): Only available when the configuration option DXF_INCLUDE_RAW_CODE_VALUES is set to TRUE. A string list containing all group codes and values that are not handled by the DXF reader.

• Linetype: Where available, the line type used for this entity.

• EntityHandle: The hexadecimal entity handle. A sort of feature id.

• Text: The text of labels.

## Driver capabilities¶

Supports Create()

This driver supports the GDALDriver::Create() operation

Supports VirtualIO

This driver supports virtual I/O operations (/vsimem/, etc.)

## Supported Entities¶

The following entity types are supported:

• POINT: Produces a simple POINT geometry feature.

• MTEXT, TEXT: Produces a POINT feature with LABEL style information. The style string may include the following parameters: f s t a c w p dx dy bo it. Text positioning might not precisely match CAD software (especially the vertical alignment of MTEXT), as calculation of the exact position would require GDAL to be aware of the font metrics. By default, character escapes such as %%p are honored where applicable, and MTEXT control sequences like \Wx.xx; are stripped. To disable this behavior and retrieve the raw text values, set the configuration option DXF_TRANSLATE_ESCAPE_SEQUENCES to FALSE.

• LINE, POLYLINE, LWPOLYLINE: Translated as a LINESTRING. Rounded polylines (those with their vertices’ bulge attributes set) will be tessellated. Single-vertex polylines are translated to POINT. Polyface meshes are translated as POLYHEDRALSURFACE geometries.

• MLINE:

• (GDAL >= 2.3.0) Translated as a MULTILINESTRING. Only the geometry is reconstructed; styling applied to individual line elements within the MLINE is ignored. Fill colors and start/end caps are also omitted.

• (GDAL <= 2.2.x) No support.

• CIRCLE, ELLIPSE, ARC, SPLINE, (GDAL >= 2.3.0) HELIX: Translated as a LINESTRING, tessellating the curve into line segments. (GDAL >= 2.3.0) CIRCLEs with nonzero “thickness” (cylinders) are approximated as a POLYHEDRALSURFACE.

• INSERT: By default, the block definition referenced by the INSERT will be inserted as a compound geometry (for example, a MULTILINESTRING for a block containing many lines, or a GEOMETRYCOLLECTION for a block that contains points and lines). If the block contains TEXT or MTEXT entities, they are not merged into the compound geometry and are instead returned as separate features.

Three configuration options are available to control the behavior of INSERT entities:

• DXF_MERGE_BLOCK_GEOMETRIES: To avoid merging blocks into a compound geometry the DXF_MERGE_BLOCK_GEOMETRIES config option may be set to FALSE. Use this option if you need to preserve the styling (such as colors) of individual linework entities within the block.

• DXF_INLINE_BLOCKS: See below.

• (GDAL >= 2.3.0) DXF_FEATURE_LIMIT_PER_BLOCK: Maximum number of features inserted from a single block. Set to -1 for no limit. Defaults to 10000.

• ATTDEF, ATTRIB:

• (GDAL >= 2.3.0) Attributes (ATTRIB) are treated as TEXT entities, and attribute definitions (ATTDEF) inside blocks are ignored. The behavior is different when DXF_INLINE_BLOCKS is false (see below).

• (GDAL <= 2.2.x) ATTDEF entities are treated as TEXT. ATTRIB entities are not supported.

• HATCH: Line and arc boundaries are collected as a polygon geometry, but no effort is currently made to represent the fill style of HATCH entities.

(GDAL >= 2.3.0) The DXF_HATCH_TOLERANCE config option determines the tolerance used when looking for the next component to add to the hatch boundary.

(GDAL <= 2.2.x) Only line and polyline boundary paths are translated correctly.

• 3DFACE, SOLID, (GDAL >= 2.3.0) TRACE: Translated as POLYGON, except for SOLID and TRACE entities with only one distinct vertex (translated as POINT) or two distinct vertices (translated as LINESTRING).

• DIMENSION:

• (GDAL >= 2.3.0) The DXF format allows each DIMENSION entity to reference an “anonymous” block (a block whose name starts with *D) that contains the geometry of the DIMENSION. If present, this anonymous block will be inlined at the required position. Otherwise, fallback will occur to a simple DIMENSION renderer that explodes a linear dimension as a MULTILINESTRING feature. Arrowheads, if present, are translated as one or more additional features. The fallback renderer will render nonlinear dimensions as if they were linear.

• (GDAL <= 2.2.x) Dimensions are translated as a MULTILINESTRING and a POINT for the text.

• (GDAL >= 2.3.0) The leader line is translated as a LINESTRING (LEADER) or MULTILINESTRING (MULTILEADER). Arrowheads, if present, are translated as one or more additional features. Text for MULTILEADER entities is translated into a POINT feature with a label. Block content for MULTILEADERS is treated as for INSERT. Spline leaders are tessellated into line segments.

• (GDAL <= 2.2.x) No support.

• 3DSOLID, REGION, SURFACE: See below.

A reasonable attempt is made to preserve color, line width (lineweight), line type, text size and orientation via OGR feature styling information when translating entities. Currently no effort is made to preserve complex line types (those that include text or shapes) or HATCH fill styles.

The approximation of arcs, ellipses, circles and rounded polylines as linestrings is done by splitting the arcs into subarcs of no more than a threshold angle. This angle is the OGR_ARC_STEPSIZE. This defaults to four degrees, but may be overridden by setting the configuration variable OGR_ARC_STEPSIZE. For splines, the interpolated polyline contains eight vertices for each control point.

Object coordinate systems (OCS), also known as “extrusions”, are supported for all entities to which they apply as per the DXF specification, except DIMENSION, LEADER and MULTILEADER. These three entity types also currently lack support for elevations; the geometries will always be 2D.

## DXF_INLINE_BLOCKS¶

The default behavior is for INSERT entities to be exploded with the geometry of the BLOCK they reference. However, if the DXF_INLINE_BLOCKS configuration option is set to the value FALSE, then the behavior is different as described here.

• A new layer will be available called “blocks”. It will contain one or more features for each BLOCK defined in the file. In addition to the usual fields, they will also have a Block field indicating what block they are part of. (Note, in GDAL 2.2.x and earlier this field was called BlockName.)

• (GDAL >= 2.3.0) ATTDEF entities in the blocks layer will have an AttributeTag field, giving the tag of the ATTDEF entity.

• The entities layer will have several new fields:

• BlockName: The name of the referenced block.

• BlockScale: The X, Y, and Z scale factors.

• BlockAngle: The angle of the block in degrees.

• BlockOCSNormal (GDAL >= 2.3.0): The unit normal vector of the object coordinate system (OCS) of the INSERT entity.

• BlockOCSCoords (GDAL >= 2.3.0): The OCS coordinates of the insertion point.

• BlockAttributes (GDAL >= 2.3.0): The text content of attributes associated with this block. Each entry in this string list contains an attribute tag, followed by a space, followed by the text for that attribute (which may be empty).

• INSERT entities will populate these new fields with the corresponding information (they are null for all other entities).

• INSERT entities will not have block geometry inlined - instead they will have a POINT geometry for the insertion point.

The intention is that with DXF_INLINE_BLOCKS disabled, the block references will remain as references and the original block definitions will be available via the blocks layer. On export this configuration will result in the creation of similar blocks.

## 3D Extensibility¶

DXF files may contain 3DSOLID, REGION and SURFACE entities, which contain 3D modelling data in the undocumented Autodesk ShapeModeler (ASM) format. GDAL cannot transform these entities into OGR geometries, so they are skipped by default.

Starting from GDAL 2.3.0, the DXF_3D_EXTENSIBLE_MODE configuration option may be set to TRUE to include these entities with the raw ASM data stored in a field. This option will add two new fields:

• ASMData: A binary field that contains the ASM data.

• ASMTransform: A list of 12 real values indicating the affine transformation to be applied to the entity.

This feature only works for DXF files in AutoCAD 2013 (AC1027) format and later.