[GIS] Calculate distance between point and linestring and how to represent that on QGIS

distancelinestringpointpostgisqgis

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) )
As ST_DISTANCE;

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?

Best Answer

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.