Monday, May 1, 2017

Create labels from multi-columns in QGIS

It is quite simple to create labels from one or more database columns in QGIS; just that you have to type in the correct syntax as shown below.

  1. Run QGIS. Display some layers, e.g. stations.

  2. In the Layer Panel, mouse right click on the layer to be labelled, e.g. stations.

    A pop up menu appears

  3. Choose Properties.

    The Layer Properties dialog box appears.

  4. Choose Labels. In the combo box, select Show labels for this layer.

  5.  In the Label with field, click the Expression icon.

    The Expression dialog box appears.

  6. In the Expression tab, type in the syntax to form the multi-column label e.g.
    name || ' ' || code.

    Note: name and code are two columns from the layer database table, and || is the string concatenation operator and ' ' is a space character.
  7. Click OK. And Click OK to apply the changes.

    The labels appear.
  8. If multi-line labels are desired, then the newline character '\n' needs to be concatenated with the database fields in the Expression dialog box, as shown below.
    name || '\n' || code

    And the resultant map look like this.


Map Learner said...

Is there a way to make this appear as a table e.g.
Name xxxx
Age 19
Gander M

dominoc925 said...

@Map Learner, sorry I don't think it supports HTML table tags

susangis said...

you can try this:

concat( 'Name:',name) || '\n' || concat( 'Age:', age)||'\n'||concat('Gender:',gender)