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:

Supported Entities

The following entity types are supported:

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.


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. 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:

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

Character Encodings

Normally DXF files are in the ANSI_1252 / Win1252 encoding. GDAL/OGR attempts to translate this to UTF-8 when reading and back into ANSI_1252 when writing. DXF files can also have a header field ($DWGCODEPAGE) indicating the encoding of the file. In GDAL 1.8.x and earlier this was ignored but from GDAL 1.9.0 and later an attempt is made to use this to recode other code pages to UTF-8. Whether this works will depend on the code page naming and whether GDAL/OGR is built against the iconv library for character recoding.

In some cases the $DWGCODEPAGE setting in a DXF file will be wrong, or unrecognised by OGR. It could be edited manually, or the DXF_ENCODING configuration variable can be used to override what id will be used by OGR in transcoding. The value of DXF_ENCODING should be an encoding name supported by CPLRecode() (i.e. an iconv name), not a DXF $DWGCODEPAGE name. Using a DXF_ENCODING name of "UTF-8" will avoid any attempt to recode the text as it is read.

Creation Issues

DXF files are written in AutoCAD 2004 format. A standard header (everything up to the ENTITIES keyword) is written from the $GDAL_DATA/header.dxf file, and the $GDAL_DATA/trailer.dxf file is added after the entities. Only one OGR layer can be used to create the output file (but many DXF layers can be created - see below).

Only the first tool (PEN, BRUSH, etc) in the style string is read. The following style string parameters are understood:

Tool Available on geometry types Supported parameters
PENPoint, (Multi)LineStringcolor (c); width (w); dash pattern (p)
BRUSH(Multi)Polygon, Triangleforeground color (fc)
SYMBOLPointcolor (c)
LABELPointGDAL >= 2.3.0: text (t); font name (f); font size (s), treated as cap height; bold (bo); italic (it); text color (c); x and y offsets (dx, dy); angle (a); anchor point (p); stretch (w)
GDAL <= 2.2.x: text (t); font size (s), treated as cap height; text color (c); angle (a); anchor point (p)

The dataset creation supports the following dataset creation options:

Note that in GDAL 1.8 and later, the header and trailer templates can be complete DXF files. The driver will scan them and only extract the needed portions (portion before or after the ENTITIES section).

Block References

It is possible to export a "blocks" layer to DXF in addition to the "entities" layer in order to produce actual DXF BLOCKs definitions in the output file. It is also possible to write INSERT entities if a block name is provided for an entity. To make this work the following conditions apply: The intention is that a simple translation from DXF to DXF with DXF_INLINE_BLOCKS set to FALSE will approximately reproduce the original blocks and keep INSERT entities as INSERT entities rather than exploding them.

Layer Definitions

When writing entities, if populated the Layer field is used to set the written entities layer. If the layer is not already defined in the template header then a new layer definition will be introduced, copied from the definition of the default layer ("0").

Linetype Definitions

When writing linestring geometries, the following rules apply with regard to linetype (dash pattern) definitions.

The intention is that "dot dash" style patterns will be preserved when written to DXF and that specific linetypes can be predefined in the header template, and referenced using the Linetype field if desired.

It is assumed that patterns are using "g" (georeferenced) units for defining the line pattern. If not, the scaling of the DXF patterns is likely to be wrong - potentially very wrong.


GDAL writes DXF files with measurement units set to "Imperial - Inches". If you need to change the units, edit the $MEASUREMENT and $INSUNITS variables in the header template.

See also

AutoCAD 2000 DXF Reference

AutoCAD 2014 DXF Reference

DXF header reference