Find nearest features¶
Nearest neighbour spatial join¶
In a nearest neighbour spatial join, each feature of the input dataset is joined to the feature in the output dataset whose geometry is closest to the geometry of the feature of the input dataset. The result of the join is a dataset that contains the attributes from both the input and the join dataset, and normally the geometry of the input dataset. Often, the distance between the features is added as an attribute to the output dataset. Spatial indexes can be used to speed up the operation.
Point, line and polygon layers¶
- v.distance in GRASS does nearest neighbour spatial joins. But v.distance is currently not working in QGIS Processing, so it must be run through the GRASS plugin. The nearest neighbour distance is included in the attribute table of the output layer.
- The NNJoin plugin (http://plugins.qgis.org/plugins/NNJoin) does nearest neighbour spatial joins. Also self joins are supported. The user can choose between exact distance joins and joins based on geometry approximations. The nearest neighbour distance is included in the attribute table of the output layer. The output layer will contain all the attributes from the two input layers (with a user-defined prefix added to the join layer attribute names).
Point layers only¶
- Distance matrix (Vector, Analysis tools) can be used to find nearest neighbours and nearest neighbour distances for point layers. To provide only nearest neighbours, the user has to check Use only the nearest (k) target points, and set k to 1 (the default).
Distance matrix does not create a vector layer, only a matrix in the form of a CSV file. The matrix links user defined IDs from the input and join layer, and provides the distances between the points.
For a tutorial, see http://www.qgistutorials.com/en/docs/nearest_neighbor_analysis.html
- Hub Distance (MMQGIS, Create) in the MMQGIS plugin can be used to find nearest neighbours for a point layer. If the join layer is not a point layer, an approximation (centroid?) of the join layer geometry is used for the calculations.