QGIS TUFLOW Apply Label to Current Layer

From Tuflow
Jump to navigation Jump to search

This tool offers a quick label tool for TUFLOW layers (check files, results, input layers etc.). The label is applied to the currently selected layer. Packaged with the plugin are a set of default labelling rules for the majority of TUFLOW layers. These defaults can also be modified by the user.

Running the Tool

The tool can be run by clicking the following icon in the toolbar:
Auto label toolicon.PNG

Clicking the label icon once will toggle labels on for the selected layer. Clicking the icon a second time will turn off the labelling. When toggling the labelling off, the same layer must be selected in the Layers Panel.

Customising the Labelling Rules

The labelling rules can be customised by the user by navigating to the TUFLOW plugin installation directory, or by clicking the down-arrow on the tool icon and selecting Open Label Settings.
(Windows labelling rules directory)

%appdata%\QGIS\QGIS3\profiles\default\python\plugins\tuflow\layer_labelling

(Linux labelling rules directory)

/home/USER/.local/share/QGIS/QGIS3/profiles/default/python/plugins/tuflow/layer_labelling

In this directory path there are a number of txt files that correspond to TUFLOW layers based on the name of the txt file. These can be edited (or new txt files can be created if one doesn't already exist) by the user to customise the labelling rules. There is also a 'default.txt' which applies default rules if a TUFLOW layer doesn't have an individual txt file yet. There is also an 'override.txt' that will override labelling rules and always take precedence (you'll notice that the rules in that file are commented out by default).

All the label styles are defined by the commands listed below:

  • Buffer == ON | OFF - this turns on whether the label draws a mask or buffer around the text (usually you wouldn't have a box and a buffer - see below)
  • Box == ON | OFF - this turns on whether the label draws a box around the text (usually you wouldn't have a box and a buffer - see above)
  • Attribute Name == ON | OFF - this determines whether the attribute name is labelled with the attribute value e.g. an "ON" value for a 2d_po type would be "Type: H_", an "OFF" value would just be "H_"
  • Label Attributes - this is the index of the labelled attribute field (starting at 1). Multiple attributes can be labelled by using a "|" to delimit the indexes. Each attribute will be labelled on a separate line. The order they are listed in the txt file will be the same order it is labelled in QGIS.
Note: - available since v3.3, labelling GPKG does not require the user to change the index of the attribute (GPKG layers usually insert a field call 'FID' at the start by default and would therefore mis-align the listed indexes in the labelling rule txt files).
  • Point Placement == Cartgraphic - the label placement around point features. Currently the only available option is 'Cartographic'.
  • Line Placement == Parallel | Horizontal - the label placement around line features. 'Parallel' alignes the label orientation to the line feature. 'Horizontal' always aligns the label horizontally.
  • Region Placement == Centrod - the label placement around polygons / region features. Currently the only available option is 'Centroid'.
  • Offset X,Y == <X>,<Y> - the offset from the normal labelling position in millimetres. Only applies to point and polygon features.

There are a number of different ways to define labelling rules:

Single Labels
This labels all features in the TUFLOW layer the same way. For example, in a 2d_po layer a single label rule will label all features the same regardless of whether the PO type is 'H_' or 'V_'. To apply single label rules, the commands listed above can be written in the txt file without any other syntax required. As an example, the txt file may look like this:

Buffer == ON
Box == OFF
Attribute Name == OFF
Label Attributes == 1  ! attribute indexing starts at 1
Point Placement == Cartographic  ! only available option at the moment
Line Placement == Parallel  ! Parallel or Horizontal
Region Placement == Centroid  ! only available option at the moment
Offset X,Y == 2,2  ! only works for points and regions

Rule Based Labels
This labels features within the layer based on a set of rules. For example, in a 1d_nwk the labelled attributes may be different depending on whether the channel type is a 'C' type compared with an 'R' type (the 'R' type uses an addtional attribute to define its dimensions). To apply rule based labelling, rules must be defined in blocks starting with "Attribute == <index> | <Value1>;<Value2>;..." and end with "End Attribute". The rule is stating that attribute at <index> should equal any of the listed <Values>. The same commands listed above should be included within the rule block. There is also an additional command that should be added:

  • Rule == Strict | Loose - a 'strict' rule will only apply to atrributes that exactly equal one of the values (case insensitive). A 'loose' rule will apply to attributes if the first letter of the attribute is the same (example below of use case).

Multiple rules can be applied, it is also recommended to also include a 'single label' block that will be applied to all other features that don't fit into any of the rules.

An example of rule based labelling for a 1d_nwk line is shown below.

! rule based labelling - attribute 2 = 'C'
Attribute == 2 | C;CU  ! circular pipe, and circular pipe with flap gate
    Rule == Strict  ! strict means this rule will only work for 'C' and 'CU' types
    Buffer == ON
    Box == OFF
    Attribute Name == ON
    Label Attributes == 1 | 2 | 14 | 16
    Point Placement == Cartographic  ! only available option at the moment
    Line Placement == Parallel  ! Parallel or Horizontal
    Region Placement == Centroid  ! only available option at the moment
    Offset X,Y == 2,2  ! only works for regions and points (points only uses the first value)
End Attribute

Attribute == 2 | W  ! weir type
    Rule == Loose  ! Loose means this rule will be applied to all weir types (WB, WD, WO, WR ,WT, WV, WW)
    Buffer == ON
    Box == OFF
    Attribute Name == ON
    Label Attributes == 1 | 2 | 7 | 8
    Point Placement == Cartographic  ! only available option at the moment
    Line Placement == Parallel  ! Parallel or Horizontal
    Region Placement == Centroid  ! only available option at the moment
    Offset X,Y == 2,2  ! only works for regions and points (points only uses the first value)
End Attribute

! all else
Buffer == ON
Box == OFF
Attribute Name == ON
Label Attributes == 1 | 2  ! attribute indexing starts at 1
Point Placement == Cartographic  ! only available option at the moment
Line Placement == Parallel  ! Parallel or Horizontal
Region Placement == Centroid  ! only available option at the moment
Offset X,Y == 2,2  ! only works for regions and points (points only uses the first value)

Examples

Auto label example.gif

Up
Go-up.png Back to TUFLOW QGIS Plugin Main Page