# Contour plugin help

This plugin generates contours for data values at points in a point vector layer. The contour are created in a new layer that can be either a line layer, for contour lines, or a polygon layer, for filled contours. The plugin uses contouring algorithms from the matplotlib library and can contour either gridded or randomly located data. For non-gridded data the contouring is based on a Delauney triangulation of the data points. .

The plugin requires the python libraries numpy and matplotlib python libaries to be installed.

The contouring function can be used either from a dialog box in which settings are entered interactively, or from a processing module. The processing module can be built into user's processing scripts, or called from python scripts.

## Using the contour dialog

The contour dialog is accessed from the contour button installed into the QGIS vector menu or on the contour menu bar.

The dialog is organised into three sections

- Input - selecting the data to contour
- Contouring - calculating the values at which to create contours
- Output - setting attributes of the output contour layer

The contour layer is generated using the Add button. Once all the required contour layers have been built the Close button is used to close the dialog box.

If a generated contour layer is the active layer when the dialog is opened then the original settings will be reloaded so that the settings can be edited if necessary and the layer regenerated.

### Input data selection

The data to be contoured are selected by picking a vector layer of point features and a numeric data value at each point. The data value can be either the value of an attribute of the layer value, or an expression calculated from field values.

The data set can be restricted to just a selected subset of the layer if required. The points to be used must be selected before opening the contour dialog.

The contouring plugin can use two different methods for contouring. Gridded data can be contoured more efficiently than irregular data, so once the data has been selected the plugin checks to see if it is organised as a grid, and if so uses grid based contouring by default. However this can be overridden by the user if required. Otherwise the contouring is derive by first building a Delauney triangulation across the data points, and then contouring across each triangle.

If the data set contains colocated points or points very close together then the triangulation algorithm may fail to run. In this case there is an option to remove duplicate points. Note that this uses a very simplistic algorithm, simply discarding points that are near to other points, so some information may be lost if this option is selected. Duplicate points are identified by specifying a tolerance such that if a group of points are closer together than this distance then all but one will be discarded. Setting the value to zero means that no points are discarded. The tolerance is in metres.

The input box is used to select the data to be contoured. This requires choosing the map layer containing the data (only point layers are available), and the data field of the layer containing the values to be contoured.

### Contouring - contour type and levels

Contours can be represented either as line features along the contour levels, or as filled polygon features defining the area between each contour level and the next, or as layer polygons defining the area above the contour level. As a convenience contour lines and filled polygons can be generated at the same time.

#### Method

The method defines how the contour levels are calculated. Each method may use a number of the parameters interval, number, minimum, and maximum.

The methods available are:

- N equal intervals: chooses equally spaced levels beteen the minimum and maximum vlaues. The number of intervals is specified in the number column.
- N quantiles: uses the distribution of data values between the minimum and maximum values to select quantiles, so that there are approximately equal numbers of data points in each contour interval.
- Logarithmic intervals: Creates up to a maximum number of logarithmically spaced values. These will be 1, 2, and 5 times powers of ten. If the data spans more than the maximum number of values then the values actually used will depend on whether a minimum or maximum values is explicitly set
- Fixed contour intervals: The contours will be calculated as multiples of the contour interval.
- User selected contour levels: The contour levels are entered manually

#### Parameters

The parameters that can be set depend on the contouring method. The parameters that can be selected are:

- Interval: the interval between contours used in the fixed contour intervals method
- Number: the number of intervals or quantiles to calulate, or for the logarithmic method and fixed contour interval methods the maximum number of contour levels to calculate
- Minimum and Maximum: if set override the default values for the minimum and maximum contour levels, which are based on the minimum and maximum data values.

#### Entering user selected contours

If the user selected contour levels method is used then the contour values are entered by clicking on the contour levels to the right of the parameters. This will open a dialog box in which either a single level can be entered, to replace the value clicked, or a set of levels separated by spaces, in which case the values replace the complete set of contour levels.

#### The extend options

The extend option is used for filled contours. These are generated as polygons within which the values lies between two contour levels. Optionally the plugin can also generate polygons for the area where the data is less than the minimum contour level or greater than the maximum contour level. The extend option is used to choose which of these are created.

### Output layer attributes

The default output layer name is generated based on the input layer and the name of the field or expression defining the data values. However this can be changed to whatever is required in the dialog box.

The layer has attributes based on the contour level (or levels for filled contour), including a "label" attribute that can be used for labelling the features. The options for formatting the label are:

- Label precision the number of decimal places used to represent data values
- Trim zeroes is used to trim trailing zeroes from contour levels. For example if the level is 1.2003, and the precision is 2, then this becomes 1.20. If the trim zeroes option is selected this will become 1.2
- Units is a string appended to the data values in the label. For example it could be "metres above sea level"

The plugin can render the layer using a categorized renderer using a different colour for each contour level. This is particularly useful for displaying filled contours. This is set using the Apply colours option. The colours are selected from a colour ramp which may be reversed if required.