1

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

Taras
  • 32,823
  • 4
  • 66
  • 137
Marin Marian
  • 55
  • 10
  • Have you tried using a filter or selection query prior to running the point to line distance tool? If you create a filter based on the point layer unique ID, as well as on the lines layer unique ID (which I assume are the same), then the point to line distance tool will always result in the intended outcome. You could then iterate over all unique ideas and merge the results. – PGerrits May 13 '22 at 11:56
  • Sorry, but I am missing the red and green arrows. Could you provide a screenshot containing them? – Erik May 13 '22 at 12:01
  • I have thought of some kind of iteration based on unique id, but there are thousands of features with each unique id and I do not know how to make this process repeatable for each feature in a graphical modeler. – Marin Marian May 13 '22 at 12:03
  • I have updated the question with the image with good directions to measure distance (green) and the directions that are taken into consideration (red). – Marin Marian May 13 '22 at 12:05
  • 1
    Check this thread : https://gis.stackexchange.com/questions/181636/nearest-distance-between-point-and-line-layers-in-qgis – Taras May 13 '22 at 12:13
  • Suggestion that might work better than I suggested above in the comments, is the following:
    1. Convert your segment that faces the road to points using the lines to points tool. You can provide an appropriate distance for the points, to make sure that it remains accurate.
    2. Use the tool Distance Matrix to calculate the distance between the two point datasets. Distance Matrix allows you to set the Unique feature IDs.
    – PGerrits May 13 '22 at 12:13
  • I have tried distance matrix with the unique id, in some cases works but on clustered plots with many lines that faces the road, it messes them up. I am reading the thread right now (https://gis.stackexchange.com/questions/181636/nearest-distance-between-point-and-line-layers-in-qgis) most voted solution was distance to nearest hub and that does not measure the distance based on a specific value, just by nearest. – Marin Marian May 13 '22 at 12:35
  • It is hard because it is not about the nearest point, it is about calculating the distance from point to the road for each plot. – Marin Marian May 13 '22 at 12:37

1 Answers1

3

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;
Taras
  • 32,823
  • 4
  • 66
  • 137
JGH
  • 41,794
  • 3
  • 43
  • 89
  • I think your query is not full in terms of N:M, however, it will work in terms of N:1. – Taras May 13 '22 at 14:10
  • @Taras yes, I understood that there is a single "road face" segment per plot – JGH May 13 '22 at 14:41
  • 1
    Regarding the "Virtual Layer in Graphical Modeler" check this : https://gis.stackexchange.com/q/240210/99589 – Taras May 16 '22 at 05:31
  • Thank you very much! The query works fine, now I am checking to implement in into graphical modeler! – Marin Marian May 16 '22 at 06:38