3

I want to extract a section of a route. My base data are route polylines and kilometer points with kilometerinformation along the route. Suppose I want to automatically create the route segment from kilometer 103 to 108 as a separate line-layer. What approach can I take? route exapmle

3
  • 1
    Are the points exactly above the vertices of the line or above the segment?
    – Mayo
    Jan 22, 2023 at 2:08
  • This is a linear referencing task, have a look at the LRS plugin that will handle this
    – J.R
    Jan 22, 2023 at 10:16
  • hello Mayo. The points are above the segment... Hello J.R. Thanks for the hint with LRS. I have to look into that, seems it's not as self-explaining, as I hoped...
    – Marek
    Jan 22, 2023 at 16:49

1 Answer 1

5

This can be achieved using the Geometry by Expression tool. Run this expression on your line layer. Make sure to select Line as the output geometry type:

Tool parameters

enter image description here

Expression
-- make variables of the start and end points (not necessary but is more convenient when changing the values)
with_variable('start', geometry(get_feature('points', 'kilometer', 103)),  -- change the 'points' layer name here to suit your project
    with_variable('end', geometry(get_feature('points', 'kilometer', 108)),  -- change the 'points' layer name here to suit your project
        
        -- substring the current line using the distances calculated below
        line_substring(
            $geometry,
            
            -- find the distance along the line of the closest point on the line to the start point
            line_locate_point(
                $geometry,
                closest_point(
                    $geometry,
                    @start
                )
            ),

            -- find the distance along the line of the closest point on the line to the end point
            line_locate_point(
                $geometry,
                closest_point(
                    $geometry,
                    @end
                )
            )
        )
    )
)
Result

enter image description here

By using the additional closest_point function (rather than inputting the @start and @end points directly into the line_locate_point functions) the expression handles situations where your kilometer marker points are not exactly on your line features.

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.