I have loaded my data with osm2pgrouting and I have my network with ways (Linestring) and nodes (Point). The problem is : I have a database of doctors addresses (point) and I should calculate the distance between these points and my ways (Linestring).

Yellow points are Doctors : 1

I am using the following query :

SELECT ST_Distance ( 
ST_GeomFromText('POINT(55.4504545699355 -20.8752577759738)',4326),
ST_GeomFromText('LINESTRING(55.4748349 -27.1342723, 55.4747091 -21.1338699)',4326) )

But I don't think that works. I need to calculate the distance from all the doctors points and represent that in QGIS as a linestring.

Any help or advice?

3 Answers 3


You could use the Distance to nearest hub algorithm from the Processing plugin which you could add your points and your lines layer instead of going through a query.

Distance to nearest hub

From a couple of example layers that I have, you can get something like this:

Output player for Distance to nearest hub analysis

Then when you open up the Attributes Table for the output layer, you will be given the HubName and HubDist in whatever measurement scale you selected (in my case, meters). Hope this helps.

  • Thank's for you help. The problem is that doesn't give me the nearest line from the point. That looks like this : link
    – Issame A.
    Commented Jul 15, 2014 at 11:17
  • And I want to add this lines to my network (table : ways) to calculate the driving_distance or the shortest_path from this points with PgRouting.
    – Issame A.
    Commented Jul 15, 2014 at 11:22
  • For the above method, you could add a query to find and show only the minimum distance from each point to its nearest line. However, I'm not familiar with PgRouting so my apologies for that.
    – Joseph
    Commented Jul 15, 2014 at 11:30

With QGIS 2.16 you can use v.net.connect in the processing toolbox.

This connects points to the nearest line to create a network.

Open the processing toolbox and search for v.net.connect enter image description here

set the properties. You can increase the treshold to set the max distance to look for connection. enter image description here

The results: beforeenter image description here

and after enter image description here

Now you can filter the new lines and calculate the distance


read gis.stakexchange_same_question this script is available here: https://github.com/tomflyjc/Closest_point

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.