Nearest distance between point and line layers in QGIS

As an alternative, you could:

  1. Use the Convert Lines to Points tool from:

    Processing Toolbox > SAGA > Shapes - Points > Convert Lines to Points

    (Add points over small distances. E.g. add a point every 1m if the overall line is 100m)

    Convert lines to points

  2. Use the Distance to nearest hub from:

    Processing Toolbox > QGIS geoalgorithms > Vector analysis tools > Distance to nearest hub

    (Set the parameters, using the output layer of the Convert Lines to Points tool as the Destination hubs layer and setting the Output shape type as Line to hub)

    Distance to nearest hub

  3. Final result should be a line layer which connects the original points layer with the original line layer (with line-converted points):

    Final result with points

    (without line-converted points):

    Final result without points

I used QGIS 2.12.3-Lyon.


In QGIS I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer....

Let's assume we have two layers 'points' and 'river' with its corresponding attribute tables, see image below.

input

With the following query, it is possible to create new lines that will represent the connection between points to the nearest line features.

SELECT ST_ShortestLine(r.geometry, p.geometry),
        p.id AS pid,
        r.id AS rid,
        ROUND(ST_Length(ST_ShortestLine(r.geometry, p.geometry)), 6) AS distance
FROM points AS p, river AS r
WHERE distance < 0.5
GROUP BY p.id
ORDER BY MIN(distance)

Note:

  • WHERE distance < 0.5 specifies the longest acceptable distance between point to the line feature

The output Virtual Layer with its Attribute table will look as following

output


The ClosestPoint does what you are looking for, currently limited to selected features only. You can take a look at the code and modify it for your needs