Posted by & filed under QGIS.

A note from Sam in the Linfiniti team:

The last two weeks of FOSS GIS training courses (posted about here and here) have been impressive.  High-five to the trainers, Tim and Gavin, for their hard work!  Having only being at Linfiniti for a short time, I was assisting with the courses but also learning some things about the software myself.  This is just one of the nice things I learnt from the QGIS course.

Using the GRASS plugin in QGIS opens you to a whole host of new tools.  The plugin makes GRASS more accessible, and simplifies the complexity of GRASS datasets, so that more users will be able to benefit from the GRASS functionality available.

You can convert vector contour lines to a raster DEM, and then visualise the DEM in 3D. The steps below are written for newbies (like I was!), so skip the detail if you an experienced user ;)

1. Setting up your mapset and adding your data

When the GRASS plugin is enabled in QGIS, you will get a GRASS toolbar added. Open your contour shapefile in QGIS as you usually would, then click New mapset on the GRASS plugin toolbar. For those new to GRASS mapsets, here are some guidelines:

  • specify the directory (you can make a ‘grass’ folder in your home directory – it is important you have full read/write access)
  • create a new location – think of this as a project folder based on a certain location (geographical extent)
  • assign the projection of your dataset (your projection will be fixed for the location and mapset)
  • under the default GRASS region section, click the ‘Set current QGIS extent’ button
  • enter the mapset name (this will be your username – each user can have a mapset in the location, the ‘project folder’)

Once you’ve setup, you will see a red outline around the data in your QGIS view, this is your mapset extents.

Click the GRASS tools icon on the toolbar, and find the option to import your vector or raster.  Here’s the vector import:

Once you click the function, select the layer to add (the list will show those layers open in QGIS), type a name and click run.

You will also need to add the newly created grass layer to your QGIS view – this will make it accessible for subsequent grass functions.  Add the layer by clicking ‘view output’ after running the function, or in the browser tab in the GRASS tools dialog – click refresh, find the file and click the add icon.

2. Creating a DEM from contours

Now for the interesting bits.  Make sure your vector contour from your grass mapset is open.  Under the Module list in the GRASS tools dialog, find and run these functions in this order:

  • -> converts your vector to raster based on an attribute (use the height attribute from the contours).  Open your result once its run.
  • -> creates a surface from the rasterized contours.  Tip: edit your mapset region (last icon on the grass toolbar) to adjust the output area to your dataset- this will save time!  Open your result once its run.

3. Visualisation in 3D using nviz

In the modules list, find nviz. This can be used to visualise any DEM data, and you can add overlays.  Using a nice colour map as explained in Tim’s post will produce a catching effect.  Running the module, and adjusting the settings (z-exaggeration, lighting, perspective etc) will give you a dynamic 3D view of your data.  Nviz is also apparently capable of 3D fly-throughs for those interested in exploring a bit more.

Voila, and there you go!  And this was all created from the comfort of your QGIS environment, thanks to the awesome plugins that have been added! :)

Hope this helps, and if you’ve got any questions, feel free to leave a comment!


  • Pingback: Tweets that mention 3d visualisation and DEM creation in QGIS with the GRASS plugin - Linfiniti Geo Blog --

  • Pingback: GIS-Lab Blog» Архив блога » Новости вокруг 58

  • Nevena

    Hi, thank you for your work and for your nice and useful description. I did exactly what you say and I got 3d visualization of my terrain data, but I have problem to drape orthophoto image on top of that. Can you please help me to do that?

    Thank you in advance

  • samantha

    Hi Nevena

    Glad it was useful. You should be able to drape a georeferenced orthophoto image once it is imported as a GRASS layer (use import loaded raster to GRASS)? Perhaps make sure that the DEM and orthophoto are in the same projection system before you import them.

    If you still getting problems its probably best to check on the Grass forums. Or try the IRC channel and mailing list.

  • opetnaistommestu

    Hello! I have been using ArcGIS for a long time and now I am exploring QGIS and its possibilities.

    I wanted to create 3D terrain model equivalent to TIN model made in ArcScene. I googled it and found this article, tried it, but I got stuck while following the instructions (I repeat – along the years I developed a ArcGIS-ish way of thinking and now I am trying to reshape te way I do things, do forgive me if I ask silly question): when I import shp to GRASS dataset, this new layer loses all of the table data original shp had. Here’s the screenshot:

    Am I doing something wrong or should GRASS have kept the data from original shp?

    Here’s the original file in case someone wants to try to import it to GRASS dataset:


    Belgrade, Serbia

  • Gideon

    Hi Sam

    I followed your “3d visualisation and DEM creating in QGIS with Grass plugin”.

    I get stuck when I try to add the layer and get a error message when I click run.

    Unfortunately I cannot paste the message here, but basically it reads “Cannot create a table”.

    Any ideas?

    Regards Gideon

  • ibadraza


    I just wanted to know that how can we show our 3D vector data in quantumgis (like buildings and houses) not TIN or contours which are interpolated into raster.

    I wanted some work done on the 3D data so I would really appreciate some immediate help.

    waiting for your kind reply. and thank you in advance

  • nustiu

    Hello! Could please someone tell me why is it that when I set the command and I select the source of raster values to be “attribute”, in the Attributes tab, field “Name of coloum” won’t appear any columns from my dbf file? What could cause these values not to appear in the specified field?
    Thank you!

  • Gideon

    When I follow Sam’s instructions I get stuck when I want to run the function ( I am prompted with the following error message : -o “dsn=C:\Users\user1\Desktop\Wingerdbou\Lutzville GIS\Data files\Landmeter generaal 2\vector data\3118\3118_RELIEF_LINE_2007_01.shp” snap=-1 min_area=0.0001

    Required parameter not set
    Finished with error

    Also the ‘View Output’ is greyed out.
    Any ideas what I’am doing wrong.

  • Gideon

    Is this blog still active? Does someone have answers on the questions? Is Sam still with Linfinity? What is happening on this site?

  • sgsalmo

    I am using Mac OS X Lion. The tool “” is not even clickable in my machine. Please help as well.

  • samantha

    Hi there. Sorry, I am no longer working at Linfiniti, hence have not been able to attend to the questions on the blog. I suggest contacting the QGIS community ( There is a very active user mailing list where someone may be able to assist. All the best.