5

I am looking for a way to implement conditional value mapping in QGIS. This means that the values available in attribute number 2 depend on the value provided in attribute 1.

Example:

If the user enters "agriculture" in attribute 1, for attribute 2 only "corn" or "wheat" will be available.

Instead, if the user enters "forest" in attribute 1, for attribute 2 only "pines" or "olives" will be available.

And so on...

Apparently this is not doable just using the QGIS widget expression builder, but I am not sure. Here's a screencast to help visualize. The problem is that if for "class" I pick other than "Agri_Field", for the "color_aggri" attribute the same possible values appear.

enter image description here

2
  • This is plugin/standalone application or you want to do this with standard Qgis tools (like subtypes in ArcGiS)?
    – dmh126
    Commented Apr 23, 2015 at 11:17
  • I wish to do this with standard tools - no plugin development
    – Lisdengard
    Commented Apr 23, 2015 at 11:56

3 Answers 3

4

The thread is quite old, but still one of the first answers to the problem found on Google. Therefore a small update: For QGIS 3.X the plugin from Lisdengard's answer does not exist anymore. From 3.4 onward this feature is now part of the core functions and can be found in Properties > Attribute Forms > Value Relation. See https://north-road.com/drill-down-cascading-forms/ and https://www.northrivergeographic.com/archives/qgis-3-2-drive-down-lists-aka-value-relation-widget for a short introduction.

2

A similar function has been introduced recently

It requires the possible values to be grouped on the related layer and is slightly more involved in setup.

If you have a layer

Plots

  • Name
  • class (foreign key to Classes:pk)

And a layer

Classes

  • pk
  • Type [Agriculture/Forest]
  • Plant [Pines/Olives/Corn/Wheat]

You will need to add a new relation in Project Properties=>Relations that defines the foreign key from Plots:class to Classes:pk.

Then you can define a relation reference widget on Plots:class with pre-filters checked (this option is new and was introduced AFTER 2.8. Until the next release, get a nightly/master build!) and check "Type" as pre-filter.

3
  • Thanks Mathias! Though not exactly what I would like it (I would prefer a recursive solution), I tried it and it's definitely a valid work around! Again, thanks a lot!
    – Lisdengard
    Commented Apr 23, 2015 at 19:50
  • Can you explain what you mean with recursive? Commented Apr 24, 2015 at 8:02
  • Maybe not the best word, but what I meant is that it would be nice if no extra table would be needed - conditioning "on fly" attribute 2 by what was entered first in attribute 1. This something usually required for mobile GIS apps, but I think it has it's space on desktop GIS too.
    – Lisdengard
    Commented Apr 24, 2015 at 11:48
0

This issue is now easy to tackle:

http://www.itopen.it/a-new-qgis-plugin-allows-dynamic-filtering-of-values-in-forms/

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.