4

I am trying to model the 'splicing' of cables (Table 1) together at a splice point (Table 2).

  • Table 1 - "Cables" (linestring)
  • Table 2 - "Nodes" (point)
  • Table 3 - "splices" (geomless table with int fields for ID of "Nodes", and "Cables" a&b)

I have created the third table ("splices") to do this by using a value relation to both Nodes & Cables ('a' & 'b' for the two ends of the cable).

When creating a new record in "splices", once "Node" is selected I would like to only return nearby "Cables".

enter image description here

To filter the Cables I have used:

intersects($geometry, buffer(geometry(get_feature_by_id('[qgis node layer]','7067')), 0.000005))

This works, but as you can see, I am referring to Node id (7067) statically. How can I instead use the Node id of the selected Node?

I wondered if I need to use current_parent_value(field_name) to find the Node id, but can't seem to make that work.

enter image description here

1 Answer 1

3

You can use current_value('field_name') to access the unsaved value of field_name in the current form. In this case, it's the node id.

Adapt the following expression in your splice layer Value Relation widget under Filter Expression for both Cable A and Cable B fields:

intersects($geometry,
    buffer(geometry(get_feature('node_layer','node_id',current_value('node'))),0.5))

Or, if you want the Cable B field to automatically bring up the Cable B value based on the Cable A value, use the above expression for Cable A, and the following one for Cable B - preferably make it read only if you want to avoid accidentally changing it.

"cable_a_id" = current_value('cable_a')


Demonstration of using the first expression for Cable A and second expression for Cable B.

enter image description here Widget settings in splice layer for Cable A field

enter image description here Widget settings in splice layer for Cable B field

enter image description here

2
  • thank you so much for the detailed answer, that works perfectly :)
    – pmwill
    Dec 20, 2021 at 18:29
  • Glad to have helped and thank you for accepting the answer!
    – she_weeds
    Dec 20, 2021 at 21:34

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.