Monday, 12 August 2019

labeling - Displaying multiple fields as labels if one field is null in QGIS?



I am having some issues trying to show multiple fields for a single label in QGIS. In QGIS2.6, attempting to display labels for a feature consisting of multiple fields results in an empty label if one of the fields is null. So for example, in the label expression dialog:


concat("Temp Site",'\n',"Notes",'\n',"Function")

will function normally unless one of the fields is null, then it results in no label being shown. Using the '||' operator instead in the expression dialog also results in the same behaviour:


"Temp Site" || '\n'  ||  "Notes" || '\n'  ||  "Function"

Is there a way to display the labels even if one of the fields is null?



Answer



Use the "Coalesce" function. Coalesce takes the first non-null value from its arguments. So this expression should work:


coalesce("Temp Site",'') || '\n'  ||  coalesce("Notes",'') || '\n'  ||  coalesce("Function",'')

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...