Generating contour lines in QGIS

One of the cool things I love about QGIS is finding stuff that you didn’t know it could do, well not just itself but plugins that you didn’t know about.

Today my discovery was in how to generate contour lines from a point layer.

  1. First install the contour plugin for qgis via the plugin installer.  Just search for “contour”
  2. Once installed open a vector point layer in QGIS.  Make sure the point layer has a field that you can use for elevation.

    One I prepared earlier
  3. Then select from the menu: Plugins->Contour->Contour
  4. Fill in the information

    Details form (The above setting will generate 0.5m contours)
  5. Press OK
  6. Results

    Results from plugin
  7. Profit??

The resulting contours will have a field that contains the label and z value for each contour line, you can then just label or color them how you wish.

Note:  There is a bug with QGIS memory layers where the fields don’t  show up in dropdown or attribute browsers, a simple fix is just to make the layer editable and then non editable then the fields will be there.

The contour layer is a QGIS memory layer so remember to save it to disk eg a shapefile before you close you will loose your new fancy contour layer.

Happy mapping :)

19 thoughts on “Generating contour lines in QGIS

  1. Thanks for this interesting post.
    Unfortunately installing the contour-plugin doesnot work for me. I t says I need the module shapely.geometry. Can you please tell where I can get this module and where/how to install it??


    1. Thanks for this I have always looked for how to generate contours in qgis. I also had the issue with the shapely.geometry, and for that I used python shaply in synaptic, then I had to install the python dev again in synaptic and this did it for me. Thanks again.

      I am a Land surveyor based in Kampala Uganda, and I wanted to know how I can display segment distances automatically when I have a vector layer, as I have been entering these distances manually. Basically I create a csv layer with xy information, but i dont know how to do this automatically. Can Qgis compute the distance between two points automatically then display the distance as a label?

  2. Nathan,

    I found a solution, maybe other newbies are also interested, so here it is:

    1) download egg-package (for python 2.5 because qgis1.6 uses this version) from
    2) reame *.egg to *.zip and use your unzipper (winzip,7-zip….)
    3) extract the shapelyfolder with geometry-subfolder into the pythons site-packages folder
    4) extract the two dll-files into pythons dll folder
    If you use the OSGeo4W- Version of python your python-folder is probably at:
    5) install plugin from within qgis

    ps. Nathan is your point-file available for download??

  3. Nathan,

    I am very excited by the steps you showed using contour>contour plugin. However, when I tried to install the contour module using Plugin>Fetch Python Plugin>Contour, the contour plugin failed to install. The message says that I have not installed Tkinter. Can you help me on this? I also tried another procedure using GRASS, but its quite complicated compared to what you presented. Any other procedure you used in generating contours? Thanks a lot.


      1. I am using Windows XP. I installed QGIS v.1.6. When I installed QGIS, I just followed the link. so far it is working well except that it asked for Tinker. I reinstalled QGIS but received the same message.


    1. I think it might have something to do with the Python install that is shipped with QGIS. Are you able to download QGIS using the OSGeo4W installer ( ( and try in that version.

      I find the layout of the install from OSGeo4W to be a little better and I have had less problems with that vs the standalone windows installer.

      Tip: If you didn’t know, with the OSGeo4W installer you can get the latest dev build of QGIS (Handy to test new features). Click advanced and look for qgis-dev in the Desktop section.

      1. Hi Nathan,

        I ran the OSGeo4w ( and installed QGIS. After installing, I ran QGIS and noticed this message:

        Couldn’t load plugin linear_ref due an error when calling its initGui() method

        Traceback (most recent call last):
        File “C:/OSGeo4W/apps/qgis/./python\qgis\”, line 147, in startPlugin
        File “C:/Documents and Settings/Ed/.qgis/python/plugins\linear_ref\”, line 63, in initGui
        self.iface.addPluginToDatabaseMenu(“&Linear referencing”, self.actionConfigure)
        TypeError: ‘sip.methoddescriptor’ object is not callable

        Python version:
        2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]

        QGIS version:
        1.6.0-Copiapo Copiapo, exported

        Python path: [‘C:\\Documents and Settings\\Ed\\.qgis\\python\\plugins\\GeoCoding’, ‘C:\\Documents and Settings\\Ed\\.qgis\\python\\plugins\\elevation’, ‘C:/OSGeo4W/apps/qgis/./python’, ‘C:/Documents and Settings/Ed/.qgis/python’, ‘C:/Documents and Settings/Ed/.qgis/python/plugins’, ‘C:/OSGeo4W/apps/qgis/./python/plugins’, ‘C:\\OSGeo4W\\bin\\’, ‘C:\\OSGeo4W\\apps\\Python25\\DLLs’, ‘C:\\OSGeo4W\\apps\\Python25\\lib’, ‘C:\\OSGeo4W\\apps\\Python25\\lib\\plat-win’, ‘C:\\OSGeo4W\\apps\\Python25\\lib\\lib-tk’, ‘C:\\OSGeo4W\\apps\\qgis\\bin’, ‘C:\\OSGeo4W\\apps\\Python25’, ‘C:\\OSGeo4W\\apps\\Python25\\lib\\site-packages’, ‘C:\\OSGeo4W\\apps\\Python25\\lib\\site-packages\\win32’, ‘C:\\OSGeo4W\\apps\\Python25\\lib\\site-packages\\win32\\lib’, ‘C:\\OSGeo4W\\apps\\Python25\\lib\\site-packages\\Pythonwin’, ‘C:\\OSGeo4W\\apps\\Python25\\lib\\site-packages\\wx-2.8-msw-unicode’, ‘~/.qgis/python’, ‘C:\\Documents and Settings\\Ed\\.qgis\\python\\plugins\\fTools\\tools’, ‘C:\\Documents and Settings\\Ed\\.qgis\\python\\plugins\\imgshowhide\\logic’, ‘C:\\Documents and Settings\\Ed\\.qgis\\python\\plugins\\imgshowhide\\gui’]

        Just the same, when I fetched Python, the same error appeared: asking for Tkinter

        What do you mean by this:

        “”you can get the latest dev build of QGIS (Handy to test new features). Click advanced and look for qgis-dev in the Desktop section.””

        Thank you for your assistance.


      2. Ok try this.

        I found this:
        which says:

        1) copy the file ‘matplotlibrc’ from
        “C:\Documents and Settings\–your user name here–\.matplotlib

        2) edit the above file and change the line 31 from:
        backend : TkAgg
        backend : Qt4Agg

        3) restart QGIS and install a matplotlib-dependant plugin. It should work.
        I’ve tested with Lionel Roubeyrie’s contour plugin and could, at last,
        generate contours from shapefile points!

        Give that a try for me.

        I have no idea if it’s going to work. I don’t have a windows install at the moment.

      3. Regarding my comment ”you can get the latest dev build of QGIS (Handy to test new features). Click advanced and look for qgis-dev in the Desktop section.”

        There is a new build of QGIS every night, it might be unstable but it’s good to see if issues have been resolved. This post explains how to install the dev build using the OSGeo4W installer,

        You don’t have to install GRASS if you don’t want to, just tick “qgis-dev” you will see what I mean.

        Sorry it’s been such a pain.

  4. Hi,

    thank you for your plugin. I work with “contours” since Qgis 1.7.0. and it’s really a good plugin.

    Now I update Qgis and when I want to use it I have all the time a error message like “Exception struck: ‘module’ object has no attribute ‘tricontour'”

    I trie to update at Qgis 1.7.3 but the problem is the same. Do you know how I can fix it ?

    Thank you

  5. I urge qGIS team to make contour plotting an in-built feature of qGIS or a feature directly built into official default plug-ins of qGIS (e.g. fTools)

    Contour plugin is most useful but it is not working since qGIS 172 + Contour 0.90.

    I have updated to qGIS 172 + Contour 0.91 but still the same problem. Updated matplotlib but ran into another problem Python27.dll conflict.

  6. I have just followed Kurt’s instructions on how to deal with the missing shapely.geometry and have modified it for the qgis 1.7.4 and I thought it would have worked. But when I try and load the contour plugin I now get an error message saying this pluging is broken, Pyhton said: 193. What does this mean and is there a way I can fix this? Or do I need to report this as a bug?

    Thanks for this page, has helped a lot.


  7. hey, for me, the plugin installed correctly, but whatever options I give, ‘OK’ is not highlighted. How can I fix this?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s