# Calculating shortest distance from point to line using QGIS?

What is the best method to calculate the distance from the nearest road for a series of address points in QGIS, having a very big dataset? (QGIS 2.0.1, Win XP)

I read the answers to previous similar questions:

Measuring the distance between lines and points in QGIS

Drawing perpendicular lines in PyQGIS?

Calculating minimum distance between points and polygons in QGIS?

Nevertheless:

1. MMQGIS plugin find the disance to the nearest node of a line network, not the shortest (perpendicular) distance to a line.

2. R and Python proposed scripts correctly works for small datasets and can be implemented in the modeler, however for my job I have 530 points and a regional street layer with about 135'000 features, and cycling through all the features then taking the shortest distance for all points will take an enormous amount of time

3. I have problems in making GRASS work in QGIS 2.0.1 (GRASS in QGIS not working (windows XP)).

• I managed to calculate the minimum distance in QGIS 1.8.0 through the GRASS plugin and the v.distance tool. It takes about 15 minutes to execute (plus the time spent to correctly set GRASS and import layers...). Why is ArcGIS (es, join by spatial location) still so rapid in comparison? Oct 7 '13 at 9:12
• It is a matter of having a spatial index and code optimized for the task. I just checked with our routing library (RW Net 4) and it can do 2000 such calculations per sec for a street network of app. the same size as yours. Making it about 4000 times faster than your GRASS plugin. Oct 7 '13 at 9:25
• Postgis should do it fast Oct 7 '13 at 17:27
• @mic_cord Can you please give a detailed explanation of your GRASS plugin v.distance method? I have successfully gotten v.distance to work using GRASS outside of QGIS, but am unable to get it to work within the Processing toolbox (QGIS 2.6). Mar 6 '15 at 20:40

## 2 Answers

We were solving similar problem. The best and fastest way for us is:

1. Rasterize line layer (Raster/Conversion/Rasterize...)
2. Convert to Proximity (Raster/Analysis/Proximity...)
3. Use plugin Point sampling tool to get values for all your point from raster

Some of the answers to Measuring the distance between lines and points in QGIS recommend the NNJoin QGIS plugin (http://arken.nmbu.no/~havatv/gis/qgisplugins/NNJoin/). It will do a nearest neighbour spatial join and include the distance in the result. The NNJoin plugin uses a spatial index, so it should handle reasonably large datasets.

• Tveite, I second your suggestion. I was very surprised that this plugin worked faster than a recommended package in R (i.e. geosphere::dist2Line). Jan 15 '20 at 9:06