Based on spatial relationship
To do it based on spatial relationship, you can use one of the overlay functions, e.g. using one of the following expressions. The first two only work if the two lines are exactly the same (version 3 even considers line direction) - in many cases, even if they should be so, in fact they are not. In such cases, you might want to use the last version.
overlay_within('LayerA',"name_A")[0]
overlay_contains('LayerA',"name_A")[0]
overlay_equals('lineA',name)[0]
: this works only if the lines have the same direction (line A to B). For a line B to A, it will return NULL
overlay_nearest('lineA',name)[0]
: this works if lines or not completely equal: it takes the nearest line of Layer_A
to the one of Layer_B
Based on common id
To copy the content of field name_A
from LayerA
to a field in LayerB
, where you use a common id
-Filed - where the value of the id from LayerA (id_A
) correspods to the id value from LayerB (id_B
) - use this expression:
attribute (
get_feature_by_id (
'LayerA',
"id_B"
),
'name_A'
)