39

I have a point layer and need to draw a line passing through or in the vicinity of the points (up to 0.5m distance between the point and the line). The nodes of the line will receive the attributes of the points closest to them.

4 Answers 4

27

The simplest way is to use the points to create the line. To do this in QGIS use the Points2One plugin. Install this plugin (available via Plugins > Manage and install plugins) and follow the dialog to create a line from your points.

Points2One window

If you have multiple lines, then make sure your points data has a suitable ID field to identify the lines they belong to.

Alternatively you can use v.build.polylines in GRASS (available through QGIS) or the SAGA GIS tool Convert points to line(s) Available through the Processing Toolbox (Ctrl+Shift+T).

2
  • 10
    The Points2One plugin is not available for the current release of QGIS (3.4.4). Feb 18, 2019 at 16:50
  • points2one fails for hard to tell reasons in 3.22.3, and needs to be installed from .zip. So the inbuilt alternatives (processing toolbox) are to be preferred, but it is surprisingly hard to define a line outside a feature set for (in my case) debugging purposes.
    – Jan
    Feb 23 at 19:03
24

To create polygons from points, you can also use

  1. "Points to path", then
  2. "Lines to polygons" tools without need to install any plugin
3
  • Where do you find the "points to path" tool?
    – Udi
    Jun 2, 2018 at 18:10
  • 1
    Go to processing and click Toolbox or "Ctrl + Alt +T" to search tools , then type "Points to path" and you will see the tool.
    – ncelik
    Jun 3, 2018 at 20:36
  • Not available in 2.8.6-Wien Mar 6, 2019 at 15:48
8

In QGIS 3.x instead of the plugin mentioned above, you can find the "Points to path" tool in your Processing Toolbox (Ctrl+Shift+T). Works exactly the same...

enter image description here

2

The Points2One plugin last version is from 2015 and as has been commented, isn't working in the current QGIS 3.x versions. I'm posting an alternative solution that I have also answered here.

One way to do this would be using a "Virtual Layer".

  1. Create "X" and "Y" fields in your point layer containing the x and y coordinates
  2. Create a constant field with the same value
  3. Save a copy of the point layer
  4. Add a virtual layer joining by the constant value of both layers (original and copy) using the following expression:
SELECT *
FROM points
JOIN points_copy
    ON points.constant = points_copy.constant

This will create a Virtual Layer that will contain every combination of X,Y origin and destination coordinates. In my example I used 29 points thus resulting in a virtual layer of 841 points (29²).

All points to all

Just for symbolization purposes the point layer can be symbolized into lines using a geometry generator expression:

make_line(make_point("cx", "cy"), make_point("cx:1", "cy:1"))

To make a permanent layer I recommend using the tool XY to line from the plugin Shape Tools.

In this particular case the OP asked to limit the distance to 0.5 m which can be accomplished filtering the lines by length.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.