Skip to main content
added 31 characters in body
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59

The first expression works for situations where there is only oneonly one intersection point per feature on Layer B. The second expression works when there are multiplemultiple intersection points per feature on Layer B.

Single intersection point

Single intersection point per feature

Multiple intersection points per feature

The first expression works for situations where there is only one intersection point per feature on Layer B. The second expression works when there are multiple intersection points per feature on Layer B.

Single intersection point

Multiple intersection points

The first expression works for situations where there is only one intersection point per feature on Layer B. The second expression works when there are multiple intersection points per feature on Layer B.

Single intersection point per feature

Multiple intersection points per feature

added 1643 characters in body
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59

You can use either of the following expressionexpressions - 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).

The first expression works for situations where there is only one intersection point per feature on Layer B. The second expression works when there are multiple intersection points per feature on Layer B.

Single intersection point

enter image description here

Multiple intersection points

⚠️ Be aware: due to the nature of Geometry Expressions, this will create a MultiLineString with duplicated geometries. You will need to run Multipart to Singleparts and then Delete Duplicate Geometries on the output to clean it up.

-- 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
    ),
    
    -- collect the array of geometries into a MultiLineString
    collect_geometries(
        -- loop through each intersection point per Layer B feature
        array_foreach(
            -- convert the MultiPoint intersection geometry into an array of geometries 
            geometries_to_array(@i),
            
            -- find the distance of the intersection along the Layer B feature
            with_variable('dist_along', 
                line_locate_point(@geometry, @element),         
                
                -- generate a line that follows Layer B spanning 100 m either side of the intersection
                line_substring(@geometry, @dist_along - 100, @dist_along + 100)
                
            
            )
        )
    )
    
)

enter image description here

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).

enter image description here

You can use either of the following expressions - 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).

The first expression works for situations where there is only one intersection point per feature on Layer B. The second expression works when there are multiple intersection points per feature on Layer B.

Single intersection point

enter image description here

Multiple intersection points

⚠️ Be aware: due to the nature of Geometry Expressions, this will create a MultiLineString with duplicated geometries. You will need to run Multipart to Singleparts and then Delete Duplicate Geometries on the output to clean it up.

-- 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
    ),
    
    -- collect the array of geometries into a MultiLineString
    collect_geometries(
        -- loop through each intersection point per Layer B feature
        array_foreach(
            -- convert the MultiPoint intersection geometry into an array of geometries 
            geometries_to_array(@i),
            
            -- find the distance of the intersection along the Layer B feature
            with_variable('dist_along', 
                line_locate_point(@geometry, @element),         
                
                -- generate a line that follows Layer B spanning 100 m either side of the intersection
                line_substring(@geometry, @dist_along - 100, @dist_along + 100)
                
            
            )
        )
    )
    
)

enter image description here

added 229 characters in body
Source Link
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 hereenter 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.

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(
        aggregate('Layer A', 'collect', @geometry),
        @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.

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.

adjusted expression to output a line and updated screenshot
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
Loading
adjusted expression to output a line and updated screenshot
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
Loading
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
Loading