3

I have a point layer named closure and a line layer named cable in QGIS.

Within closure there's 4 fields (id, type, ingress, egress), cable has 4 fields (id, type, from, to).

I have managed to form a code within attribute form to tell me that cable starts at closure Point A (from will show me closure type):

aggregate(layer:='closures_v1', aggregate:='max', expression:="type",
filter:= intersects( $geometry, start_point(geometry(@parent))))

and ends at closure Point B (to will show me closure type):

aggregate(layer:='closures_v1', aggregate:='max', expression:="type",
filter:= intersects( $geometry, end_point(geometry(@parent))))

Though I have not been able to autogenerate the fields for the closure layers' columns ingress and egress. ingress will represent the cable that is entering the closure (there can only be one), egress will represent the cable that is exiting the closure (there can be multiple). The autogenerated field will tell me the cable type.

Is this possible?

Let’s says I had one closure point called 'main closure', I will draw a cable (whatever I decide to label it, in this called 'cable IN') to end at the 'main closure' --- this will be my ingress cable.

Then, I draw two cables starting from the 'main closure'(I will label these 'cable out1' and 'cable out2').

I would like an automated process to auto-fill my ingress layer to tell me that 'cable IN' is the cable entering the 'main closure', and my egress layer to tell me that 'cable out1' and 'cable out2' are exiting 'main closure'.

enter image description here

4
  • 2
    Please explain your workflow more detailed. What are you trying to do when, based on which layer?
    – Erik
    Commented May 15, 2023 at 18:34
  • You mention code but have not presented any.
    – PolyGeo
    Commented May 15, 2023 at 19:33
  • 2
    A picture would really help explain this problem
    – Vince
    Commented May 16, 2023 at 14:10
  • Your question is a bit confusing, I hope I understood it well. You mention a layer closure, but in your expression, it is named closures_v1 - this adds to the confusion, as well that you don't tell us which of the attribute fields contains the name (like cable in). So we have to make a lot of assumptions. When asking a question, you should always be as clear as possible.
    – Babel
    Commented May 18, 2023 at 13:11

1 Answer 1

2
+25

To get the name (saved in field type) of the feature from the layer cable that enters the current point, use the expression below the screenshot. Use a virtual field to autogenerate the values. Like this, the value is updated automatically each time you change something.

Screenshot: the expression, used here as source of a dynamic label: enter image description here

array_filter (
    array_foreach(
        overlay_nearest ('cable', $id, limit:=-1),
        if (
            intersects (
                end_point (geometry (get_feature_by_id('cable',@element))),
                buffer ($geometry,0.01)
            ),
            attribute (get_feature_by_id ('cable',@element), 'type'),
            ''
        )
    ),
    @element <>''
)[0]

To get the name of the outgoing cables, replace end_point in line 6 with start_point and enclose the whole expression as argument in a array_to_string() function, pseudocode: array_to_string( [expression_from_above_changed_to_start_point])

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.