QGIS Export: Set DXF Layers By Attribute

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.

Tags:

Dxf

Qgis