[GIS] How to measure the distance of multiple points to a line

distanceqgisqgis-pluginsvector

I have two shapefiles in QGIS to which I am trying to find the distances between. I have a shoreline which is a vector line and then I have hundreds of data points in the ocean.

What I am trying to find is measuring the distance of each point to the corresponding place horizontally on the shoreline thus giving me a distance of each point from the shore. I have tried the distance matrix plugin which seems to only deal with point to point distances and have tried the mmqgis hub distance which only measures distances to a central fixed point on the line. Is there a plugin or way to find the distances I am looking for?

Best Answer

Try this: from the attribute table of your point file add a new field (real number) and use the following formula:

distance( $geometry , geometry ( get_feature( 'line-file','field',name-of-line))))

Were 'line-file' is the file where the line is stored, 'field' is a field in the line-file table, and name-of-line is the values of that field for your line. This formula gives only positive distance.