Suppose we have a layer of wiggly lines (black), and we want to straighten the lines (blue):
We can use QGIS virtual layers to create a new layer of straightened lines:
select
make_line(start_point(geometry), end_point(geometry)) 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..."