QGIS – Calculating Distance from Point to Line by Unique ID

attribute-joinsdistanceproximityqgisunique id

I have four points of interest for each plot, a line representing the segment that faces the road and the plots themselves for representation purposes (all of them share in common an unique "id" to differentiate each plot). It is needed to calculate the distance from each red point to the segment of the plot that faces the road for each plot.

I have tried "Distance to nearest hub", and "Point to line distances (SAGA)" but the problem in these cases is that the distance is calculated to the closest line (direction of the red arrows), and it does not take into consideration the unique "id" of each plot and its correct direction to measure distance (green arrows).

Is there any way to calculate the distance for each red point to their line counterpart?

The solution must be a tool that can be added to a model in Graphical Modeler. I can change the line into point with interpolation if it is needed.

Example:

enter image description here

Example of directions:

enter image description here

Best Answer

You can create a "Virtual Layer", that will join the two layers by plot "ID" then compute the distance:

Go to the menu Layer > Add Layer > Add/Edit Virtual Layer... and enter the query:

SELECT pt.plotID, pt.id, 
       ST_Distance(pt.geometry, ln.geometry) AS distance
FROM point_layer AS pt
JOIN line_layer AS ln 
  ON pt.plotID = ln.plotID;
Related Question