I have a shapefile layer of contour lines that I'd like to export to DXF, but I want to have each feature be on a layer defined by an elevation attribute. I saw here that something like this should be possible, but can't find how to do it.

I tried both "Save As" and "Project -> DXF Export," and saw no obvious option to set the DXF layers. I also tried creating an attribute called "layer" (and also tried "Layer" and "layers") to see if either export method would automatically use this attribute for the DXF layer, but got nothing.

I can get this to work using ogr2ogr, but is there a more direct way to set the DXF layers on export in QGIS? (BTW I am using QGIS 2.18.3)

3 Answers 3


For the sake of closure (and in case I need to look this up again) I'm posting how I created my DXF file with layers. This uses ogr2ogr, but I used the QGIS toolbox so I guess technically it could count as a QGIS solution.

I found here how to use the ogr2ogr -shp option to create layers in the DXF file based on attribute values in the shapefile, the basic command looks like

ogr2ogr -f DXF output.dxf input.shp -sql "SELECT ATTRIB AS Layer FROM input"

where ATTRIB is the attribute used for the layer name in the shapefile.

To do this with the QGIS toolbox, open the OGR conversions tool, select the input layer (which, by the way, needs to have the same name as the shapefile it refers to), set output to DXF, and add

-sql "SELECT ATTRIB AS Layer FROM input"

to the "Creation Options" field.

This did exactly what I was looking to do.


I know this is old but I was trying to find an answer to this. Using QGIS 3.4 I found that If you export the DXF from File>Import/Export>Export DXF you can choose the attribute to be used as layers for each GIS layer in your project by choosing the attribute from the Output Layer Attribute dropdown.


It took me a bit to figure out after getting ERROR 1, but in the command of Don (ogr2ogr -f DXF output.dxf input.shp -sql "SELECT ATTRIB AS Layer FROM input"), the last word input is the layer name the user needs to fill up, so that it matches with the input.shp, so if your shapefile is 123.shp, the command ends with 123".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.