[GIS] How to export elevated contours to a DXF file in QGIS

dxfqgis

Having tried Project -> Export DXF as well as right clicking my vector layer and using the save by dxf feature I have found that the contours do not show in AutoCAD to be elevated from 0

I have checked the attributes of the contours vector layer and find and attribute set containing ID,ELEV and going further I have tried the command:

ogr2ogr -f "DXF" contours-out.dxf contours.shp -zfield ELEV

which I have run successfully although I found that I had to download some version of gdal tools and add the path to my system to the various gdal subfolders I am finding that still the contours do not elevate from 0 and all are still drawn to a 0 elevation in AutoCAD.

  • I also received at some point an error in my console about the creation of an additional attribute ID which is not supported reported by the ogr2ogr command.

Is there a way to export contours to DXF with elevations?

Before I posted this question I read:
Exporting QGIS contour attributes in DXF file?
and a few others like it.

Best Answer

If your original data set is in 2D then you have to add -dim 3. Try this command:

ogr2ogr -dim 3 -zfield ELEV -f DXF contours-out.dxf contours.shp

The warning about attribute creation is no problem, DXF files cannot store attributes in a GIS way.

You can use ogrinfo to check the dimension of the output entities, e.g:

ogrinfo -al contours-out.dxf

Be careful using LibreCAD to view DXF, it is restricted to 2D!