0

How can I have a set of labels for a location, where the variables are within a single column?

What I am hoping for is to have placement of 'concentration' followed by depth at each location shown on label.

Example of my data:

Loc_ID (1, 1, 1, 2, 2, 2...) Depth_m (0.2, 0.5, 1.0, 0.2, 0.5, 1.0) Conc. (1, 0.2, <LOR, 1 ,no data, 0.2) etc...

I have tried CASE and coalesce. However, in an instance where there is no data, the label shows an empty line, which is not required.

I am using QGIS.

1
  • 1
    Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Your questions should as much as possible describe not just what you want to do, but precisely what you have tried and where you are stuck trying that. Please check out our short tour for more about how the site works.
    – Ian Turton
    Commented Jul 13, 2020 at 8:43

1 Answer 1

2

Sorry if I did not understand you properly; I thought you might want an expression like:

CASE 
WHEN "Conc" != 'no data'
THEN 'Loc_ID: '  + to_string("Loc_ID")  + '\n' + 
     'Depth_m: ' + to_string("Depth_m") + '\n' + 'Conc: '    + to_string("Conc")
ELSE 'Loc_ID: '  + to_string("Loc_ID")  + '\n' + 'Depth_m: ' + to_string("Depth_m")
END 

in the Field Calculator -

enter image description here

Which will produce a new field for the label:

enter image description here


[UPDATE]

To make a "grouped" label at each 'Loc_ID', you can use concatenate() function.

Using the previously made "Label" field, the expression would be:

concatenate("Label" , group_by:= "Loc_ID", concatenator:= '\n', order_by:= 'Depth_m')

enter image description here

Given this is what you are up to, the expression for "Label" field should be simplified as below:

CASE WHEN  "Conc" != 'no data'
THEN 'Depth_m: ' + to_string("Depth_m") + ' , ' + 'Conc: ' + to_string("Conc")
ELSE 'Depth_m: ' + to_string("Depth_m")
END 

The final attribute table becomes:

enter image description here

Please use the `"oneLabel"' field to add the label.

2
  • Just a clarification. is there a condition where i could have the 'various' depths and conc under a single 'label'? or is that more a edit option in QGIS for labeling a point. cheers!
    – Alan Bull
    Commented Jul 16, 2020 at 23:14
  • @AlanBull Yes, it is called aggregate operation. Please see the updated answer. If it is not answering your comment, please let me know.
    – Kazuhito
    Commented Jul 17, 2020 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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