3

Is there a way to alter the data defined override expression? I have a points layer which I label with one of its attributes. The attribute table also comes with a field for an offset from point-value for correct displaying, but the format of this field doesn't work with the override on these two points:

  1. Datatype in the table is int, Override is looking for string
  2. Table values range from 1-9, Override is looking for 0-8 (and starts from top left quadrant, instead of bottom left)

I would like to avoid making a copy of the layer and alter the values, as this is a layer that I sync from an external source.

Here is the current expression:

Data defined override
Active: no   (ctrl|right-click toggles)
Expected input:
int
[0=Above Left|1=Above|2=Above Right|
3=Left|4=Over|5=Right|
6=Below Left|7=Below|8=Below Right]
Valid input types:
string
Current definition ():
undefined

And this is what I would like it to be:

Data defined override
Active: no   (ctrl|right-click toggles)
Expected input:
int
[7=Above Left|8=Above|9=Above Right|
4=Left|5=Over|6=Right|
1=Below Left|2=Below|3=Below Right]**
Valid input types:
int
Current definition ():
undefined

Best regards /Jeston

1 Answer 1

5

Great thing about data defined override is that you may not only use a column, but also any valid expression producing valid values for the thing you like to override (this is either or, if you add an expression, you needn't add a column, and vice versa). Simply click the override button, go to edit and enter the following:

CASE
WHEN "override column" = 1 THEN 6
WHEN "override column" = 2 THEN 7
WHEN "override column" = 3 THEN 8
WHEN "override column" = 4 THEN 3
WHEN "override column" = 5 THEN 4
WHEN "override column" = 6 THEN 5
WHEN "override column" = 7 THEN 0
WHEN "override column" = 8 THEN 1
WHEN "override column" = 9 THEN 2
END

"override column" is your column name and needs to be replaced, and I assume your column has integer values. If this is not the case, you need to place single paranthesis (') around the first number in each row.

3
  • Great answer, thank you very much! That solved the second part of the problem! I still cannot select the correct column for the override however, since the column is "Field type: Int", and QGIS only allows for "Field type: String". I somehow need to change the "Valid input type" in the expression. Commented Aug 4, 2020 at 10:18
  • No, there is no need to select a column for the override, you only paste the expression under edit and are done with it @JestonLunnigan. Fair to add that I am working with 3.10., but I somehow doubt this could be an error source.
    – Erik
    Commented Aug 4, 2020 at 11:08
  • 1
    My mistake. You're absolutely right. This issue is resolved! Thanks again! Commented Aug 4, 2020 at 11:49

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.