I have layer of points of which I need to build lines. Standart Points to path function doesn't suit me. I have data on time, but it does not reflect the order of connection that I need. I need to connect them by distance. That is, if the distance between two points is less than 10 meters - draw a line. Is it possible?
If you don't mind working with QGIS' natively supported SQLite dialect, this breaks down to a trivial self-
JOIN on the distance threshold:
- either create a Virtual Layer, or use the DB Manager
run (assuming your point source layer is called
pts, and has an
SELECT a.id, b.id, MakeLine(a.geometry, b.geometry) AS geometry FROM pts AS a JOIN pts AS b ON ST_Distance(a.geometry, b.geometry, 1) < 10 WHERE a.id <> b.id ;
The optional third parameter to
use_ellipsoid BOOLEAN), if given, will force the function to calculate distances based on a sphere (
use_ellipsoid=0) or spheroid (
use_ellipsoid=1), rather than on the Cartesian plane; this requires the geometries to be in a geographic reference, but works on meter as unit instead of the unit of the underlying CRS.
Note that this effectively aggregates attributes from two rows; the natively compiled SQLite version doesn't have any array support other than string concatenation. I simply added the
id of both points to the output as reference; you could e.g. use the timestamp here.