Habitat network — Recipe (QGIS)
Tool-bound implementation of the Habitat network (Task) Task Schema in QGIS 4.2. Worked example: Habitat network at Ledreborg (Example).
Data you need
| Role | Form | Level of measurement | Notes |
|---|---|---|---|
| Habitat patches | polygons | nominal type (optional) | e.g. from Nature content layer (Task) |
| Connection distance | a number | ratio (metres) | from the species or species group in question |
| Patches with cluster (output) | polygons | nominal cluster_id; ratio counts and areas |
Build the clusters (Task Schema steps 3–5)
Buffer (Tool - QGIS) on the patches:
- Distance: half the connection distance
- Dissolve result: ticked
- Keep disjoint results separate: ticked
This one dialog realises three Operators — dilation, dissolve and explode — and gives one feature per cluster. Then:
- Renumber feature ids (Tool - QGIS) on the clusters. Without it, saving to a GeoPackage fails (UNIQUE constraint failed), because the clusters share
fidvalues. - Field calculator (Tool - QGIS): an integer field
cluster_id=$id.
Give each patch its cluster (step 6)
Join attributes by location (Tool - QGIS): Join to features in the patches, By comparing to the clusters, predicate intersect, field cluster_id, join type Take attributes of the first matching feature only (one-to-one).
Measure and classify (steps 7–8)
Field calculator (Tool - QGIS) on the joined patches:
n_in_cluster(integer) =count($id, group_by:="cluster_id")cluster_area(decimal) =sum($area, group_by:="cluster_id")
Style the layer with Categorized on the expression
CASE WHEN "cluster_area" = maximum("cluster_area") THEN 'Main network'
WHEN "n_in_cluster" = 1 THEN 'Isolated patch'
ELSE 'Smaller cluster' END
Repeat with at least one other connection distance, as the Task’s choices recommend.
Checked in QGIS 4.2.2, October 2026.