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?
-
1Are the points exactly above the vertices of the line or above the segment?– MayoCommented Jan 22, 2023 at 2:08
-
This is a linear referencing task, have a look at the LRS plugin that will handle this– J.RCommented 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...– MarekCommented Jan 22, 2023 at 16:49
Add a comment
|
1 Answer
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
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
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.