0

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

10
  • 1
    The short answer is: Yes. The more detailed answer is based on what you need: please edit your question and add more details. – Babel Jan 25 at 21:18
  • I've added an example – LeoC Jan 27 at 8:08
  • Your expression is valid and produces an output (array). So what is your question? It would also help to see your data structure - or even better have some sample data. – Babel Jan 27 at 9:02
  • 1
    You can use the filter in the value relation widget. A good example that shows how to do it is the video here: northrivergeographic.com/archives/… – Babel Jan 27 at 9:26
  • 1
    I suggest that you get the information of the layers infra and telecomLines as attributes in your equipment layer, creating new attributes: array_first ( overlay_nearest( 'infra', type)). You than have all the information in one layer. – Babel Jan 27 at 11:01

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.