“3D-features” with QGIS 2.8 – derive elevation from DEM and write into table ?

Yesterday I tried to reproduce one of my typical ESRI-workflows with QGIS 2.8.x – having some 2D point-features and converting these features to 3D features deriving elevation from a DEM – and at least I need the z-value in the table… a simple task, or not ?

Step 1: From 2d to 3d…

Ok, with some GIS-experience step 1 was a simple task with some nosy browsing through the processing-toolbox. For testing purposes I created a Shapefile with some points, added a DEM with the same SRS as the Shapefile. QGIS does not support such 3D-functions itself, but with the help of the GRASS-Toools in the Toolbox it can be done easily: v.drape


Without any problems a 3D-Shapefile was generated – cross checking it with ArcMap verified it.

Step 2: Getting the z-values into the table… a roundabout way 🙁

Next step should be a column in the attribute table with the z-value (height) derived from the DEM for each feature – in ArcMap no big task. I looked around in the table-calculator, no way – searching the web I realized that QGIS 2.8 does not have native 3D support (am I wrong?). A possible and pausible solution I found is exporting the 3D-Shapefile into a database like the file-based Spatialite-DB-format and doing it with Spatial-SQL-commands as Faunalia describes it.

Convert the 3D-Shapefile to Spatialite, add your Z-value column to the table (e.g. in the layer-properties or table) and use the following SQL-command in the QGIS-DatabaseManager (Database-menu – DB-Manager):

update tablename set z-value-columnname = st_z(geometry)


In my example executing the SQL-command worked without any error and fine.

Thx to David for helping with some SQL-failures and the reference of http://www.gaia-gis.it/gaia-sins/spatialite-sql-4.2.0.html

Anyone with a solution with GDAL/OGR ?

Comments welcome: https://www.facebook.com/isticktoit