QGIS Proximity Analysis – Finding Distance Between Buildings and the Nearest Road Using QGIS

distancelinepolygonproximityqgis

I am very new to working with GIS data. I am currently using the QGIS tool to work with the data.

I have two datasets:

  1. Buildings – polygon shapefile with information about different buildings in a city. There is a unique column called "propertyid".
  2. Roads – line shapefile with information about different roads in the city. There is no unique column, but we do know that each line item refers to one road, so we have created an index column based on "@row_no".

Objective: To find the distance between a given building and the nearest road.

What I have already tried:

  1. Converted buildings layer to points(centroids) and lines layer to points(extracted vertices) and run a distance matrix using these two layers. But this doesn't give me the desired result for some reason.
    Since I am very new, I could be doing something wrong.
  2. Using the same point layers mentioned above, ran the distance to the nearest hub algorithm. Again, I may have committed an error in doing this as well.

It would be great if someone could guide me in the right direction and tell me if

  • what I'm trying to achieve is possible, and
  • if it is, then how would you go about doing it.

Best Answer

While in general this would be better handled in PostGIS, there are plug-ins which do the heavy lifting for you:

NNJoin

This is the preferable and correct way, however could be slow on large datasets. It has the non trivial advantage to compute the correct polygon-to-line distance, without converting buildings into points first (which could lead to erroneous results).

Hub Distance

Faster, but only works with point vector layers.

Since you are working with a local, projected system, make sure to check the Layer Units option.

An output layer will be created, with lines connecting each building with the closest road. Alternatively you can choose to have a point layer as output (one point per building)

Related Question