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)


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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