Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kgjenkins
Last active June 24, 2020 22:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgjenkins/ba4208abab23df2791e639aa657342fe to your computer and use it in GitHub Desktop.
Save kgjenkins/ba4208abab23df2791e639aa657342fe to your computer and use it in GitHub Desktop.
Straighten lines in a layer using QGIS virtual layers

Straighten lines in a layer using QGIS virtual layers

Suppose we have a layer of wiggly lines (black), and we want to straighten the lines (blue):

image

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"

image

Note that the new layer is virtual, and is dynamically generated from the "origlines" layer. To save it permanently, right-click and "Save as..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment