Skip to main content
4 of 6
added 229 characters in body
Matt
  • 17.9k
  • 4
  • 23
  • 59

You can use the following expression - Either as a Geometry Generator symbol layer (on Layer B) or by using the Geometry by Expression geoprocessing tool if you wish to create a new layer with the results (used also on Layer B).

-- find the intersection of the line layers and assign it to a variable
with_variable('i',
    intersection(
        -- a small extension is applied to Layer A to ensure there is a true intersection with Layer B.
        -- the extension is applied at both ends so that the direction of the line does not need to be known
        aggregate('Layer A', 'collect', extend(@geometry, 1, 1)),
        @geometry
    ),
    
    -- get the distance of the intersection along Layer B's geometry
    with_variable('dist_along', 
        line_locate_point(@geometry, @i),

        -- generate the line that spans 100 m either side of the intersection
        line_substring(@geometry, @dist_along - 100, @dist_along + 100)
    )
)

enter image description here

Note, when using either a Geometry Generator symbol layer or the Geometry by Expression tool, don't forget to set the output geometry type to LineString / MultiLineString or Line respectively.

Matt
  • 17.9k
  • 4
  • 23
  • 59