4

is it possible in the attribute table of a vector, to use a condition for the whole table in a single method?

I have computed a correlation matrix between all the fields and it could be very useful to highlight all the values, for example, > 0.8.

I tried to use the Full row option and to add @value > 0.8 but it did not work..

Else I had to add a rule for each column and it could take a while..

2

The best way to do this is to make a custom expression function:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def any_value(feature, parent):
    for attr in feature.attributes():
        if attr > 0.8:
            return True
    return False

Use the Function Editor and create the function changing the attr == line to match what you need.

You can then have a condition use this.

enter image description here

  • Wouldn't that be very fragile because it takes unrelated columns into account? – Matthias Kuhn Sep 13 '16 at 6:36
  • Thanks for the answer.. however I loaded your function and use it in the Full Row option.. but all the table is green now (I'm sure there are values <0.8 and also some strings)... – matteo Sep 13 '16 at 7:53
  • Post a screenshot of your data that might help – Nathan W Sep 13 '16 at 12:41
2

It wouldn't work if your equation included the '@value'. That should be substituted with the field use wish to calculate with.

"correlation matrix column name" > 0.8

EDIT:

OK so I've made a mock example from all the details you've given. I have a vector layer and a table fro the correlation matrix. I've joined the two together and applied full row conditional formatting across all columns for rows with a value greater than 0.8. Is this what you're trying to achieve.

enter image description here

  • thanks for the answer. That's not what I am looking for. I already have the correlation matrix loaded in QGIS (as table) and I want to highlight all the values >0.8, but for all columns, not for a single column (or without having to add the same rule manually for all the columns) – matteo Sep 12 '16 at 14:13
  • Table names should be in double quotes - especially when there are spaces ;) – Matthias Kuhn Sep 13 '16 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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