QGIS 3.2: Drive Down Lists aka Value Relation Widget

Jul 13, 2018 | GIS

This is cool.

So – North Road ran a crowd funding campaign to get this into the core component of QGIS. There was a plugin – and to be honest I discovered that about the same time as the crowdfunding was announced. The campaign put the plugin into the core parts of QGIS.

What happens is you have pick lists that can change based on other values. Have a pipe? It can be made out of W,  X, Y, and Z. Is it a Water Pipe? It can only be made of X and Z. Wastewater Pipes can only be made of W and Y.

I worked my way through setting this up – and it’s really not bad once you know how. Granted – had I listened to the above video more closely it would have made better sense starting out.

Here is my walk through. I have a point layer and that point layer has a type and a subtype. I stored this all in a Geopackage by the way. The type drives the subtype. So you pick A and you can only have red or blue. Maybe B is green and white. I made two tables to help with this process tableA is 2 fields: a primary key and a value. TableB has three fields: a primary key, a value, and a foreign key that relates back to Table A.  From that you can see Type A can only have a value of Red and Blue. Type D can only be Black and Gray.

tables

Here’s where it gets a little bit fun. My point layer has two attributes of concern: type and subtype. Type will be A,B,C, or D. Subtype will be a range of colors that Match the Type picked. If you right click the layer and select attribute forms you can assign a form for data entry. In this case for type the key column is the primary key and the value is the type. Note the Widget type is Value Relation!

type widget

Lets looks at the subtype field. The key column is the Foreign Key (the part that relates it back to table A). The value column is the subtype. The magic is this – if you look at the filter expression:“fk” = current_value(‘type’) . Check it out Below:

subtype widget

The foreign key equals the value of the type widget. When you add a point you’ll see this (nothing crazy). The type drives the subtype.

menu

BUT WHEN YOU USE IT:

So you have a drive down list. Utilities usage? There’s more functionality with this you can exploit through the field calculator and the widget lists. It’s another greater way to control your data editing. So don’t be lazy – create great data to drive your database.

 

 

 

 

 

 

 

You may also like

Conda and QGIS Part 2

Conda and QGIS Part 2

Coming back from Yellowstone has left me slightly adrift. I missed a meeting yesterday as I keep forgetting to add things to my calendar. So the last time I mentioned Conda was like 2018 and the whole point to the Article was "I can now have two versions of QGIS...

MAGIP and TNGIC in 2024

MAGIP and TNGIC in 2024

I just came off two conferences with one being in Montana and one being in Tennessee. Both Geo related. It was my first time attending the MAGIP conference. Not that you need a long overly drawn out review of both - here are some of the highlights: TNGIC was fun. It...

QGIS and LIDAR and Forestry Part 2

At the TNGIC conference I did a workshop on LIDAR and QGIS. I was completely blasted out by ESRI's Avenue for the Web class but I had a few souls come in and take a look at it. I finished it off with "I don't use LIDAR that much". Well.....I'm finally using it. It...