0

Its my impression that validation of attribute values is generally approached by defining these constraints in the database schema.

Simple example of a constraint:

Feature 'lamps' has a 'manufacturer' attribute which is a string of length 20 and it must be one of the values in the 'manufacturer' table's 'name' column.

This requires being able to work on classic databases in SQL, and has little to do with QGIS, GIS or WFS. I believe the following would do:

CREATE TABLE manufacturer (
name VARCHAR(20) PRIMARY KEY
);

CREATE TABLE lamps (
    id INT PRIMARY KEY,
    manufacturer VARCHAR(20) REFERENCES manufacturer,
    model VARCHAR(20),
    geom geometry(Point, 4326)
);

The server exposes a WFS API that I can connect to in QGIS and manipulate the 'lamps' feature/table. If I try to commit a change set via WFS and this violates a constraint, I will get an error and the commit is rolled back.

It would be very helpful for the user if QGIS helped show instant validation feedback while typing, and maybe also showed comboboxes or auto suggestions for filling in values. I imagine this is a widely requested feature, but I havent been able to find anything about how to do this in a simple and elegant way.

I am aware that I can manually change the Edit Widget for a field, and define a widget that gets its enum values in a combobox by doing a sql selection from the database. But this will require a lot of work, and it will require doing this every time I add this layer to an existing QGIS Project.

Right now I am considering writing a primitive plugin that automatically sets up the right widgets and the right conditional formatting in any QGIS Project. But I assume there must be easier and more elegant ways to do this.

1
  • you could make your "lamp" a complex attribute by using the application-schema plugin which would allow you to find out what the constraints were in the describeFeature response which could build into the plugin configuration
    – Ian Turton
    Aug 4 at 12:17

0

Your Answer

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

Browse other questions tagged or ask your own question.