TransWikia.com

Creating a dynamic drop-down list based on an array expression

Geographic Information Systems Asked by LeoC on March 10, 2021

Would it be possible in a QGIS form to create a list of values with the array() function in the expression builder? This array would change, depending on different conditions.

The Value Relation widget is close to what I need, but it has to have one connected table, and the values in the list are only from this table. I’d like to add multiple conditions and values modifications.

Let’s say I have 3 layers:

  • infra, where i’ll find the type of infrastructure
geometry "type"
line ‘underground’
‘aerial’
  • telecomLines, where I’ll find the size of the lines.
geometry "size"
line ‘big’
‘small’
  • equipment the layer i’ll have to edit, where l’ll choose the type of equipment to install, I would need an array of possible object to install depending on the intersected type and size. Id like the array to be used as a scrolling menu in the form when creating or editing a point. Depending on the intersecting lines, a filtered list of possible choices would appear.
geometry "equipment"
point ‘big pole’
‘large pole’
‘high pole’
‘small pole’
‘thin pole’
‘low pole’
‘big chambre’
‘large chamber’
‘deep chamber’
‘small chamber’
‘thin chamber’
‘shallow chamber’

For exemple, for big and underground cables, an array of possible big chambers, and for small and aerial cables, an array of possible small telecom poles.

This Expression would produce the array of possible equipment on a the equipment layer when opening an form.

with_variable('lineType',
            aggregate(
                layer:='infra', 
                aggregate:='max', 
                expression:="type", 
                filter:=intersects( $geometry, geometry(@parent) )),

with_variable('linesSize',
            aggregate(
                layer:='telecomLines', 
                aggregate:='max', 
                expression:="size", 
                filter:=intersects( $geometry, geometry(@parent) )),

if (@lineType = 'underground',
         map_get( map(  'big', array('big chambre', 'large chamber', 'deep chamber'),
                        'small', array('small chamber', 'thin chamber', 'shallow chamber')), 
                @lineType),
if (@lineType = 'aerial',
        map_get( map(   'big', array('big pole', 'large pole', 'high pole'),
                        'small', array('small pole', 'thin pole', 'low pole')), 
                @linesSize),
--(Else)
array('big pole', 'large pole', 'high pole', 'small pole',
        'thin pole', 'low pole', 'big chambre', 'large chamber', 'deep chamber',
        'small chamber', 'thin chamber', 'shallow chamber')))))

here’s a quick map of the exemple on qgis Cloud:

https://qgiscloud.com/nox/filterList/?bl=mapnik&l=telecomLines%2Cequipment%2Cinfra&t=filterList&e=172490%2C6003875%2C174522%2C6004867

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP