6

With two layers, one multiline and one point, I need to split lines who intersect point layer.

In example (image), the selected line is unique but I need 11 lines cut at point level.

enter image description here

How can I do this with QGIS?

Taras
  • 32,823
  • 4
  • 66
  • 137
pasqal
  • 508
  • 3
  • 12

2 Answers2

9

Let's assume there are two layers 'lines_test' (blue) and 'points_test' (orange), see image below.

input

Step 1. By means of the "Geometry by expression" with the following expression:

make_line($geometry, translate($geometry, 10, 10))

window

create tiny lines starting/ending at those points

step_1

On this step a smarter approach may be required, thus tiny lines should not overlap with initial lines. I would probably refer to these threads then: Perpendicular lines on line using QGIS and Creating line segments at point coordinates in QGIS.

Step 2. Use the "Split with lines" with the result from the Step 1 and get the final output

step_2

Taras
  • 32,823
  • 4
  • 66
  • 137
8

Using only QGIS native tools, you can convert the points to small, auxiliary lines, perpendicular to the line you want to split. Then use Split with lines.

To create the auxiliary lines, use this expression with Geometry by Expression on the line layer. Replace point (line 4) with the name of your point layer:

collect_geometries (
    array_foreach (
        aggregate( 
            'point', 
            'array_agg', 
            $geometry
        ),
        extend (
            make_line(
                line_interpolate_point( 
                    $geometry,
                    line_locate_point($geometry,@element)
                ),
            project (
                 line_interpolate_point( 
                    $geometry,
                    line_locate_point($geometry,@element)
                ),
                10,
                radians(
                    90+line_interpolate_angle( 
                        $geometry,
                        line_locate_point($geometry,@element)
            )))),
            10,
            0
)))

Use the newly created auxiliary lines to split the initial line into segments.

Screenshot: the small red auxiliary lines are created (here: with geometry generator) on the line-layer, based on the points. As you see from the colors, the line is then split at these points:

enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208
  • 1
    as mentioned in this question https://gis.stackexchange.com/questions/475866/geometry-by-expression-does-not-work-after-intersection/ could I suggest an edit to change the $geometry in the aggregate() function to geometry_n($geometry,1) so that it works with multipoint layers? Also an alternative approach of using overlay_nearest() instead of aggregate() (with limit:= -1 and some max_distance parameter) so that it can work even if there is >1 feature in the line layer. – she_weeds Feb 15 '24 at 02:44
  • 1
    actually maybe it should be if(is_multipart($geometry),geometry_n($geometry,1),$geometry)) because geometry_n() returns null if it's not multipart. – she_weeds Feb 15 '24 at 03:18
  • Great! Feel free to add this as an additional solution – Babel Feb 15 '24 at 08:25