1

I want in QGIS 3.22 Geometry Generator to connect related points with a line, but the line must go between the points along the shortest network of paths. I have two layers:

  • one is "points" point type layer and every feature has 'name' and 'parent' field. The 'parent' field shows which point 'name' on the same layer the given point is related to.
  • the second is a "roads" line type layer (brown) with a network of roads

this code generates a straight line

make_line( 
$geometry ,  
geometry( 
    get_feature( 'points', 'name' , 'Parent')
)

)

I want the given line to run along the shortest path on the road layer (brown) network. The picture shows that the point is not located directly on the road, the algorithm must find the nearest road and connect it with a line. Something like this as code

closest_point( 
collect_geometries ( 
    overlay_nearest( 
        'roads', 
        $geometry
    )
),
$geometry

)

enter image description here

10
  • I don't want to use processing tools ... i want that the connection lines are changing dynamically if points are displaced.
    – Rii Pii
    Aug 25, 2022 at 15:00
  • If the network would consist of simple lines, then it would be easy to use line_sunstring () and line_locate_points(), together with what you have (closest_point()) to achieve that. However, for a network layer consisting of mulitpart or several different layers, I don't see an easy solution as there are no network/routing functions in QGIS expressions.
    – Babel
    Aug 25, 2022 at 21:10
  • Probably using a Virtual layer or PostGIS, this can be achieved
    – Babel
    Aug 25, 2022 at 21:12
  • What do you mean "simple lines"? But what about simplifying the road network into more straight lines? I don't want to measure the distance along the road so much, but to more realistically visualize the connections between the points. Babel could you describe your idea in code, that would help me a lot!
    – Rii Pii
    Aug 27, 2022 at 6:47
  • Does the lines have some direction (one way) or it doesn't matter?
    – Mayo
    Dec 16, 2022 at 22:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.