[Qgis-user] New Labeling: conditional labels

Giuseppe Sucameli sucameli at faunalia.it
Thu Dec 29 05:18:19 PST 2011


Hi Andreas,

On Thu, Dec 29, 2011 at 11:25 AM, Andreas Neumann <a.neumann at carto.net> wrote:
> I think I sort of understand the syntax - at least the > operator and the
> substr. What I do not understand is why I need the *-1 (multiplier).

when the condition is true I need the entire string,
so if id > 0 then substr(id, 0, length(id)) else substr(id, 0, 0).

I usually use -1 in python to get the entire string, so I gave it a
try, but even if it works well looking at function help I've noticed
it's wrong.

The function help says:
substr(string,startpos,length)
so we need to use the string length, but also the startpos values
starts from 1, not 0... (and the help doesn't help to understand it).

> But I think the syntax is far from being intuitive, without some help. Maybe
> we can come up with a simple solution in the future?
1+, I agree

Regards.

> If we could combine the rule-based renderer approach with the current
> labeler (with its new query builder), it would be awesome.
>
> Thanks for your help!
>
> Andreas
>
>
> On Wed, 28 Dec 2011 20:01:43 +0100, Giuseppe Sucameli wrote:
>>
>> Hi Andreas,
>>
>> On Thu, Dec 22, 2011 at 2:31 PM, Andreas Neumann <a.neumann at carto.net>
>> wrote:
>>>
>>> What I want is that a label is only drawn if a column value is larger
>>> than
>>> 0. I don't want to label features with a value of zero.
>>>
>>> Do you have any hints how the syntax works for such a case? I see ">"
>>> operators but no "if" or "when".
>>
>>
>> there's no "if" operator, but ">" returns 1 if true and 0 if false,
>> e.g. (field > 5)*10 let's give you 10 or 0 as result.
>>
>> The problem is that you don't want to display anything when
>> the field value is 0, so we can use the substr function.
>>
>> Here's the solution to your problem:
>> substr(id, 0, (id > 0)*-1)
>> that means if id <= 0 then substr(id, 0, 0) else substr(id, 0, -1)
>>
>> In general:
>> substr(output, 0, (condition)*-1)
>>
>> Cheers.
>>
>>> If it is not possible, then I can still do it in Postgis, but it would be
>>> nice being able to do this in QGIS.
>>>
>>> Thanks for any hints,
>>> Andreas
>>>
>>> --
>>> --
>>> Andreas Neumann
>>> Böschacherstrasse 10A
>>> 8624 Grüt (Gossau ZH)
>>> Switzerland
>>> _______________________________________________
>>> Qgis-user mailing list
>>> Qgis-user at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
> --
> --
> Andreas Neumann
> Böschacherstrasse 10A
> 8624 Grüt (Gossau ZH)
> Switzerland
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user



-- 
Giuseppe Sucameli



More information about the Qgis-user mailing list