I am using QGIS.

'm working on population data (point features), and I'd like to know their distance from the coast as shown in the image below.

Is there a way to create a field in the attribute table which would give for each point its distance from the shore?

enter image description here

2 Answers 2


The idea is to get the distance to the boundary of your polygon.

You can convert it to a linestring first and it could be easier to handle :

Geometry tool > convert polygon to line.

Then you have multiple choices.

I saw a good use of QGIS tools for a graphic solution which is well explained at Nearest distance between point and line layers in QGIS

Or you could try to use GRASS library and v.distance wich can fill your need I think.


Or try to go with PostGIS and St_Distance if you know how to use PostGIS.


Assuming that the coast is defined as a multiline in the 'Rivers' layer, with an attribute 'name', and one of those lines has the name 'Amazon':

Then, the expression in the Field Calulator to fill the field 'd_Amazon' in the layer containing the points should be:


Note that the distance will be calculated based on the coordinates of the entities in their own reference systems, so it is advisable that both layers have the same system assigned to them.

If the coast is defined in a layer of polygons, the expression works in the same way for the points that are outside the polygon, but returns 0 if the point is inside the polygon.

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.