3.4. Proximity analysis¶
We will now focus on operations involving point layers. Please note that QGIS, when clipping a Point layer, also converts its geometry type to MultiPoint. This geometry type is not suitable for some of the functions we will use in the next step and therefore we will first see how to convert the geometry type back to Point.
3.4.1. Convert geometry type¶
Available at Processing Toolbox->Vector geometry->Convert geometry type, it provides an algorithm that allows to convert the MultiPoint features to single Point features. To do so, the input parameters are:
- Input layer: the point layer whose geometry we want to convert. In this example we use the
places_clip
layer- New geometry type: select Centroids
- Converted: the path and the name of the output vector layer. Note that if left empty a temporary layer will be created
In order to continue with the following functions, please convert the geometry type also for the
natural_clip
point layer.Note
After you are done with the conversion, you can remove the previous point layers and include in the project only the new ones.
3.4.2. Average Nearest Neighbor¶
Available at Processing Toolbox->Vector Analysis->Nearest Neighbour Analysis, it provides a function that performs nearest neighbor analysis for a point layer. The output is generated as an HTML file with the computed statistics. We perform the Nearest Neighbor Analysis with the
natural_clip_point
point layer; the input parameters are:
- Input layer: the
natural_clip_point
layer- Nearest Neighbor: the path and the name of the output HTML file. Note that if left empty a temporary file will be created
Once the operation is done, you can open the HTML file containing the results and you will see information about the Observed mean distance, Expected mean distance, Nearest neighbour index, Number of points, and Z-Score.
We now see how to calculate the nearest feature to a given point or set of points in QGIS. We distinguish between distances from point to point, and from point to a line or polygon layer.
3.4.3. Distance from point to point¶
Available at Processing toolbox->Vector analysis->Distance to nearest hub (points), it provides an algorithm that computes the distance between point features taken as the origin and their closest point destination. In this case, we will calculate the distance from the
places_clip_point
layer to thenatural_clip_point
layer. The input parameters are:
- Source points layer: the
places_clip_point
shapefile- Destination hubs layer: the
natural_clip_point
shapefile- Hub layer name attribute: osm_id
- Measurement units: meters
- Hub distance: the path and the name of the output vector layer. Note that if left empty a temporary layer will be created
The result is a copy of the places layer, but each point feature has two additional attributes: the id of the nearest natural point feature (HubName) and the distance from it (HubDist), as you can see from its attribute table:
3.4.4. Distance from point to layer¶
Available at Processing Toolbox->Vector analysis->Distance to nearest hub (line to hub), it provides an algorithm that computes the distance between point features taken as origin and their closest destination line or polygon feature.
Note
Distance calculations are based on the centroid of the line or polygon features.
In this case, we calculate the closest forest to each place. To do so, we select all the forests from the
landuse_a_clip
layer:
- Right-click on the
landuse_a_clip
layer in the Layers panel and click on Open attribute table- Click on the Select features using an expression button
- In the window, write the following expression:
"fclass" is 'forest'
, and then click “Select features”Once we have selected all the forests from the
landuse_clip
layer, we can run the Distance to nearest hub (line to hub) function. The input parameters are:
- Source points layer: the
places_clip_point
layer- Destination hubs layer: the
landuse_a_clip
layer, considering only selected features- Hub layer name attribute: osm_id
- Measurement units: meters
- Hub distance: the path and the name of the output vector layer. Note that if left empty a temporary layer will be created
The result is a line layer representing all the distances from each places point feature to the nearest forest feature.