1

I try to project points onto a line layer. The line layer consists of lots of simple lines (I got it from Voronoj diagram, it is a center line of my polygon). I need to draw path from start point to end point following the polygon centerline and does not go beyond the polygon boundaries (it's important because the polygon can be very winding). When I created Voronoj diagram I cannot include start and end point here because the diagram goes around the points.

I tried very simple way to start with. I used geometry expression to project my point on middle line like the shortest path to line.

shortest_line($geometry, geometry(get_feature('line','unid',1)))

But it doesn't work. How can I create geometry expression for it?

enter image description here

Example data

https://drive.google.com/drive/folders/14jjiVjH3Z6VPX87QkjsQz2RcA26nxJGB?usp=sharing

1

1 Answer 1

3

Your line layer has a different CRS to your point layer, which is likely the reason the shortest_line function is not working.

You can collect together your line segments and perform a transformation within the shortest_line function like so:

shortest_line(
    @geometry, 
    transform(
        aggregate('line', 'collect', @geometry),
        'EPSG:3857',
        'EPSG:4326'
    )
)

The @geometry notation was introduced in QGIS 3.28. For earlier versions, use $geometry.

enter image description here

7
  • Yes, my expression differs from my layers because I got it from this gis.stackexchange.com/questions/246541/… and it didn't work. Thanks!
    – redhat
    Jan 25 at 8:42
  • Do you have any idea how to collect lines into 1 MultiString inside geometry expression? I have to merge them manually. I found that "collect" command can be good but I have no idea how to combine command "geometry(get_feature)" and "collect" because the current layer is a point layer and I need to collect different layer in geometry expression
    – redhat
    Jan 25 at 8:46
  • 1
    Is unid = 1 the entire center line skeleton, or is it a segment of that line? aggregate('line', 'collect', @geometry) is likely what you are looking for.
    – Matt
    Jan 25 at 8:57
  • 1
    See my updated expression. It's what used to make the screenshot.
    – Matt
    Jan 26 at 7:59
  • 1
    Glad to help. Good luck with your project.
    – Matt
    Jan 27 at 13:48

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.