I have a polyline and points layer. The points lie on both sides of the polyline at some distance. I want to calculate the minimum distance between all the individual points and the polyline. I can do it in ArcGIS by converting the polyline into a route and then locating features along that route.

Is there a way to do it in QGIS?


One way to do that (using the DB Manager of QGIS) :

You choose Database / Database Manager / Database Manager then Virtual Layers / Qgis Layers you can then try the following query :

select points.id, min(st_distance(line.geometry, points.geometry)) from line, points
where line.id=1

I identify one line using its id.

You get the id of the closest point and the computed distance.

Adapt the query according to your data structure (tables and attributes naming)

  • Thank you for the answer. I'm getting a message "Query preparation error on PRAGMA table_info(_tview): no such column: trial". I don't have any experience with virtual layers. My polyline layer name is "pdi" and the points layer name is "trial". Could you tell me where exactly to use the attributes and tables name. Thank you. – Noel Victor Aug 12 at 10:47
  • QGIS seems to refer to trial as if it was a column (whereas it is a table), so something must be wrong in your syntax ... can u write your full query so that i see if u're doing something wrong ? – snaileater Aug 12 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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