QGIS – How to Remove 3m Along a Line

lineqgis

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

Best Answer

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

Related Question