Project Overview: From Pixels to Land-Use Maps
A county planning department needs an up-to-date land-use map covering 250 km² to support decisions on zoning, stormwater management, and environmental impact assessment. Traditional field surveys would take months and cost hundreds of thousands of dollars. Instead, the engineering team proposes an unsupervised classification of multispectral satellite imagery — a workflow that can be repeated quarterly as new imagery becomes available.
The pipeline follows five stages:
- Data acquisition — Obtain multispectral satellite imagery with Red, Green, Blue (RGB) and Near-Infrared (NIR) bands.
- Feature extraction — Compute spectral indices (NDVI, NDWI, and additional band ratios) that amplify the differences between land-cover types.
- Clustering — Apply K-Means to the feature vectors to partition every pixel into one of K land-use classes.
- Evaluation — Assess cluster quality using silhouette scores and visual inspection against known landmarks.
- Interpretation — Map cluster labels to meaningful categories (urban, vegetation, water, bare soil) and generate the final classified map.
Think of this project as a modern version of what surveyors have done for centuries: classifying the terrain. Where a 19th-century surveyor walked the land, noted soil types, sketched tree lines, and flagged water courses in a field book, the satellite-and-algorithm approach does the same classification from orbit — covering an area in minutes that would take weeks on foot. The “field book” is the feature matrix; the “surveyor's judgement” is the K-Means algorithm; and the “final map” is the clustered output coloured by land-use type.
Satellite Imagery Bands
Multispectral satellites capture reflected sunlight in discrete wavelength bands. Each band reveals different information about the surface:
| Band | Wavelength | What It Captures | CE Relevance |
|---|---|---|---|
| Red | 620–700 nm | Chlorophyll absorption; vegetation appears dark | Distinguishes vegetated vs. built-up areas |
| Green | 500–565 nm | Vegetation reflectance peak; water appears dark | Helps identify water bodies and vigour of vegetation |
| Blue | 450–515 nm | Water penetration; atmospheric scattering | Bathymetry of shallow water; identifying haze |
| NIR | 750–900 nm | Strong vegetation reflection; water absorbs completely | Key to NDVI; separates vegetation from water and soil |
A single pixel in a four-band image is a vector of
four reflectance values: [Red, Green, Blue, NIR].
The entire image is a matrix of dimensions
rows × cols × 4. For clustering,
we reshape this into an N × 4 matrix
where N = rows × cols, treating each
pixel as an independent sample.
Why NIR Is the Game-Changer
Healthy vegetation has a distinctive spectral signature: it absorbs Red light for photosynthesis but strongly reflects Near-Infrared. This creates a dramatic contrast that is invisible to the human eye but unmistakable to the sensor. Water does the opposite — it absorbs NIR almost completely. Urban surfaces (concrete, asphalt) reflect moderately across all bands. These opposing behaviours are what make spectral indices so powerful for land-cover classification.
Feature Extraction: Spectral Indices
Raw band values can separate some land-cover types, but spectral indices — normalised ratios of bands — amplify the differences and reduce the effect of illumination variations. The two most important indices for this project are NDVI and NDWI.
NDVI — Normalised Difference Vegetation Index
NDVI = (NIR - Red) / (NIR + Red)
NDVI ranges from -1 to +1. Dense, healthy vegetation yields values of 0.6 to 0.9. Bare soil and urban surfaces fall between 0.0 and 0.2. Water bodies typically produce negative values because NIR reflectance is near zero while Red reflectance is non-zero.
| NDVI Range | Typical Cover |
|---|---|
| -1.0 to -0.1 | Deep water |
| -0.1 to 0.1 | Bare rock, sand, snow, clouds |
| 0.1 to 0.3 | Sparse vegetation, grassland, urban gardens |
| 0.3 to 0.6 | Moderate vegetation, shrubs, crops |
| 0.6 to 1.0 | Dense forest, healthy crops at peak growth |
NDWI — Normalised Difference Water Index
NDWI = (Green - NIR) / (Green + NIR)
NDWI highlights water content. Positive values indicate water bodies or saturated soil. Negative values correspond to dry surfaces and vegetation. For civil engineers, NDWI is invaluable for delineating floodplains, identifying wetlands that constrain site selection, and monitoring reservoir levels.
Additional Band Ratios
Beyond NDVI and NDWI, the feature vector for each pixel can include:
-
Built-up Index (NBI) —
(Red × SWIR) / NIR— amplifies urban surfaces. When SWIR is unavailable, a simplified ratioRed / NIRserves as a proxy for distinguishing built-up areas from vegetation. -
Bare Soil Index (BSI) —
((Red + SWIR) - (NIR + Blue)) / ((Red + SWIR) + (NIR + Blue)). Without SWIR, the approximation(Red - Green) / (Red + Green)captures exposed soil reasonably well. -
Brightness — The mean of all
bands:
(Red + Green + Blue + NIR) / 4. High brightness combined with low NDVI suggests urban concrete or dry sand.
For this case study, we construct a six-feature vector
per pixel: [Red, Green, Blue, NIR, NDVI, NDWI].
Standardisation (z-score) is applied before clustering
so that no single feature dominates the distance
calculations.
Spectral indices are the remote-sensing equivalent of geotechnical index properties. Just as the plasticity index (PI = LL - PL) collapses two Atterberg limits into a single number that separates clays from silts, NDVI collapses two spectral bands into a single number that separates vegetation from non-vegetation. Both are simple ratios that encode domain knowledge about what matters most for classification.
K-Means Clustering on Spectral Data
With the feature matrix prepared — each row a pixel, each column a spectral feature — K-Means partitions the pixels into K land-use clusters. The algorithm iterates between assigning each pixel to its nearest centroid and updating centroids until convergence.
Choosing K: For a four-class land-use map (urban, vegetation, water, bare soil), K = 4 is the natural starting point. However, real imagery contains mixed pixels (e.g., a pixel spanning both road and grass) and sub-classes (e.g., dense forest vs. sparse grassland). It is common practice to cluster with K = 6 or K = 8 and then merge related clusters into the four target categories during interpretation.
Python Pipeline: From Image to Clusters
import numpy as np
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
# 1. Load bands (simulated as 2D arrays of reflectance)
red = load_band('red.tif') # shape: (rows, cols)
green = load_band('green.tif')
blue = load_band('blue.tif')
nir = load_band('nir.tif')
# 2. Compute spectral indices
ndvi = (nir - red) / (nir + red + 1e-8)
ndwi = (green - nir) / (green + nir + 1e-8)
# 3. Stack into feature matrix
rows, cols = red.shape
features = np.stack([red, green, blue, nir, ndvi, ndwi], axis=-1)
X = features.reshape(-1, 6) # shape: (N, 6)
# 4. Standardise
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
# 5. Cluster
kmeans = KMeans(n_clusters=4, n_init=10, random_state=42)
labels = kmeans.fit_predict(X_scaled)
# 6. Reshape to map
land_map = labels.reshape(rows, cols)
Practical Tips for Satellite Clustering
- Add a small epsilon (1e-8) to denominators in index formulas to avoid division by zero at pixels with no reflectance (e.g., deep shadows).
- Mask clouds and no-data pixels before clustering. Including them distorts centroids and wastes a cluster on artefacts.
-
Use
n_init=10or higher to mitigate K-Means sensitivity to random initialisation. Each run starts from a different seed and the best SSE is kept. - Over-cluster and merge. Starting with K = 8 and merging down to 4 avoids forcing dissimilar pixels into the same cluster.
- Preserve spatial context. After clustering, apply a 3×3 majority filter to remove salt-and-pepper noise — isolated pixels misclassified relative to their neighbours.
Evaluation: Silhouette Scores and Visual Inspection
With no ground-truth labels, evaluation relies on the internal metrics from Sub-chapter 3.9. The two most practical tools for this case study are:
- Silhouette score — Computed on a random sample of 5,000 pixels (full computation on millions of pixels is prohibitively expensive). A score above 0.45 for K = 4 indicates that the four classes are reasonably separated in spectral space.
- Visual inspection — Overlay the classified map on the original RGB composite. Do the “water” pixels align with rivers and lakes? Does the “vegetation” class cover parks and forests? Does “urban” track roads and buildings?
Interpreting the Centroids
Each K-Means centroid is a prototype spectral signature. By examining the centroid values, the engineer assigns a land-cover label:
| Cluster | NDVI (centroid) | NDWI (centroid) | Brightness | Assigned Label |
|---|---|---|---|---|
| C0 | 0.72 | -0.35 | Low | Vegetation |
| C1 | -0.28 | 0.65 | Low | Water |
| C2 | 0.08 | -0.10 | High | Urban |
| C3 | 0.15 | -0.05 | Medium | Bare Soil |
The key discriminators: vegetation has high NDVI and negative NDWI; water has negative NDVI and high positive NDWI; urban surfaces have low NDVI, slightly negative NDWI, and high overall brightness; bare soil sits between urban and vegetation with moderate values across all indices.
Common Misclassification Patterns
- Urban ↔ Bare soil: Concrete and dry sand have similar spectral profiles. Adding texture features (local variance) or thermal data helps separate them.
- Shadow pixels: Shadows in urban canyons reduce reflectance in all bands, making buildings look like water. A shadow mask or terrain correction mitigates this.
- Mixed pixels: At 10 m resolution, a pixel covering half road and half lawn gets an intermediate spectral signature. Over-clustering creates a “mixed” class that can be re-assigned by majority vote with neighbours.
- Seasonal variation: Deciduous trees in winter lose their NIR reflectance, causing vegetation to be classified as bare soil. Multi-temporal imagery (summer + winter) resolves this ambiguity.
Civil Engineering Applications
A classified land-use map derived from satellite imagery feeds directly into several critical civil engineering workflows:
Urban Planning and Zoning
The urban cluster delineates the current built-up footprint. Comparing maps from successive years reveals urban sprawl rates, guides growth boundaries, and supports transit corridor planning. A planner can overlay the vegetation class to identify green corridors worth preserving and the bare-soil class to locate potential development parcels.
Environmental Impact Assessment (EIA)
Regulatory agencies require an assessment of how a proposed project will affect existing land cover. The classified map quantifies the area of vegetation, wetland, and water body that falls within the project footprint. Change detection between pre- and post-construction imagery measures the actual impact and compliance with mitigation commitments.
Site Selection
For infrastructure projects — highways, dams, treatment plants — the land-use map is a first-pass screening tool. Sites with extensive vegetation or water bodies carry higher environmental constraints and mitigation costs. Bare-soil areas near existing urban zones are preferred candidates. The clustering approach automates this screening over hundreds of candidate sites simultaneously.
Stormwater and Hydrological Modelling
Land-use classification directly determines runoff coefficients in rational-method or SCS-CN hydrological models. Urban surfaces have high imperviousness (C = 0.7–0.95), vegetation has low imperviousness (C = 0.1–0.3), and water bodies contribute zero overland flow but may produce baseflow. A classified map feeds these coefficients into watershed delineation tools, enabling accurate flood peak estimation.
Interactive Demo 1: Satellite Band Explorer
This demo generates a simulated 32×32 satellite scene containing four land-cover types — urban (grey), vegetation (green), water (blue), and bare soil (brown). Toggle between RGB composite, individual bands (Red, Green, Blue, NIR), and the computed NDVI overlay to see how each view highlights different surface types. Observe how NIR makes vegetation “glow” bright and water appear dark.
Satellite Band Explorer
Band View
Ground Truth
Putting It All Together: GIS + Unsupervised Learning
This capstone combines everything from Ch 3 — clustering, PCA, evaluation — on real remote sensing data for civil engineering site analysis.
Land-Use from Satellite
K-Means on spectral bands (RGB, NIR, SWIR) classifies pixels into land-use types: urban, agriculture, forest, water, barren. Essential for EIA and watershed planning.
Watershed Delineation
Combine elevation data + spectral clustering to delineate watersheds, identify flood-prone zones, and plan drainage infrastructure at the regional scale.
Full Pipeline
Raw imagery → PCA for dimensionality reduction → K-Means clustering → silhouette evaluation → final land-use map. Every technique from 3.1–3.9 in action.
A pixel has Red reflectance = 0.08 and NIR reflectance = 0.52. What is its NDVI value, and what land cover does it most likely represent?
Why do we compute spectral indices (NDVI, NDWI) instead of clustering directly on the raw band values (R, G, B, NIR)?
Interactive Demo 2: K-Means Land Classification
This demo applies K-Means clustering to the simulated
satellite scene from Demo 1. Each pixel's six-feature
vector [R, G, B, NIR, NDVI, NDWI] is
clustered into K groups. The result is a classified
land-use grid coloured by cluster. Adjust K to see
how under- or over-clustering affects the map. The
silhouette score updates in real time to quantify
cluster quality.
K-Means Land Classification Map
RGB Composite
Classified Map
Full Pipeline Walkthrough
Bringing together every step into a coherent workflow that a civil engineering team can execute end-to-end:
- Step 1 — Acquire imagery. Download a cloud-free, multispectral scene (e.g., Sentinel-2, Landsat 8/9) covering the project area. Sentinel-2 provides 10 m resolution in RGB and NIR, freely available from ESA's Copernicus Open Access Hub.
- Step 2 — Pre-process. Apply atmospheric correction (e.g., Sen2Cor for Sentinel-2) to convert digital numbers to surface reflectance. Mask clouds, shadows, and no-data pixels using the scene's quality band.
-
Step 3 — Extract features.
Compute NDVI, NDWI, and any additional indices.
Stack into a feature matrix of shape
(N_pixels, n_features). - Step 4 — Standardise. Apply z-score standardisation so that all features contribute equally to the distance metric.
- Step 5 — Determine K. Run the elbow method and silhouette analysis for K = 2 to 10. Start with K = number of expected land-cover types, but explore neighbouring values.
-
Step 6 — Cluster.
Run K-Means with the chosen K and
n_init ≥ 10. Record the centroids and labels. - Step 7 — Post-process. Apply a spatial majority filter. Merge sub-clusters that represent the same land-cover category (e.g., “bright urban” and “dark urban” into one “urban” class).
- Step 8 — Evaluate. Compute silhouette on a subsample. Visually compare the classified map against known landmarks (rivers, parks, highways).
- Step 9 — Deliver. Export the classified raster as a GeoTIFF with a colour table and legend. Import into GIS software (QGIS, ArcGIS) for integration with other project layers.
The land-classification pipeline is structurally identical to a geotechnical site investigation. Data acquisition is the field sampling. Feature extraction is the laboratory testing (grain-size distribution, Atterberg limits). Clustering is the soil classification (USCS grouping). Evaluation is the cross-check between lab results and boring-log observations. And the deliverable — a classified map — is the geotechnical report that feeds into foundation design. The same discipline applies whether you are classifying soil strata underground or land cover from space.
Limitations and Possible Extensions
- No spatial awareness. K-Means treats each pixel independently. Two adjacent pixels with slightly different spectra may end up in different clusters even though spatial context suggests they are the same cover type. Object-based image analysis (OBIA) first segments the image into homogeneous regions, then classifies the segments — a natural extension of this pipeline.
- Fixed K. K-Means requires K to be specified in advance. DBSCAN or Gaussian Mixture Models can infer the number of clusters from the data, though they introduce other hyper-parameters.
- Spectral ambiguity. Some cover types (concrete vs. dry sand) are nearly indistinguishable in four bands. Additional bands (SWIR, thermal) or multi-temporal analysis resolve many of these ambiguities.
- Scale effects. At 10 m resolution, many pixels are mixtures of multiple cover types. Sub-pixel or spectral unmixing techniques estimate the fraction of each class within a pixel.
- Supervised alternatives. When training data are available (e.g., ground-truth samples from field visits), supervised classifiers (Random Forest, CNNs — covered in Chapter 4) typically outperform unsupervised methods. The unsupervised pipeline in this case study is ideal when labelled data are scarce or unavailable.
After running K-Means with K = 4 on satellite imagery, a cluster centroid has NDVI = -0.25, NDWI = 0.58, and low brightness. What land-cover type does this cluster most likely represent?
An engineer clusters satellite imagery with K = 4 but notices that the “urban” cluster includes both concrete buildings and dry sandy terrain. What is the best course of action?
Chapter 3 Summary: Unsupervised Learning
This case study brings together every concept from Chapter 3 into one cohesive project. Here is a recap of how each sub-chapter contributed:
Sub-chapter Connections
| Sub-chapter | Topic | Role in This Case Study |
|---|---|---|
| 3.1 | Introduction to Unsupervised Learning | Established the premise: no labelled training data for pixel classification. |
| 3.2 | Clustering Fundamentals | Defined distance metrics and the clustering objective used by K-Means. |
| 3.3 | K-Means Algorithm | The core algorithm partitioning pixels into K land-use classes. |
| 3.4 | Hierarchical Clustering | An alternative approach for merging sub-clusters during post-processing. |
| 3.5 | DBSCAN | A density-based alternative when the number of classes is unknown. |
| 3.6 | Dimensionality Reduction (PCA) | Could reduce the 6-feature space for visualisation or noise reduction. |
| 3.7 | Feature Scaling & Preprocessing | Z-score standardisation ensures equal feature contribution. |
| 3.8 | Association Rules | Could discover co-occurrence patterns (e.g., water always near vegetation). |
| 3.9 | Evaluating UL Models | Silhouette scores and visual inspection validate the classification. |
| 3.10 | CE Case Study (this page) | Integrates all concepts into a real-world GIS classification project. |
Key Takeaways from Chapter 3
- Unsupervised learning discovers structure in unlabelled data. It is ideal for civil engineering problems where labelled datasets are scarce or expensive to create.
- K-Means is the workhorse algorithm for partitioning data into a pre-specified number of clusters. It is fast, interpretable, and effective when clusters are roughly spherical.
- Feature engineering (spectral indices, standardisation) is as important as the algorithm itself. Poor features lead to poor clusters regardless of the method.
- Evaluation requires multiple lenses: internal metrics (silhouette, DB, CH, elbow), visual inspection, and domain cross-validation. No single metric suffices.
- The over-cluster-and-merge strategy is a pragmatic approach that handles spectral ambiguity better than trying to guess the exact K.
- Domain expertise is irreplaceable. The algorithm finds patterns; the engineer decides which patterns are meaningful. A cluster is only useful if it maps to an actionable category in the project context.
Looking Ahead: Chapter 4 — Convolutional Neural Networks
Chapter 3 demonstrated what can be achieved without labelled data. Chapter 4 introduces Convolutional Neural Networks (CNNs), which learn spatial hierarchies of features directly from images. Where K-Means treats each pixel independently, CNNs consider the neighbourhood context — recognising that a group of pixels forms a roof, a road, or a tree canopy. This makes CNNs dramatically more powerful for image classification tasks, provided sufficient labelled training data are available. The transition from unsupervised spectral clustering to supervised deep learning marks a quantum leap in what remote sensing can achieve for civil engineering.
Try a clustering pipeline end-to-end in Python
Open the playground and adapt the k-means soil-sample snippet to your own GIS feature table — the same code path used in the case study above.