Vector field renderer

Contents

Introduction

The vector field renderer is used to display vector field data such as earth deformation, tidal flows, and the like. It displays the vectors as arrows that are scaled and oriented according selected attributes of data points. It can only be used to render point data - line and polygon layers are not derawn by this symbology.

The vector field is defined by attributes in the data, which can represent the field either by cartesian components (x and y components of the field), or polar coordinates. If polar coordinates are used, the angle may be meaured either eastwards from north, or northwards from east, and may be either in degrees or radians. The magnitude of field can be scaled up or down to an appropriate size for viewing the field.As a special case the renderer can also display "height only" data, which displays a vertical arrow scaled usign an attribute of the data. This is appropriate for displaying the vertical component of deformation, for example.

Scale box

The renderer also displays a scale box on the map showing how the arrow size relates to the corresponding vector length.

Note that the renderer does not take account of on-the-fly projection of the map - the arrows are drawn assuming that north is towards the top of the map.

Rendering a vector field

Renderer dialog

A vector field is displayed by changing its symbology. Right click on the layer in the layers list, and select the symbology tab. In the renderer drop down select "Vector field". This will display the options for configuring the symbology. (Note: to see the renderer in the drop down the "new symbology" must be selected.)

The dialog has two main sections - the top section defines how the vector field is expressed in the data, and the bottom section defines characteristics of the arrow symbology.

The fields in the dialog are:

Vector field type Selects the field type - cartesian, polar, or height only, as described above.
... attribute Selects the data attributes which define the vector field, either X/Y for cartesian fields, length/angle for polar fields, or height for the height only field
Scale/units Defines how the vector field will be scaled when it is represented on the map. This can be either in map units, or in the units in which the arrow format is defined (see below). Note that if the arrow is defined in map units, then these are the same. The length of each vector will be multiplied by this scale for representing on the map.
Scale group Defines a scale group label for the layer. Layers rendered with the same scale group will be forced to use the same scale. This must be a simple name, for example "displacement". The name can optionally followed by "*" and a mupltiple, which scale the arrow at the specified multiple of the group scale (for example "displacement*2").
Angle orientation/units Defines how the angle is defined in the data. The orientation is one of North from East (North is 0°, East is 90°) or East from North (East is 0°, North is 90°). The units are either degrees or radians.
Arrow format - units Selects either millimetres, or map units. Defines the units define the arrow sizes. If millimetres are selected, then the arrow sizes are defined in millimetres on the plotted map, and will not change as the map scale changes. If map units, then the arrow will scale up and down as the map scale changes.
Arrow size Defines the size of the components of the arrow. The arrow has three components - the arrow head, the shaft, and the base. The head may change size according to the length of the vector - the shaft width and base size are fixed. The sizes are:
Head (relative) The size of the head relative to the length of the arrow
Head (maximum) The maximum size of the head, overrides the relative size
Base The size of the base of the arrow
Width The width of the arrow shaft
Colours Selects the colours of components of the arrows. The components are:
ArrowThe head and shaft of the arrow
BaseThe fill colour of the base of the arrow
Base borderThe border line colour of the base of the arrow
Legend text Defines text that will displayed alongside the symbology on the legend
Scale box text/Show The scale box text is displayed alongside the scale arrow in the scale box. If the show box is not ticked then the layer will not be included in the scale box.

Modifying the vector field - the vector field toolbar

The renderer installs a toolbar with buttons for controlling the size of the arrows. These rescale the arrows of the currently selected vector layer. They are only enabled if the layer is rendered with the Vector field renderer.

Rescale the arrows of the current layer to an appropriate view. The scaling is based on the maximum size and the number of arrows in the current view.
Increase the scale of the arrows.
Reduce the scale of the arrows.
Configure the scale box - see below
Display this help information

Configuring the scale box

Vector scale box options dialog

The scale box can be configured using the Vector scale box options dialog. This has the following options:

Position Defines the corner of the map where the scale box will be plotted
OffsetX/Y Defines offset of the box from the corner
Approx arrow size Defines the approximate size of the scale arrow as a percentage of the width of the map
Draw box? If checked then a rectangular box will be drawn around the vector scale arrows
Fill box If checked then the box will be filled (features underneath will be hidden).
Border/Fill color Defines the colour of the border and fill of the box
Title Displays the title that will be displayed at the top of the box
Title/scale font Select the font used for the scale box title, and for the legend beside each scale arrow.

Configuring the renderer from python

The following example code shows how to configure the renderer for a layer from python code.

    # Obtain a vector field renderer metadata object vm

    vm=QgsRendererV2Registry.instance().rendererMetadata("VectorFieldRenderer")

    # Create a renderer

    r = vm.createRenderer(None)

    # Set the mode for the renderer - possible values are
    # Cartesian vector (0), Polar vector (1), height only (2)
    # And set the attributes defining the vector field

    r.setMode(0)
    r.setFields('dx','dy')

    # Get the arrow symbol and assign its colors

    arrow = r.arrow()
    arrow.setColor(QColor.fromRgb(255,0,0))
    arrow.setBaseColor(QColor.fromRgb(255,0,0))
    arrow.setBaseBorderColor(QColor.fromRgb(0,0,0))

    # Set other symbology properties
    r.setScaleGroup('deformation')
    r.setLegendText(' horizontal')
    r.setScaleBoxText(' hor')

    # Assign the renderer to the layer and refresh the symbology
    # Not sure whether clearing the image cache is necessary, should be 
    # done by QGis on setting the renderer

    layer.setRendererV2(r)
    layer.setCacheImage(None)
    self._iface.legendInterface().refreshLayerSymbology(layer)

    # If the scale is to be automatically set based on the visible
    # vectors, then the following rather obscure code will do it.

    self._iface.mapCanvas().refresh()
    mapsize = self._iface.mapCanvas().extent()
    layer.rendererV2().autoRescale(mapsize)
    layer.setCacheImage(None)

Change history

Version 0.12: 8 March 2011:Bug fix causing QGis crash when fields not selected. Added functions to simplify programming from python. Improved documentation.

Version 0.10: 8 April 2010: Changed activated() signals to triggered() in readiness for removal of qt3 support.

Version 0.9: 2 April 2010: Fixed autoscaling of vector layers when using on the fly projection.