1

This question is almost identical to my previous question. However, instead of placing a point at each vertex, I would like to place a point at a specified distance from each vertex (start offset, end offset)

For example, I would like 36 points along a group of lines, each with slightly different lengths. The start point and end point is 1.5 feet inward from each line vertex.

I tried using the Points Along Geometry tool. With the Distance field set to and also $length/37 and the Start Offset and End Offset set to 1.5. All also tried with the Distance set to ($length/37)-0.0001.

Points Along Geometry Output

I tried Geometry by Expression with the expression..

collect_geometries( array_foreach( generate_series(1.5, $length-1.5, $length/37-0.0001), line_interpolate_point( $geometry, @element)))

..but was not able to achieve the desired results.

2
  • What was the undesired result that you got?
    – user30184
    Commented Mar 23, 2023 at 22:08
  • I would like the first point on each line and the last point on each line to be the same distance from the vertices of the line. The picture I posted with my question shows that none of the lines meet this criteria.
    – GNG85
    Commented Mar 24, 2023 at 23:08

1 Answer 1

4

There are two problems in your approach:

  1. $length calculates ellipsoidal distances. So you might want to use length($geometry) to get planimetric distances. Depending on what CRS you use and what distances you have, that might play a role or not.

  2. Generate a series from 0 to 35 (36 points) and multiply this with the interval. Be aware: there are 35 intervals for 36 points. So the length of the interval is: line's length minus 3 (for 1.5 offset at start and end), divided by 35. Then add to this the start offset of 1.5 and multiply the @element for each point with the interval.

This is the expression to use:

collect_geometries( 
    array_foreach( 
        generate_series(0,35), 
        line_interpolate_point ($geometry,1.5+@element*(length($geometry)-3)/35)
    )
)

Demonstration for 26 points and offset of 15 from start-/endpoints: enter image description here


Variant:

To easily change the no. of points and the offset, use variables.Change the values of 36 and 1.5 on lines 1 and 2 and the expression will automatically adapt:

with_variable('no_of_points',36,  -- change here
with_variable('offset',1.5,  -- change here
collect_geometries( 
    array_foreach( 
        generate_series (0,@no_of_points-1), 
        line_interpolate_point (
            $geometry,
            @offset + @element * (length ($geometry) - 2 * @offset) / (@no_of_points-1))
    )
)))
1
  • 1
    Wonderful, I understand more now about how the arguments work in this expression. Thank you for the in-depth explanation.
    – GNG85
    Commented Apr 5, 2023 at 15: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.