Given a points collection layer containing the data field ("DATADIA") with the date (YYYYY-MM-dd), how could I connect the nearest points in order of increasing date?

The expression should work with an expression for Geometry generator that draw a line.

I add a screenshot with a hand-made simulation of the expected result example

enter image description here

Unsuccessful solution attempt:

With the following SQL query to create a Virtual Layer that connects each point to its closest point with the first upper date I get the following result:

SELECT ST_ShortestLine(r.geometry, p.geometry) AS geom,
       p.DATETEMPS AS pid,
       r.DATETEMPS AS rid,
       ROUND(MIN(ST_Distance(r.geometry, p.geometry)),2) AS distance
FROM Layer_1 AS p, Layer_2 AS r
ORDER BY distance DESC

enter image description here

What modifications or corrections would have to be made so that the Virtual Layer query draw for each point its corresponding line as I show in this expected result?

enter image description here

  • 1
    Distance Matrix can do part of this, you most likely need to add an expression for dates docs.qgis.org/3.28/en/docs/user_manual/processing_algs/qgis/…
    – Mapperz
    Apr 19 at 17:44
  • 1
    I dont understand why all your features arent connected
    – BERA
    Apr 19 at 18:06
  • At the beginning, this example is handmade. Now I also observe that there is a point not connected (the point value 2023-04-22). This is an error. According to what I am looking for, this point should be connected to the nearest point with value 2023-04-23.
    – Acperience
    Apr 19 at 18:26
  • 1
    See here: gis.stackexchange.com/a/380598/88814
    – Babel
    Apr 19 at 20:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.