1

I have two shapefiles: 'Lines' and 'Base-line'. One attribute inside 'Base-line' is the number of 'Lines' features overlapping that specific 'Base-line' feature. It basically represents the number of tubes inside the main pipeline.

A 'Lines' feature can be overlapped to a chain of many consecutive 'Base-line' features.

I need to fill the attribute in the 'Base-line' features after I trace all the 'Lines' over the already traced 'Base-line'.

The total number of 'Lines' overlapping the specific 'Base-line' will then be used by a Virtual layer to create and display labels for each 'Base-line'.

Both shapefiles share a common key representing the coordinates of the geometry.

I tried using something like

aggregate(layer:='LINES_9e784a1c_48d8_4510_a6a5_20967c6dff6c',
          aggregate:='concatenate',
          expression:=count("KEY"),
          concatenator:='',
          filter:=intersects($geometry,geometry(@parent))
          )

But I think it would only work if the 'Lines' features have already been traced before the 'Base-line' (which is not possible). Any suggestions?

UPDATE

enter image description here

Example: there are 3 BASE_LINE features. Two LINE features are overlapping the first and then they proceed in different directions to overlap different BASE_LINE features.

This is what I get using

array_length(overlay_crosses( 'CAVI', $id))

enter image description here

Where CAVI are the LINES.

1

Use this expression on the baseline layer and replace 'lines' with the name of your lines-layer (works for QGIS 3.16+):

array_length(overlay_crosses( 'lines', $id))

Screenshot: counting the number of red lines that cross each black baseline. For visualization purpose, here the expression is used directly in the label field, but you can use the same expression with field calculator to create a new field:

enter image description here

6
  • Hi, thank you for your answer. I tried a couple of ways to use this function but I always get 'false'. I tried both writing only the layer name or the full name I find in properties overlay_crosses(layer:='LINES_707e57a2_4492_40b8_b982_55e7327b98e4').
    – Phil
    Jul 16 at 21:13
  • whicht QGIS version? It must be 3.16 or later. Did you use the whole expression? array_length(overlay_crosses( 'lines', $id))
    – Babel
    Jul 16 at 21:34
  • Yes, I opened the project with 3.16 and tried to update the field using the whole expression but I get zero. I posted a picture with an example
    – Phil
    Jul 16 at 21:47
  • Did you also try using the field calculator? docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/… Can you post a screenshot showing the lines + the layet panel with the names of the layers?
    – Babel
    Jul 17 at 6:08
  • I see: your lines do not cross the baseline, they at best touch it. Even that might not be the case. Try using overlay_touches instead of overlay_crosses or extend your lines a bit, using geometry by expression with the function extend docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/… then convert multi- to singleparts
    – Babel
    Jul 17 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.