Landscape metrics, part 6 of 7
Signatures and kinds of landscapes
Cut a land cover into squares, describe each square by its metrics (its spatial signature), summarise them with principal components and non-negative factors, and group the squares into kinds of landscapes by k-means, choosing the number of groups with a clustergram.
- Level
- Advanced
- Time
- 50 min
- Template
- Kinds of landscapes
- 1What metrics are
- 2Patch and class
- 3Landscape level
- 4Moving windows
- 5Sampling and change
- 6Kinds of landscapes
- 7Large maps
A region of 50 × 50 km holds several kinds of landscape: open plains of arable land, mosaics of fields, pasture and woods, forests, towns. Ecologists and planners often need them as units: to stratify a sampling design, to report how each kind changed, to compare regions. This part builds them from the metrics: the map is cut into squares, each square is described by a handful of landscape and class metrics (its spatial signature), the signatures are summarised by principal components and by non-negative factors, and the squares are grouped by k-means. At the end you will have a map of kinds of landscapes, a table that says what each kind is, and a defensible number of kinds.
The idea#
Every square of the map is a small landscape, and a set of metrics places it as a point in a space of several dimensions: its diversity, its edge density, its largest patch, its share of forest... Squares that are close in that space are alike. Two families of methods then make sense of the cloud of points:
- Ordination reduces many correlated metrics to a few axes. Principal component analysis (PCA) finds the directions along which the squares differ most; part 5 showed that landscape metrics are strongly correlated, so a few components usually hold most of the variation (Riitters et al., 1995; Cushman et al., 2008). Non-negative matrix factorization (NMF; Lee & Seung, 1999) does something similar with factors that only add up, which are often easier to read as "parts" of a landscape.
- Classification groups the squares. K-means puts them into \(k\) groups so that each square is closer to the mean of its group than to any other; a clustergram (Schonlau, 2002) shows how the groups split as \(k\) grows, to help choose \(k\).
The approach follows pylandstats' spatial signature analysis (Bosch, 2019), which Terraflux reproduces through landschaft: the same signatures, the same PCA and NMF, the same k-means from the same seeds, so the groups are the same as in Python. Nowosad and Stepinski (2019) used a related idea, two numbers of information theory per square, to map kinds of landscape over whole continents.
Key idea: z-scores and principal components
Metrics have different units (ha, m/ha, %), so before PCA and k-means each metric \(x\) is turned into a z-score, \(z = (x - \bar{x}) / s\): its distance from the mean of all squares in standard deviations. Then every metric weighs the same. A principal component is a weighted sum of the z-scores, \(\text{PC}_1 = \sum_j l_{1j} z_j\); the weights \(l_{1j}\) are its loadings, and its share of the variance says how much of the differences between squares it captures.
When to use it#
- Stratifying: sample sites spread over the kinds of landscape, so that every kind is represented.
- Mapping and reporting by kind: how much of each kind there is, how each changed between two dates
(
metrics.signaturestakes a stack, a row per layer, as well as zones). - Finding gradients: the first principal component is often a gradient of heterogeneity or intensification that is a useful predictor in itself.
- Not a land cover classification: the groups describe the pattern of squares of fixed size, not what a cell is. And not a substitute for knowledge of the region: always name the groups by looking at their metrics and maps.
What you need#
A categorical map in a projected system: clc.tif, CORINE around
Hannover, grouped into 7 classes as in parts 4 and 5. The squares' size is a choice of scale like a window's: large
enough to hold a landscape (here 2.5 km, 100 × 100 cells), small enough to be homogeneous. In the application,
Templates > Landscape metrics > Kinds of landscapes builds the same chain on a land cover drawn along a gradient.
Build the model#
Model file (TOML)
format = "terraflux/1"
[[nodes]]
id = "corine"
op = "raster.read"
params = { path = "clc.tif" }
[[nodes]]
id = "cover"
op = "raster.reclassify"
inputs = { map = "corine.raster" }
params = { rules = "1..11 -> 1\n12 -> 2\n13..22 -> 3\n23..25 -> 4\n26..34 -> 5\n35..39 -> 6\n40..44 -> 7" }
note = "1 urban, 2 arable, 3 pasture and mixed farming, 4 forest..."
[[nodes]]
id = "signatures"
op = "metrics.signatures"
inputs = { maps = "cover.map" }
params = { grid = 2500, landscape_metrics = ["shdi", "ed", "lpi", "contag", "ai"], class_metrics = ["pland"], classes = [1, 2, 3, 4] }
note = "A row per square of 2.5 km."
[[nodes]]
id = "pca"
op = "metrics.pca"
inputs = { table = "signatures.table" }
params = { components = 3 }
[[nodes]]
id = "nmf"
op = "metrics.nmf"
inputs = { table = "signatures.table" }
params = { factors = 3 }
[[nodes]]
id = "groups"
op = "metrics.cluster"
inputs = { table = "signatures.table" }
params = { k = 4, seed = 0 }
note = "Four kinds of landscape."
[[nodes]]
id = "clustergram"
op = "metrics.clustergram"
inputs = { table = "signatures.table" }
params = { k_min = 1, k_max = 8 }
- The map (nodes 1 and 2): read and group the classes, as in part 4.
- The signatures (node 3). Connect node 2's
mapto themapsinput ofmetrics.signatures.gridtiles the map with squares of that side in map units (2,500 m);plotswould take polygons or points instead. Itstablehas a row per square (zone, numbered row by row from the top left), a column per landscape metric, and a column per class metric and class:pland_1topland_4, the share of urban, arable, pasture and forest.classeslimits the class columns to the classes that matter. - The analyses (nodes 4 to 7) all take the signatures'
table: drag from it to each. By default they use every column but the keys (zone,landscape,class,date);columnspicks some.
Choosing the metrics is the important decision. Here, five landscape metrics covering diversity (shdi), edge
(ed), dominance (lpi) and aggregation (contag, ai), and the shares of the four main classes: composition and
configuration both. Metrics that are near copies of each other (ed and te, np and pd) should not both be in:
they would weigh twice.
Read the results#
The signatures#

The table has 400 rows. The first square, in the north-west corner, has 66% arable land, 14% pasture, 12% forest and 8% urban, a Shannon diversity of 1.01, an edge density of 30 m/ha and a largest patch of 63%.
Principal components#
The loadings table of metrics.pca:
| PC1 | PC2 | PC3 | |
|---|---|---|---|
| Variance explained | 52% | 17% | 14% |
| AI | −0.41 | 0.15 | 0.09 |
| CONTAG | −0.41 | −0.02 | 0.02 |
| ED | 0.43 | −0.13 | −0.08 |
| LPI | −0.43 | −0.04 | −0.01 |
| SHDI | 0.44 | 0.01 | 0.00 |
| % urban | 0.00 | 0.00 | 0.86 |
| % arable | −0.15 | −0.67 | −0.35 |
| % pasture | 0.29 | −0.04 | 0.06 |
| % forest | 0.00 | 0.72 | −0.36 |
Read each component by its largest loadings:
- PC1 (52%) is a gradient of heterogeneity: positive for diversity and edge, negative for aggregation, contagion and the largest patch. Squares high on PC1 are fine-grained mosaics; squares low on it are dominated by one large patch, whatever its class.
- PC2 (17%) opposes forest (+0.72) to arable land (−0.67): what dominates.
- PC3 (14%) is urban (+0.86).
Three axes hold 83% of the variation of ten metrics. The scores table places every square on them.

Non-negative factors#
metrics.nmf scales every metric to 0–1 and approximates the table by three factors whose weights are all
positive. Its components table:
| Factor | Largest weights | Reads as |
|---|---|---|
| 1 | % arable 1.65, LPI 1.60, AI 1.45, CONTAG 1.15 | large uniform fields |
| 2 | ED 1.03, SHDI 1.01, % pasture 0.46 | a fine mosaic |
| 3 | AI 0.73, LPI 0.66, % forest 0.61 | large forests |
Where PCA gives contrasts (forest against arable), NMF gives parts that add up: every square is a mix of
"uniform fields", "mosaic" and "forest", with its scores the amount of each. The error output says how well the
three factors reproduce the table; try more factors if it is large.
Kinds of landscapes#
metrics.cluster groups the squares by k-means of their z-scores (method = "kmeans", starts from seed, the
best of n_init starts), or by a hierarchical linkage (ward, average...). Its table is the signatures with a
cluster column; rows with a missing metric are left out.






With \(k = 4\), the mean metrics of each group say what it is:
| Group | Squares | SHDI | ED (m/ha) | % urban | % arable | % forest | Kind |
|---|---|---|---|---|---|---|---|
| 0 | 194 | 1.04 | 26.4 | 13 | 42 | 22 | mixed farmland (19% pasture) |
| 1 | 139 | 0.56 | 14.5 | 8 | 81 | 7 | arable plains |
| 2 | 37 | 0.44 | 8.8 | 3 | 12 | 76 | forests |
| 3 | 20 | 0.52 | 11.3 | 81 | 8 | 3 | city |

The largest patch covers 48% of an average square of group 0 and around 80% in the others. Naming the groups is the analyst's job, from such a table: the algorithm only says that the squares of a group are alike.
How many kinds?#
There is no single right \(k\). The clustergram shows how the groups form as \(k\) grows: for every \(k\), a dot per group at the group's mean on the first principal component, sized by its number of squares, and lines that follow the squares from one \(k\) to the next.

A good \(k\) is one after which the large groups stay stable: here 4. Beyond, the groups cut a continuous gradient at arbitrary places. Choose \(k\) also by use: four kinds are easy to sample and report; seven may be needed to separate the variants of the mosaic if they matter to the species.
Settings that change the answer#
- The square's size (
grid): a scale, as the window's in part 4. Small squares are often one class; large ones mix kinds. - The metrics: the groups are only as meaningful as the metrics chosen. Redundant metrics weigh twice; a metric irrelevant to the question still pulls the groups.
- The method: k-means makes compact groups of similar size in z-score space; Ward's linkage behaves similarly;
averageandsinglelinkages make unequal groups and chains. components: clustering the first principal components instead of the metrics removes the noise of the minor axes.- The seed: k-means starts at random;
seedandn_initmake the result repeatable. Report them.
Common pitfalls#
- Squares cut by the map's border (the last row and column when the map is not a multiple of the square) are smaller: their metrics are not comparable. Drop them, or choose a square that divides the map.
- Missing values: squares of a single class have no contagion; they are left out of PCA and clustering (here 10). If such squares matter (all forest, all city), choose metrics defined for them, or add them back as a kind of their own.
- Reading k-means groups as natural types: they are a partition of a continuum unless the clustergram shows clean, stable splits.
- Two dates with different groups: to follow change, classify the squares of both dates together (one table, the date as a key), so that the groups mean the same thing at both.
Going further#
- Part 7: signatures of maps larger than memory (
block_rows). - Biodiversity: clusters of regions by their species, Biodiverse's analyses.
- The operator reference:
metrics.signatures,metrics.pca,metrics.nmf,metrics.cluster,metrics.clustergram.
References#
- Bosch, M. (2019). PyLandStats: an open-source Pythonic library to compute landscape metrics. PLOS ONE, 14(12), e0225734. https://doi.org/10.1371/journal.pone.0225734
- Cushman, S. A., McGarigal, K., & Neel, M. C. (2008). Parsimony in landscape metrics: strength, universality, and consistency. Ecological Indicators, 8(5), 691–703. https://doi.org/10.1016/j.ecolind.2007.12.002
- Lee, D. D., & Seung, H. S. (1999). Learning the parts of objects by non-negative matrix factorization. Nature, 401(6755), 788–791. https://doi.org/10.1038/44565
- Nowosad, J., & Stepinski, T. F. (2019). Information theory as a consistent framework for quantification and classification of landscape patterns. Landscape Ecology, 34(9), 2091–2101. https://doi.org/10.1007/s10980-019-00830-x
- Riitters, K. H., O'Neill, R. V., Hunsaker, C. T., Wickham, J. D., Yankee, D. H., Timmins, S. P., et al. (1995). A factor analysis of landscape pattern and structure metrics. Landscape Ecology, 10(1), 23–39. https://doi.org/10.1007/BF00158551
- Schonlau, M. (2002). The clustergram: a graph for visualizing hierarchical and nonhierarchical cluster analyses. The Stata Journal, 2(4), 391–402. https://doi.org/10.1177/1536867X0200200405