Skip to content
TOPOLUMA

DEM to DXF: how elevation data becomes CAD contours

What a digital elevation model is, the difference between surface and terrain models, how contours are traced from a grid, and how to turn a DEM into DXF contours yourself in QGIS or in TOPOLUMA.

Updated · 8 min read

Almost every digital contour map starts as a grid of heights. Knowing how that grid is made, and what happens when it is turned into lines, tells you how far you can trust the contours in your drawing.

What a DEM is

A digital elevation model is a raster: a regular grid where each cell holds one height. Its resolution is the size of a cell on the ground. A 30 m DEM has one height for every 30 × 30 m square, so a terrace, a ditch or a retaining wall narrower than that simply is not in it.

Two kinds matter for site work:

  • DSM (digital surface model): the top of whatever is there, including roofs and tree canopies. Satellite radar models such as SRTM and Copernicus GLO-30 are surface models, although in open land they are close to the ground.
  • DTM (digital terrain model): the bare ground, with buildings and vegetation removed. National lidar surveys usually publish a DTM, often at 1 m or finer.

Copernicus GLO-30 covers all land at about 30 m, and its product specification targets an absolute vertical accuracy better than 4 m at 90% confidence. National lidar models are far more precise, but only some countries publish them openly.

From grid to lines

Contours are traced by finding where the surface crosses each chosen height. Standard algorithms (marching squares and its variants) look at each grid cell, check which corners are above and below the height, and place line segments by interpolating along the cell edges. Joining the segments gives the contour polylines.

Two consequences follow:

  • Lines between samples are estimates. With a 30 m grid, a contour is placed by linear interpolation between points 30 m apart. A finer interval adds lines, not information.
  • Coarse grids give stair-steps. Tracing a coarse grid directly produces angular, zig-zag lines. Smoothing the surface before tracing, as TOPOLUMA does, gives natural lines without moving them far from the data.

Writing the DXF

For CAD the useful form is a polyline per contour with its elevation. In DXF R12 that is a 2D polyline whose elevation is the contour height; every CAD program reads it, and terrain tools (Civil 3D surfaces, Revit toposolids, ArchiCAD meshes) can use the heights. A 3D model of the terrain is a different object: a mesh of triangular faces, which TOPOLUMA writes as DXF 3D faces, OBJ, STL or IFC.

Doing it yourself in QGIS

If you already have a DEM file (a GeoTIFF from a national portal, for example), QGIS can make the contours:

  1. Load the DEM and check its coordinate system and units in the layer properties.
  2. Run Raster → Extraction → Contour (the GDAL contour tool). Set the interval and keep the elevation attribute it writes.
  3. Optionally clip the result to your site and simplify or smooth it.
  4. Save the layer as DXF, or use Project → Import/Export → Export Project to DXF, and choose the elevation attribute so the polylines keep their heights.

This gives you full control over the source data. The cost is time: finding the right DEM, reprojecting it, and assembling buildings and roads from other sources.

Doing it in TOPOLUMA

TOPOLUMA reads elevation from Mapterhorn, which serves the best open model for each place: Copernicus GLO-30 everywhere and national models where they are open. It fills any gaps from coarser data (and tells you when it did), smooths, traces the contours at your interval and writes them to DXF with buildings, roads and water from OpenStreetMap on their own layers. The steps are in exporting contour lines to DXF.