Does anyone know if it's possible to create a 3D dxf with OGR? I would like to assign the contour lines a Z value and then export them to dxf for some cad work.

PS. I know FME can do this, however I would like to try and find a free solution, and if possible do it in QGIS.

  • Autocad map3d does this easily. – Brad Nesom Feb 7 '11 at 14:43
  • 2
    Yeah but Autocad map isn't really free – Nathan W Feb 7 '11 at 22:13

Easier then I thought (thanks to BenjaminGolder for the tip):

ogr2ogr -f "DXF" Contours.dxf Contours.TAB -zfield Height

Contours.TAB is the input MapInfo tab file.

| improve this answer | |
  • 1
    As far as I can tell this will work for contour lines, but not for true 3d-lines, which have a (x,y,z) coordinate for every point, and not one z value for every point of the line – johanvdw Sep 28 '11 at 14:12
  • I have been trying this in FWTools (2.4.7) without any luck. Has anyone had any luck? I am not sure if I am missing something in my GDAL? – Ryan Garnett Jul 5 '12 at 12:25

For the sake of completeness.

I believe this should be a comment on Regan response. But since I don't have enough reputation I'll leave it as a response.

The DXF writer supports 2.5D layers, and given a line input, should output a 3D linestring on dxf.

In the case of input POLYGONS you have to be more careful, since the driver defaults to generate a dxf HATCH with a Polyline. And by format specification, that line does not support Z coordinates, only X,Y.

If you input polygons, ogr can export dxf with 3D linestrings representing those polygons. For that you need to set up the config option DXF_WRITE_HATCH to NO.

ogr2ogr -f "DXF" Contours.dxf Contours.TAB

ogr2ogr -f "DXF" Contours.dxf Contours.TAB

As far as I am aware this is not documented nor explained anywhere, it was added on revision 24991

| improve this answer | |

I've never tried it, but it should be possible. The source code for the DXF driver writes Z values to dxf if the geometry is 2.5D, which (according to the source for the shapefile reader) is what you will have if the input shape has Z values.

| improve this answer | |
  • That sounds good. Next question, how do you create a shapefile with Z values. Say I have a column called Height, is there a easy way to make this the Z value. – Nathan W Feb 9 '11 at 0:08
  • Provided the shapefile is Z-aware, with ArcGIS, you can use a code block in the field calculator. I don't know how you would do it in Qgis. – Regan Sarwas Feb 9 '11 at 0:46
  • 1
    in the ogr2ogr documentation, it appears that you can create a 3d shapefile using the -zfield argument and then specifying a field name that holds z values. gdal.org/ogr2ogr.html – BenjaminGolder Mar 25 '11 at 1:20
  • @BenjaminGolder That sounds good. I will give it a go. – Nathan W Apr 14 '11 at 7:14

Did you try in GRASS the v.out.dxf command? http://grass.osgeo.org/grass64/manuals/html64_user/v.out.dxf.html

| improve this answer | |
  • I haven't tried it yet, I will give it a go. I was hoping for a QGIS option also but I could make a script to automate it in GRASS to make it easier to do. – Nathan W Feb 9 '11 at 0:05

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.