QGIS Attribute Edit Form – Support for ‘Relationship’ Data in Editing

editingqgisrelationship-class

Consider I have a geometry table having one-to-many relationship with a no-geometry table. When I create a feature (geometry), I would like to be able to add the relative no-geometry table data in the corresponding feature attribute edit form as well. Is this possible?

Best Answer

This is possible.

But for QGIS to support this type dynamic change when editing data, the data has to have a backend to support that like a RDBMS.

If using PostgreSQL that has PostGIS enabled, you could create a new VIEW to facilitate the requirements of the JOIN.

Then when you add a new feature to your source table (the geometries) or the view, then the VIEW will reflect that change and map the values to the related table correctly.

When creating a new feature in QGIS, you often have to "Save Edits" before the change is actually committed to the database - once the feature has been committed the VIEWS will do their thing and you should be able to see the changes (ie, the columns from the related table are populated in the VIEW)

There are a number of ways you can make sure the data you enter is valid for both the spatial and attribute components. QGIS allows you, for example, to set up the input forms so that you can enter values from a list of existing values in a column (or enter new ones if needed). But this makes sure that the data you are entering will actually map to the related tables.

Then on the PostgreSQL/PostGIS side of things, the data types can be checked against CONSTRAINTS built into the database such as making sure the column types are the right format and length, spatial types are 3D vs 2D, geometry types are consistent (eg, all LINESTRINGS or all MULTILINESTRINGS). You can even set up constraints that only allow a set of values (similar to building domains and subtypes in an ESRI File Geodatabase) to be valid for specific columns. This last little bit enhances the QGIS form building process by preventing users from inputting invalid values that won't match a record in your related table.

Though this isn't an example of JOINS, this video shows the dynamic nature of VIEWS and how they can be leveraged: http://youtu.be/oOhbbEkl4Kg

EDIT:

There are these two related questions that also give some tips on how to work with subtype and domain type functionality in QGIS.

Related Question