Skip to main content
Fixed typo
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
-- make variable from array of all distances of intersecting points
with_variable(
    'distarray',
    overlay_intersects(
        'points', 
        "distance"
    )
    ,
    -- make variable of the geometry of the point with minimum distance
    with_variable(
        'start',
        array_filter(
            overlay_intersects(
                'points', 
                array("distance", $geometry)
            ),
            @element[0] = array_min(@distarray)
        )[0][1],
        
        -- make variable of the geometry of the point with maximum distance
        with_variable(
            'end',
            array_filter(
                overlay_intersects(
                    'points', 
                    array("distance", $geometry)
                ),
                @element[0] = array_max(@distarray)
            )[0][1],
            
            -- make variable of the route intersecting the area polygon
            with_variable(
                'intersectline',
                intersection($geometry, aggregate('route', 'collect', $geometry)),
            
                -- get length of line between the start of the intersecting route and the first point and subtract it from the minimum point distance
                round(array_min(@distarray) - line_locate_point(@intersectline, @start), 1) 
                
                -- concatenate the two resulting values into a string, separated by a comma
                -- of course, the two values can be calculated separately into two different fields if you prefer
                || ', ' || 
                
                -- get length of line between the end of the intersecting route and the last point and add it to the maximum point distance
                -- the line is reversed so that `line_locate_point` starts at the other end of the intersecting route
                round(array_max(@distarray) + line_locate_point(reverse(@intersectline), @end), 1)
            
            )
        )
    )
)
-- make variable from array of all distances of intersecting points
with_variable(
    'distarray',
    overlay_intersects(
        'points', 
        "distance"
    )
    ,
    -- make variable of the geometry of the point with minimum distance
    with_variable(
        'start',
        array_filter(
            overlay_intersects(
                'points', 
                array("distance", $geometry)
            ),
            @element[0] = array_min(@distarray)
        )[0][1],
        
        -- make variable of the geometry of the point with maximum distance
        with_variable(
            'end',
            array_filter(
                overlay_intersects(
                    'points', 
                    array("distance", $geometry)
                ),
                @element[0] = array_max(@distarray)
            )[0][1],
            
            -- make variable of the route intersecting the area polygon
            with_variable(
                'intersectline',
                intersection($geometry, aggregate('route', 'collect', $geometry)),
            
                -- get length of line between the start of the intersecting route and the first point and subtract it from the minimum point distance
                round(array_min(@distarray) - line_locate_point(@intersectline, @start), 1) 
                
                -- concatenate the two resulting values into a string, separated by a comma
                -- of course, the two values can be calculated separately into two different fields if you prefer
                || ', ' || 
                
                -- get length of line between the end of the intersecting route and the last point and add it to the maximum point distance
                -- the line is reversed so that `line_locate_point` starts end of the intersecting route
                round(array_max(@distarray) + line_locate_point(reverse(@intersectline), @end), 1)
            
            )
        )
    )
)
-- make variable from array of all distances of intersecting points
with_variable(
    'distarray',
    overlay_intersects(
        'points', 
        "distance"
    )
    ,
    -- make variable of the geometry of the point with minimum distance
    with_variable(
        'start',
        array_filter(
            overlay_intersects(
                'points', 
                array("distance", $geometry)
            ),
            @element[0] = array_min(@distarray)
        )[0][1],
        
        -- make variable of the geometry of the point with maximum distance
        with_variable(
            'end',
            array_filter(
                overlay_intersects(
                    'points', 
                    array("distance", $geometry)
                ),
                @element[0] = array_max(@distarray)
            )[0][1],
            
            -- make variable of the route intersecting the area polygon
            with_variable(
                'intersectline',
                intersection($geometry, aggregate('route', 'collect', $geometry)),
            
                -- get length of line between the start of the intersecting route and the first point and subtract it from the minimum point distance
                round(array_min(@distarray) - line_locate_point(@intersectline, @start), 1) 
                
                -- concatenate the two resulting values into a string, separated by a comma
                -- of course, the two values can be calculated separately into two different fields if you prefer
                || ', ' || 
                
                -- get length of line between the end of the intersecting route and the last point and add it to the maximum point distance
                -- the line is reversed so that `line_locate_point` starts at the other end of the intersecting route
                round(array_max(@distarray) + line_locate_point(reverse(@intersectline), @end), 1)
            
            )
        )
    )
)
added 25 characters in body
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
  • route: is your line layer
  • area: is your polygon layer
  • points: is your points layer (with a field called distance - I use meters but- to use km you will work just as wellhave to convert in the expression)
  • route: is your line layer
  • area: is your polygon layer
  • points: is your points layer (with a field called distance - I use meters but km will work just as well)
  • route: is your line layer
  • area: is your polygon layer
  • points: is your points layer (with a field called distance - I use meters - to use km you will have to convert in the expression)
added 196 characters in body
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59

Where:

  • route: is your line layer
  • area: is your polygon layer
  • points: is your points layer (with a field called distance - I use meters but km will work just as well)

Where:

  • route: is your line layer
  • area: is your polygon layer
  • points: is your points layer (with a field called distance - I use meters but km will work just as well)
added some comments to clarify expression
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
Loading
added 12 characters in body
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
Loading
added 862 characters in body
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
Loading
Source Link
Matt
  • 17.9k
  • 4
  • 23
  • 59
Loading