3

I am searching for a tool or a combination of tools in QGis to get done some line-cuttings. They have to follow some rules:

  1. Lines should be cut at the borders of a raster. For example, the purple line in picture 1 should be cut into 4 pieces as can be seen in picture 2 (rasters 5-8).

  2. Lines that leave a raster and enter the same raster afterwards should be cut into 2 separate lines (e.g. the red line in raster 1).

  3. Lines that leave a raster and enter the same raster afterwards AND cross themselves inside this raster should not be cut by the line itself (e.g. the yellow line in raster 3) but only by the raster-borders.

picture 1 - start picture 1

picture 2 - what I try to get picture 2

So here's what I got so far:

I managed to cut lines (picture 1) by raster-borders to get line-pieces for each raster. Therefor I used the intersection-tool. The result is shown in picture 3. Using then "multipart features to single parts" the red line in raster 1 is cut into 3 pieces and the yellow line in raster 3 is cut into 6 pieces as shown in picture 4.

If you have a look at picture 2 again, the red line in raster 1 should only be cut into 2 pieces and the yellow line in raster 3 should be cut into 3 pieces.

picture 3

picture 3

picture 4 - what I got

picture 4

3
  • 3
    Please have a look at explode lines in the toolbox. It should do exactly what you're looking for in step 3.
    – Erik
    Dec 10, 2020 at 14:55
  • Thanks @Erik. Explode lines is not the right tool. Using it the line is seperated into multiple pieces. What I try to get are continous lines from raster border to raster border (picture 2).
    – Leo
    Dec 11, 2020 at 7:31
  • 1
    Yeah, now your question is better structured.
    – Erik
    Dec 11, 2020 at 7:40

1 Answer 1

1

Short answer

The SAGA tool line-polygon intersection does the job: Menu Vector / Processing / Line-polygon intersection, see result:

enter image description here

Compare with the original line and the settings I used:

enter image description here

Specific problem - and how to overcome it

Using the data you provided, there is however a problem. In several cases, e.g. in grid cell no. 7, no line is created at all. Inspecting the data, the reason is because the line that crosses grid 7 has no vertex inside of 7 - all vertices lie outside, in grid cell no. 5 (extremely close to the border with 7) and in cell no. 8.

For this reason, you can use Menu Vector / Processing / Densify by interval to generat a new line with more vertices. Just define the interval in such a way that for sure every part of your line that finally should become a separate feature contains at least one vertex. With this line, now you can use Line-polygon intersection as describe.

enter image description here

In a first (failed) attempt to find a solution, I created points with Menu Vector / Processing / Line intersections to get the intersection points - maybe that could lead to another way to find a solution.

enter image description here

11
  • OK, so what is left to be resolved?
    – Babel
    Dec 11, 2020 at 10:46
  • This gets me really close to what I need! By using line-polygon-intersection I got the right pieces of lines. Now there pops up another Problem. After running the tool some pieces are missing completely. In my case the line going through raster n.7. In the previous and the following raster the line appears.
    – Leo
    Dec 11, 2020 at 10:51
  • Strange - is there something wrong with raster nr. 7 (e.g. no unique id)?
    – Babel
    Dec 11, 2020 at 10:53
  • Why do you think the line in raster no. 7 is missing? Is it just a visualization problem? I had this too when creating my output and setting random colors: one line was in a very light yellow, barely visible. Or did you otherwise datermine that there is really a line missing?
    – Babel
    Dec 11, 2020 at 10:56
  • I used create grid (extend input -> line-layer) which automatically creates a unique id for each feature. I can't select any line in raster nr. 7 because there is no - really strange. Changing symbology doesn't help in this case.
    – Leo
    Dec 11, 2020 at 11:17

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.