[Qgis-user] using nested case statements in labelling

DelazJ delazj at gmail.com
Tue Dec 20 23:50:18 PST 2016


Hi,
The issue resides in the use of || operator, which doesn't handle null
values: if any of the concatenated items is null then the result returns
null. In this case, better use the concat function. Something like below
should work (untested, though)

Case when  "signifcant"  = 'yes'
Then
concat( title( "Name" ), '\n',
 Case when "Cu_e_t" <1 Then '' Else round("Cu_e_t"/1000,0) || 'Kt Cu ' End,
 Case when "Pb_e_t" <1 Then '' Else round("Pb_e_t"/1000,0) || 'Kt Pb' End
)
Else null -- I think it's not really needed
End

See
http://docs.qgis.org/2.14/en/docs/user_manual/working_with_vector/vector_properties.html#define-labels-based-on-expressions
for some sample of labeling code

Hope that helps,
Harrissou

Le mercredi 21 décembre 2016, damos <damien.stephens at gmail.com> a écrit :
> HI I am trying to do a nested case statement for a labelling task.
> I have a list of mines of varying sizes with different commodities and
would
> like to label with the name of the mine and the amount of each commodity
at
> the mine in a new line below the name. I only want to label the mines
that I
> have decided are signifcant and for this I have made a new column in my
> table called significant.
> My difficulty is that not all mines have the same commodities, for example
> one mine has copper (Cu) and no lead(Pb), while another has both. yet
> another will only have Pb.
> i can easily label all of the sigificant mines and their copper amoutns
with
> a suffix of kt Cu using this code:
>
> case when  "signifcant"  = 'yes' then  title( "Name" ) ||   '\n'   ||
 case
> when "Cu_e_t" <1 then '' else round("Cu_e_t"/1000,0) || 'Kt Cu' end else
> null end
>
> however if I then try to add in the Pb amounts like this;
> case when  "signifcant"  = 'yes' then  title( "Name" ) ||   '\n'   ||
 case
> when "Cu_e_t" <1 then '' else round("Cu_e_t"/1000,0) || 'Kt Cu' end ||
> case when "Pb_e_t" <1 then '' else round("Pb_e_t"/1000,0) || 'Kt Pb' end
> else null end
>
> I lose all of the Cu only mines and only get labels for those with Cu and
Pb
> or just Pb.
> I understand that I am doing something wrong with the nested case
> statements, but cant figure out what.
>
> any help would be much appreciated.
> int the mean time I am going back to do the formula in excel where I am
> capable.
>
>
>
>
> --
> View this message in context:
http://osgeo-org.1560.x6.nabble.com/using-nested-case-statements-in-labelling-tp5300779.html
> Sent from the Quantum GIS - User mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20161221/0712a010/attachment.html>


More information about the Qgis-user mailing list