GIS Tutorials >> Quantum GIS >> Beginner Quantum GIS Tutorials >> How to generate contours using point data in Quantum GIS (QGIS)

GIS Programming Tutorials

GIS Theoretical Tutorials

GISTutor Newsletter

GISTutor Poll

How did you hear about us?

GISTutor Users Online

We have 16 guests online
How to generate contours using point data in Quantum GIS (QGIS)
( 7 Votes )

This beginner QGIS tutorial explains how to generate contours using a points dataset.  The points dataset used in this tutorial was created in the first half of this two part tutorial, called ‘How to sample raster datasets using points in Quantum GIS (QGIS)’.  That tutorial explains how to create a regular grid of points and effectively sample the raster elevation values for use in the contour plugin.  


Note: This tutorial can be completed with any other point dataset as long as it has an elevation attribute column associated with the point data.




This tutorial will be built using the output of the previous tutorial.  In QGIS, open up the dem_clip.tif raster file by selecting Add Raster layer and navigating to the location where the data has been saved.  Also add the point_sampling.shp file created from the previous tutorial by selecting Add Vector layer.


Installing the QGIS Contour Plugin


Before we can generate contours using points data, we must first install the necessary python plugin for QGIS.  In QGIS select Plugins > Fetch Python Plugins.  In the filter section type the word ‘contour’, select the Contour Plugin and click the Install/upgrade plugin button.  Once the plugin has been installed, double check that it is enabled by selecting Plugins > Manage Plugins.  Again type in ‘contour’ in the filter section and ensure that a checkbox is placed next to the plugin, enabling it.  Now that it is enabled, select Plugins > Contour > Contour.


Generating Contours from Points


This QGIS Contour Plugin is only capable of generating contours using point datasets.  For the Vector layer, make sure that point_sampling has been selected.  Ensure that Data field has the dem_clip attribute column selected, because it contains the elevation data that we have sampled from the raster in the previous tutorial.  Down in the Contouring section, set the Number to 12, Min to 300 and Max to 1400.  On the right hand side of the tool you should see all the individual cutoff values for the classification that will take place.  In order to have nice rounded numbers we will have to adjust these classification values manually.  Double click the 2nd classification and enter the value of ‘400’ to enter the new level value.  Double click the 3rd classification entering the value of ‘500’ as the new level value and continue all the way up until you have classes 300 – 1400 all defined.  Lastly in the Output section at the bottom, enter ‘point_sampling_contour’ as the Layer name, click OK to generate your contours.  You will likely receive a message saying levels 300 and 1400 are not represented; this is because they fall outside the minimum and maximum values of our point_sampling dataset.  Click Close once the point_sampling_contour appears in your TOC.




Adding Symbology to Contours


To view the results of your contours make sure that dem_clip is the very bottom layer of your TOC, uncheck the point_sampling layer and place the point_sampling_contour layer as the top layer of your TOC.  You should see that the contours tend to follow the different shades of black, grey and white according to their elevation values.  To better symbolize the data, right click on point_sampling_contour and select properties.  In the symbology tab click the New Symbology button in the top right corner.  When asked if you would like to use a new symbology implementation for this layer, select yes.  In the Renderer dropdown select the Graduated option.  Set Column to use dem_clip since that relates to the elevation values.  Click on the Change symbol button and enter a line width of 2, click OK.  Select a color ramp of your choice.  Set Classes to 9 and set the Mode to use Pretty Breaks.  Note: It is important to match up the classification to the exact same levels you defined at the time of generating your contours file. Click the Classify button to generate the different classifications of your symbology.  If done correctly you should see that the classifications are going to be representing nice rounded elevation values from 400 – 1300.  Click Apply to update the colors of your contours using the new symbology.


Labeling Contours


The last effect we will add will be contour labels.  Click on the label tab in the left hand side of the properties window.  Place a checkbox next to Display Labels to enable the menu.  For Field Containing Label select dem_clip from the dropdown.  Remove the ‘Label’ from the Default Label field, leaving it blank.  Scroll down and place a checkbox next to Buffer labels make sure that a white buffer color is selected.  When you are ready click on Apply to setup the new labels and click OK to close the point_sampling_contour layer properties window.  You should now have a nice clear map which shows the vector contours with graduated color scheme and feature labels overlaid on top of the original raster elevation data.





+3 #3 john 2013-09-05 08:27
I get an error message like ;
"Exception struck: 'ascii' codec can't encode character u'\xf6' in position 0: ordinal not in range(128)"
Any ideas?
+3 #2 Andre 2013-02-01 12:54
Is it also possible to script this in Qgis? So I could make a loop in linux and use an entire dataset of GPS coordinates and transform each dataset into a contourmap?
0 #1 2012-04-04 05:38
Oh am I ready to try this! Thank You for the insight. This is exactly why I was evaluating Quantum GIS.

Add comment

Security code