20

Is there a way to concatenate fields in field calculator of QGIS? (e.g. hectares + ' ha')

0

5 Answers 5

30

In recent QGIS versions (>= 2.6), + works for string concatenation

tostring(hectares) + ' ha'

Previously, the only concatenation operator was: ||

tostring(hectares) || ' ha'
12

Right-Click on the layer -> Properties -> Labels Then you can use the following function "concat(string1, string2,... ) : enter image description here

I hope it will be usefull.

3
  • 8
    You can also concatenate directly with "field1" || "field2".
    – SAnderka
    Commented Jan 6, 2014 at 8:52
  • With || you can use all kinds of columns. Using concat(), you can only use strings. Commented Jan 6, 2014 at 10:04
  • 2
    I usually prefer at least a blank as separator: "field1" || ' ' || "field2". Splitting the label in two lines is also possible by defining a line separator like /n.
    – AndreJ
    Commented Jan 6, 2014 at 10:44
8

You can also append text or put spaces between using alternate quotations:

 "Streetnum" || ' ' || "Streetname"
1
  • I suggest the readers use this solution rather than the popular solution to combine two integers. to_string("field1") || to_string("field2")
    – G.S. J
    Commented Jun 23, 2021 at 6:59
3

You can use tostring() to concat number fields Ex hectares || ' ha' || tostring(id)

1

Yes! Using the field calculator, the syntax is: FIELDNAME || FIELDNAME

EDIT: This works on string fields or string-integer combinations. With Integers, it will just perform the math and add the fields together.

Not the answer you're looking for? Browse other questions tagged or ask your own question.