0

I have multiple bufferstops on railways. I want to cut out 3m (1,5 m in each direction along the rails) of the railway lines with the buffer stop in the middle. Buffering does not work here because, I do not want to touch lines next to each other. The railway lines may have more than up bufferstop. It is not certain if the bufferstops are exactly on the lines. some bufferstops are not even on the desired railways in red. I checked with select by expression and overlay disjoint if the points are really on the lines. Does not look like it (for the yellow ones). I am using OSM data. How can I do this (something like buffer along a line)?

enter image description here enter image description here

with the suggested solution below, QGIS is working but not returing the correct lines.

My project and the geopackage with the bufferstops and the rails: Railwayproject

I used: enter image description here

result:

-Solved- It is important not to use the suggestionbox in "geometry by expression" but the same name as in the layer. So using the suggestion box does not work for me.

enter image description here

enter image description here

12
  • 1
    I stronlgy doubt the tracks are closer than 1.5 m to each other. So feel free to buffer and use difference.
    – Erik
    Commented Aug 29, 2022 at 15:58
  • true but I want to do this for other larger objects (switches, crossings) too.
    – BAE_23
    Commented Aug 30, 2022 at 20:54
  • What means does "not returing the correct lines"? Can you show the result? Otherwise it's difficult to help. You also did not mention you have more than one points on each line. This expression works for one point per line. Please provide more information in your question about your exact setting. Otherwise, the answer will not fit your exact use case.
    – Babel
    Commented Aug 30, 2022 at 21:17
  • 1
    I tried the solution with the data+project you provided and it works fine. Are you sure you made adaptaption of point layer accordingly? Line 5 must be: overlay_nearest ('bufferstops', $geometry, limit:=1)[0]. See second screenshot in my updated answer. Check if it works the same for you.
    – Babel
    Commented Sep 1, 2022 at 12:47
  • 1
    I guess the "suggestionbox" (as you name it) does not work because you have the layer name inclosed in two single quotes (as I can see on your screenshot): overlay_nearest (''bufferstop_e5c.....''. It should be only one single quote: overlay_nearest ('bufferstop_e5c.....' - like this, it should work with the simple layer name of the "suggestionbox" as well. See: i.sstatic.net/olQOw.png
    – Babel
    Commented Sep 1, 2022 at 15:37

1 Answer 1

3

Use QGIS expression with Geometry generator or Geometry by expression. Use this expression on the railway line layer and replace point (line 5) with the name of your point (bufferstop) layer:

with_variable(
    'stop',
    line_locate_point ( 
        $geometry, 
        overlay_nearest ('point', $geometry, limit:=1)[0]
    ),
    difference (
        $geometry,
        buffer (
            line_substring (
                $geometry, 
                @stop-1.5,
                @stop+1.5
            ),0.1
        )
    )
)

The red line is created based on the black line, but cutting out a distance to both sides of the point: enter image description here

enter image description here

2
  • synatax seems correct but returns not the wanted geometry. for point I insert the bufferstop and apply this to my railway layer? "your line layer" confuses me a bit. the bufferstop are not lines?!
    – BAE_23
    Commented Aug 30, 2022 at 20:37
  • Sorry, I meant point layer, see updated answer. Does it work? If not, can you provide more details, screenshot etc.? Otherwise it's difficult to see what goes wrong.
    – Babel
    Commented Aug 30, 2022 at 20:47

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.