Suppose we want to interpolate a number of points along each line in a layer:
We have a column called stations
that specifies how many points to
interpolate on each line:
We can use QGIS virtual layers to create a new layer containing the interpolated points:
select
line_interpolate_equidistant_points(geometry, st_length(geometry)/ (stations+1) ) as geometry,
*
from origlines
Note that we first calculate the new geometry, then select all the remaining columns with *
.
To use this query:
- Layer menu > Add layer > Add/edit virtual layer
- Specify the "Layer name" for the new layer
- Paste the code above into the "Query" box
- Click "Add"
Note that the new layer is virtual, and is dynamically generated from the "origlines" layer. To save it permanently, right-click and "Save as..."
Also, all the points along a single line are multipoints, and part of a single multipoint feature. If you want separate records for each point, you can use the "Multipart to singleparts" tool, found in the Processing Toolbox.