[GIS] Finding line with minimum distance to point and update attribute of points

distancegrasslinepointqgis

I am currently working with QGIS 2.18 and I have two layers: one layer is filled with lines which represent streets. The second layer describes the location of sensors which are represented as points like in the image below:
enter image description here

Each point has its own attribute values like followed:
enter image description here

As you can see, the attribute edgeid is still empty and I want to fill it with the id of the nearest street. Each line in the street-line-layer has an edgeid as followed:
enter image description here

Now I will have to determine the street with the shortest distance to the point and store its id into the edgeid-attribut of my point. The distance between point and line should be calculated as illustrated (d=distance; AB is the street vector and P is the point):

enter image description here

I have already tried the Distancematrix in QGIS but it seems that it can only be done between points. And I do not want to convert the lines into points.

Another thing I tried was the v.distance()-algorithm (GRASS) but I couldn't get it to work. I tried the following configurations for executing the algorithm:
enter image description here

For your better understanding: The tiger:graph is the line-layer and the EVIS_Stat_Sensorik_… is the point-layer. I want to calculate the nearest line (or edge) for each point and write its id into the attribute "edgeid" of the point. Is this even possible with this function? As I am quite new to this tool, I do not really know how to debug this.

Is there any other possible way to do this?

Best Answer

A simple solution for your question is using QGIS tool Distance to Nearest Hub. However, this tool does not bring into account your particular way of calculating distance using a 90 degree angle, as you specified. It simply measures the distance from each input point to the middle of each line feature.

Here is an example of how the tool can be used in a similar context:

Input:

Road and points

Parameters (Hub Layer name attribute is the attribute from the line layer you wish to keep, in your case 'id'):
Distance to nearest hub

Output (same points as input, with added attribute): Attribute Table of output

As with any other processing algorithms, make sure both your layers are using the same coordinate systems (in your case you had a different CRS for each input layer). If the distance field (Hub Dist) is of importance to you too (not just which feature is closest), then make sure you are also using projected coordinate systems (not 4326).
Hope this helps!

Related Question