QGIS 3 Exporting Contours to .DXF with 3D Elevation

4,300 views
Skip to first unread message

Thomas Grant MacDonald

unread,
Apr 8, 2019, 6:22:17 PM4/8/19
to QGIS Australia User Group
Hi guys, I'm a landscape architect learning to use QGIS, and I can't seem to figure out how to maintain the elevation data when exporting contours from QGIS 3 to a .DXF file (for importing into AutoCAD/Rhino).  One YouTube video suggests using the GRASS plugin for this, but apparently the QGIS 3 does not support this plug in.

Can anyone help me me out?  Cheers!
Tom

Callum McClure

unread,
Apr 8, 2019, 7:06:42 PM4/8/19
to australian-qg...@googlegroups.com
Are you sure your contours are 3d to begin with? Use Set Z Value to translate 2d contours with 3d by selection Z value = the contour elevation attribute.
I would also use DWG rather than DXF as a transfer data format. I known FME squashes DXF contours to 2d + attribute to save memory, where as DWG maintains full 3d.


--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.
To post to this group, send email to australian-qg...@googlegroups.com.
Visit this group at https://groups.google.com/group/australian-qgis-user-group.
To view this discussion on the web, visit https://groups.google.com/d/msgid/australian-qgis-user-group/51eca04f-55ae-42ad-a702-972d7f02a306%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Grant MacDonald

unread,
Apr 8, 2019, 9:30:09 PM4/8/19
to QGIS Australia User Group
Hi Callum, thanks for the response.  What I mean by 3D is that they have an elevation attribute and can be categorized in QGIS 3.

I tried importing the DFX into AutoCAD, but it looks very strange.  It seems that every point has "exploded" (refer attached image).  Perhaps this is an AutoCAD display style issue - I am in the process of re-familiarizing myself with AutoCAD after several years of using Rhino and Vectorworks.

How do I go about exporting my QGIS 3 clipped contour layer as a DWG?  I only see an option for DXF...
Capture 1.PNG
Capture 2.PNG
Capture 3.PNG

Juan Fernando Berrío

unread,
Apr 8, 2019, 11:23:53 PM4/8/19
to australian-qg...@googlegroups.com
Hello Thomas,

If the OSGeo4W Shell window was installed in your PC with QGIS, you may be able to use ogr2ogr.  The procedure is described in these webpages:


Using ogr2ogr for *.shp to *.dxf conversion

How to use ogr2ogr


Hope it helps,
Juan



--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.
To post to this group, send email to australian-qg...@googlegroups.com.
Visit this group at https://groups.google.com/group/australian-qgis-user-group.

Thomas Grant MacDonald

unread,
Apr 9, 2019, 11:53:35 PM4/9/19
to QGIS Australia User Group
Thanks Juan and Callum, it seems I have succeeded.

For anyone who is extremely green (like me), here are the baby steps I used to export the elevation shapefile from QGIS 3 to a .DXF on my desktop, which I could then bring into Rhino as 3D contours.  This process has been described elsewhere (like here) but I will state it in this thread anyways.  Note that I'm running Windows 10 64-bit on a 2012 Mac using Bootcamp.


1. in QGIS, right-click the elevation layer and choose Open Attribute Table.  Note the title of the column containing elevation data (in my case it was ELEV)
2. navigate to the file location of the elevation shapefile and make sure that it possesses an associated .TAB file
3. open OSGeo4Shell (just type it into the Windows start bar.  It should have been installed automatically with QGIS 3)
4. copy and paste the following into the OSGeo4Shell command line:

ogr2ogr -f "DXF" {outFile} {inFile} -zfield {ColumnWithZValue}

5. replace {outFile} with your chosen output folder address and file name, replace {inFile} with the name and location of the .TAB file described in step 2, and replace {ColumnWithZValue} with the title noted in step 1.  For me, this ended up as:

ogr2ogr -f "DXF" C:\Users\Tom\Desktop\3Dcontours.dxf C:\Users\Tom\Desktop\contour_test\Contours_1m_ProjectArea-01.tab -zfield ELEV

6. hit enter to run the  OSGeo4Shell

When I executed this I received the errors below, however it still produced a .DXF that worked perfectly when imported into Rhino.

ERROR 1: DXF layer does not support arbitrary field creation, field 'fid' not created.
ERROR 1: DXF layer does not support arbitrary field creation, field 'FTYPE' not created.
ERROR 1: DXF layer does not support arbitrary field creation, field 'ELEV' not created.


Cheers,
Tom




On Tuesday, April 9, 2019 at 1:23:53 PM UTC+10, Juan Fernando Berrío wrote:
Hello Thomas,

If the OSGeo4W Shell window was installed in your PC with QGIS, you may be able to use ogr2ogr.  The procedure is described in these webpages:


Using ogr2ogr for *.shp to *.dxf conversion

How to use ogr2ogr


Hope it helps,
Juan



On Tue, Apr 9, 2019 at 11:30 AM Thomas Grant MacDonald <tmacd...@gmail.com> wrote:
Hi Callum, thanks for the response.  What I mean by 3D is that they have an elevation attribute and can be categorized in QGIS 3.

I tried importing the DFX into AutoCAD, but it looks very strange.  It seems that every point has "exploded" (refer attached image).  Perhaps this is an AutoCAD display style issue - I am in the process of re-familiarizing myself with AutoCAD after several years of using Rhino and Vectorworks.

How do I go about exporting my QGIS 3 clipped contour layer as a DWG?  I only see an option for DXF...

--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-user-group+unsub...@googlegroups.com.

Juan Fernando Berrío

unread,
Apr 10, 2019, 12:07:00 AM4/10/19
to australian-qg...@googlegroups.com
Thanks for sharing!

To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.

To post to this group, send email to australian-qg...@googlegroups.com.
Visit this group at https://groups.google.com/group/australian-qgis-user-group.

Thomas Grant MacDonald

unread,
Apr 10, 2019, 2:27:53 AM4/10/19
to QGIS Australia User Group
No problem!

I should also mention that you can export a .TAB file by simply selecting the layer in QGIS 3 and choosing Export > Save Features As...  You'll then get an export pop-up dialogue box, and in the pull-down menu choose Mapinfo TAB.  If you want to maintain the symbology when you import into Rhino (i.e. maintain the contour 'colors' as displayed in QGIS) then also select "feature symbology" from the Symbology field.  I left all of other fields the as is.

I'll also note that I seem to run into trouble when executing the OSGeo4Shell command if the names contain spaces (i.e., you should use ProjectArea_Contours1m.TAB/.dxf instead of Project Area-Contours 1m.TAB/dxf.)


Cheers,
Tom
Thanks for sharing!

To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-user-group+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-user-group+unsub...@googlegroups.com.

Michael Dufty

unread,
Apr 12, 2019, 2:39:34 AM4/12/19
to QGIS Australia User Group
I don't think it needs to be that complicated. It can be done directly in QGIS through the GUI.

The issue is probably what Callum said. 
Contours created in QGIS have the z value or elevation as an attribute in the data table, rather than genuine 3d Geometry.
Dxf files need the z value in the actual geometry.
QGIS is quite capable of doing this in recent versions.

To make it work you need to use the processing toolbox (processing menu).
Under the Vector Geometry toolset is one called "Set Z value"
You need to run this, In the input window next to Z value, choose the box to the right, click on the line under attribute field, and choose the field that has your z values in it.
You can then either run as is, which will create a temporary layer you can then export to dxf, or click the ... next to z added which will allow you to export it directly as a dxf file.

Ernest Dunwoody

unread,
Apr 12, 2019, 4:49:38 AM4/12/19
to australian-qg...@googlegroups.com
Very helpful.
Ernest

--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.

To post to this group, send email to australian-qg...@googlegroups.com.
Visit this group at https://groups.google.com/group/australian-qgis-user-group.

Callum McClure

unread,
Apr 14, 2019, 9:37:42 PM4/14/19
to QGIS Australia User Group
Just to confirm another issue i have seen in the past (using FME). Even though your contours are 3d, when exported to DXF some transformers can translated to 2.5D in the unique case of contours, where all elevation are the same for the one element. This elevation storage allows for the DXF to be smaller in size as the elevation is just a attribute. The assumption is that your DXF reader recognises that data as 3D, which isn't always the case, even for Autodesk products.
I'm not sure if this is a issue with QGIS export, just keep an eye on it.
I think i still have emotional scares from trying to identify this issue in the pass.
Glad OP was able complete the task. 
Reply all
Reply to author
Forward
0 new messages