using expression builder for Labels

94 views
Skip to first unread message

Ia...@jcis.net.au

unread,
Mar 11, 2025, 4:58:32 PM3/11/25
to australian-qg...@googlegroups.com

I am trying to label heritage items on a map and am using the expression builder to get a field called Heritage ID to sit over another field Heritage name so it looks like

 

    I 1099

Old house

 

I think I have worked it out but is there a cheat sheet or some sort of guide on doing this? The official QGIS guide is quite useless. I don’t even know what sort of language is being used.

 

Looking for pointers so I can lean.

 

Cheers

 

Dr Iain Stuart

JCIS Consultants

President Royal Australian Historical Society

P.O. Box 2397

Burwood North

NSW, 2134

 

(02) 9701 0191
(0413) 380116 (m)

 

Emma Hain

unread,
Mar 11, 2025, 5:48:31 PM3/11/25
to australian-qg...@googlegroups.com
ooo This is a great idea for a resource - Let's collate a cheat sheet for labelling and we can include html as well.
Here's a google doc to populate:




--
You received this message because you are subscribed to the Google Groups "QGIS Australia User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/australian-qgis-user-group/001301db92c8%2443ec8490%24cbc58db0%24%40jcis.net.au.

Emma Hain

unread,
Mar 11, 2025, 7:02:23 PM3/11/25
to australian-qg...@googlegroups.com
But in the meantime:
Label 1: I
Label 2: 1099
Label 3: Old House

"Label 1" || ' ' ||  "Label 2"  ||  '\n'  ||  "Label 3"

image.png


Kind regards
Em

Emma Hain — Product Manager/Senior GIS Analyst
em...@north-road.com
https://north-road.com
North Road
Cartography • Development • Spatial Analysis


north-road.com

QGIS User Conference 2025
2-3 June,
Norrköping, Sweden
FOSS4G 2025
17-23 November, Auckland, New Zealand


Juan Fernando Berrío

unread,
Mar 11, 2025, 7:57:11 PM3/11/25
to australian-qg...@googlegroups.com
Hi Iain, Emma, 

Emma already answered the question - I hope that one works well. 

To complement, building labels is a function of QGIS where I often end up spending more time than anticipated too.  For how to do it, I usually go to google and end up using answers from gis.stackexchange.com, rather than official documentation - for the same reason you mention Iain.  Improving the documentation as Emma mentions sounds like a great idea. 

From what I've seen, the language used to build label expressions is a hybrid between standard python string formatting, and QGIS' custom functions. The '\n' for new lines in your example comes from standard python for example.  So if you google how to format strings in python, you may be able to find answers for particular questions.  It's not guaranteed that all of them will work though - some functions/conventions don't work for me from time to time. 

Another obstacle is that it's not easy to visualise how formulas get processed (they may work on the first row but not on all the rows) - so it's not always easy to detangle issues.  To help with that, I generally try to avoid building complex expressions in one go.  Instead, I usually build the expressions by testing one part at a time (one field at a time), check that they work, and then put it all together at the end.  That helps. 

Some quick bullet points that usually help me:

- Single quotes denote strings/text, double quotes denote fields. 
- Double vertical bars join text
- '\n' inserts a new line
- If you're labelling columns that contain NULL values, use the function coalesce to avoid issues [e.g.   coalesce("mycolumn", '')   ].  

Hope it helps,
Juan






Ia...@jcis.net.au

unread,
Mar 11, 2025, 9:13:25 PM3/11/25
to australian-qg...@googlegroups.com

Thanks Emma,

 

Years ago in the ESRI universe I came across a cheat sheet for Arc.

 

If there isn’t one for QGIS – we may as well build one ourselves.

 

In my googling (I have a really thankless task for work that I am avoiding) I came across this neat video on road symbology and labelling from the Map Academy  https://www.youtube.com/watch?v=cNBWn3sHfmQ&ab_channel=MapAcademy It appealed to me as I was struggling with the road corridor layer from the NSW Spatial database which needs a bit of cleaning up.

 

Cheers

 

Dr Iain Stuart

JCIS Consultants

President Royal Australian Historical Society

P.O. Box 2397

Burwood North

NSW, 2134

 

(02) 9701 0191
(0413) 380116 (m)

 

WillyB

unread,
Mar 29, 2025, 11:07:51 PM3/29/25
to QGIS Australia User Group
Iain, 

the Expression Builder is used widely in QGIS and has help built in. Maybe "concatenate" isn't so obvious, but once you type your request in the expression search, you will get a good bunch of hints, including on the right hand side, proper help with worked examples. This part of QGIS I find to be one of best user interfaces of any software bar none. No googling reqd. 
As always, there is more than one way to skin a cat. Using pipe operator "||" for joins of text instead of concatenate, you will likely get errors with the pipe operator when you have missing data. The full function concatenate is more robust if you dataset has NULLs. 


concat labels.png

Reply all
Reply to author
Forward
0 new messages