5

I'm struggling to find a great example of attribute validation in QGIS. I have existing data created in Autocad Map. It contains some errors. I'd like to check text fields match a code in a lookup table. ie for the field 'FP_TYPE' valid attributes are {'SP', 'RP', 'TP'} Anything else isn't valid and I'd like it flagged.

I don't want to do this using a selection expression, if possible. I'd prefer to use something like style. I've tried using field constraints. I've set up a field constraint using an expression and checked enforce constraints. Then copied the style to my erroneous shapefile. The erroneous attributes aren't flagged in any way. So I presume I'm using the constraint feature incorrectly.

Does anyone have great instructions on how to set up attribute validation in QGIS? There's plenty of instructions on setting up the forms for creating new features with attributes from a drop down list but that doesn't seem to apply to checking existing features.

1 Answer 1

4

Doing this with styling is a good suggestion and is something I have done in the past.

You can used Rule-based symbology to achieve this.

Layer Properties > Symbology > Rule-based

Create a rule for the acceptable values of each field, then create an ELSE to capture all the invalid values.

In your case:

  • Create a rule with the Filter, set the style to a green:

    "FP_TYPE" IN ('SP', 'RP', 'TP')

  • Create a rule with Else radio button checked, set the style to a red. A catch-all for other features i.e invlaid ones.

All the geomtery with valid values will appear green, all the ones with other values will appear red.

We can add as many different validation rules as we like, i.e. referencing different fields.

ValidationWithRules

1
  • Great! The same expression could also be used to create a new attribute flag with field calculator. In this case, the information is stored in the data and thus software- independent. It makes it also possible to filter based on this attribute.
    – Babel
    Jul 2, 2021 at 6:05

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.