I have a line ('line 1' for example) that sits on top of another set of lines in a separate layer ('line 2' we shall name it). 'Line 2' has within it a field for IDs. What I need is to populate a field within 'line 1' with a list of all the instances of 'line 2' that they intersect with.

So for example 'Line 1' shares space with 'line 2.1', 'line 2.2' and 'line 2.3'. How can I get the field in line one to be a list of the relevant IDs from lines 2.1 , 2.2 and 2.3.

I've tried overlay intersects and this brought back nothing. I've also tried making a buffer so I could use that to select all the sections of 'line 2' but couldn't work that out either.

  • I would do it with the tool "selection by location" after all lines are merged in one shp and it's copy (so you compare the whole shp with the selected ones). This would be the step-by-step option. In case you want something automatic, PostgreSQL/Postgis will be an option.
    – Gery
    Aug 25, 2021 at 18:43
  • ive managed to get a merge of line 1 and lines 2.1 2.2 and 2.3 but they are all seperate items and i have a lot of them to do this for so was hoping it could be automated in someway
    – snakey866
    Aug 25, 2021 at 18:46
  • isnt the linked question only in relation to polygons? im working with lines here and im useless with writing expressions. its been a very long day
    – snakey866
    Aug 25, 2021 at 19:46
  • @snakey866 the answers are about geometries in a layer intersecting with geometries in another layer. It doesn't matter whether they are points, lines, polygons or their multi versions
    – JGH
    Aug 25, 2021 at 20:07

1 Answer 1


The expression overlay_intersects() returns an array. You have to convert it to a string. Use this expression:

 array_to_string(overlay_intersects('line_2', $id))

enter image description here


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.