A coastline measured from space, taken apart
How the Mekong showcase is made: 38 dry seasons of Landsat, one rule for where the coast is, and a trend that a few bad years cannot drag
The Mekong showcase looks at 38 dry seasons of satellite images, 1988 to 2025, over five stretches of the delta’s coast and draws, year by year, where the vegetation ends and the mudflat begins. On the Ca Mau east coast that edge stood more than a kilometre further inland in 2025 than in the first clear years. This article takes the measurement apart: where the images come from, how a coastline is found in them, how a rate is read from 38 noisy years, and what it cannot see.
Built with AI coding tools: I set the direction, tested and decided; the tools wrote the code and the first draft of this article. The reference list was checked against Crossref, and what I say about each source against its abstract or an open copy (for one, which has neither online, I say nothing beyond its title).
The same 9 × 9 km box on the Ca Mau east coast in the dry seasons of 1988 and 2025, as the page shows it (without its lines). Landsat images courtesy of the U.S. Geological Survey.
The images
Every image on the page is a Landsat image: Landsat 5 for the early years, then 7, 8 and 9. The archive has been reprocessed as Collection 2, and since then the U.S. Geological Survey provides surface reflectance worldwide, corrected for the atmosphere, as a ready product (Crawford et al. 2023). The page uses that product, called Level 2.
It reads the images through the Microsoft Planetary Computer, which offers the Landsat archive with a free, anonymous access token, and reads only the 9 × 9 km box from each scene, not the whole scene. A script, scripts/showcase_mekong/build_frames.py, asks the catalogue for every scene of a dry season over a box (from build_frames.py):
body = {
"collections": ["landsat-c2-l2"],
"bbox": bbox_ll,
"datetime": f"{year - 1}-12-01T00:00:00Z/{year}-04-30T23:59:59Z",
"query": {"eo:cloud_cover": {"lt": MAX_SCENE_CLOUD},
"platform": {"in": ["landsat-5", "landsat-7", "landsat-8", "landsat-9"]}},
"limit": 100,
}It looks only at the dry season, December to April. The script sorts the scenes so that Landsat 7 after May 2003, whose images have gaps from a broken scan-line corrector, comes last, then by cloud cover.
Clouds out, one picture per year
Each Landsat pixel comes with a quality band that flags fill, cloud, the margin around a cloud and cloud shadow. The script drops every pixel with any of those flags:
def clear_mask(qa: np.ndarray) -> np.ndarray:
q = qa.astype(np.uint16)
fill = (q & 1) > 0
bad = (q & (1 << 1)) | (q & (1 << 3)) | (q & (1 << 4)) # dilated cloud, cloud, shadow
return (~fill) & (bad == 0) & (q > 0)Of the first 16 scenes of a season, it keeps up to five whose box is at least 90 % clear, preferring those with the least haze (judged by how bright the blue band is); if fewer than three qualify, it adds the clearest of the rest. From those it takes, pixel by pixel, the median. A median ignores a single bright cloud edge or a dark shadow the mask missed, as long as most looks at that pixel are clean. In practice there are fewer looks than that: on the Ca Mau east coast, the typical pixel of a clear year has two to four clean looks, and with two the median is just their mean and rejects nothing. A year counts for the measurement only if at least 85 % of the box is clear in the result. On the Ca Mau east coast, three of the 38 years fail that test: 1993, 2011 and 2012.
Where is the coast?
On a sandy beach the coast is the waterline. On the Mekong’s mud coast that does not work: the waterline moves a long way with the tide over the mudflats, so in an image it says more about the hour the image was taken than about the coast. The page uses the seaward edge of the vegetation instead, which moves much less with the tide.
Vegetation is found with the normalised difference vegetation index, NDVI: the difference between near-infrared and red reflectance, divided by their sum. Green leaves reflect much near-infrared and absorb red, so NDVI is high over them and low over water and mud. Tucker (1979) studied how red and infrared measurements can be combined to monitor vegetation. The script also requires a bright near-infrared (at least 0.15), so that green, algae-rich water is not taken for forest.
Then the edge. Across each box run straight lines from the sea to the land, 90 m apart, roughly at right angles to the coast. Along each, every 15 m, the script reads the NDVI and walks in from the sea. The edge is the first point where the vegetation holds for five samples in a row, 15 m apart (the page calls this 75 m) (from veg_line in build_frames.py, shortened):
for k in range(seg.size):
if unknown[k]:
gap += 1
run = 0
if gap > MAX_GAP:
break # long cloud gap on the way in: no answer here
continue
# …
if veg[k]:
if run == 0:
start, start_after_gap = k, after_gap
run += 1
else:
run = 0
# …
if run == RUN:
# an edge right behind a cloud gap could really sit inside the gap
if not start_after_gap:
pos[p] = dists[ins[start]]
breakTwo guards keep it honest. A line must start in clear, unvegetated water or mud, or it has no crossing to find. And an edge found right behind a masked gap is thrown away, because the real edge might lie inside the gap.
This kind of measurement is now routine on sandy coasts. Vos et al. (2019) published an open toolkit that extracts shorelines from Landsat and Sentinel-2 to about 10 m, and Luijendijk et al. (2018) used freely available satellite images since 1984 to assess the world’s sandy beaches, 1984 to 2016, finding 24 % of them eroding by more than half a metre a year. The page’s rule is much simpler than theirs, and made for a mud coast.
A rate from noisy years
Each line now has an edge position for most clear years (35 on the Ca Mau east coast, all 38 at Ca Mau west and Soc Trang). Some years are off, for reasons such as haze or a gap the median could not fill. A straight line fitted by least squares would be pulled by such years. The page uses the Theil–Sen estimator instead, after Henri Theil and Sen (1968): take every pair of years, compute the slope between them, and keep the median of all those slopes.
def theil_sen(x: np.ndarray, y: np.ndarray) -> float:
"""Median of all pairwise slopes: a trend that a few bad years cannot drag."""
i, j = np.triu_indices(len(x), 1)
dx = x[j] - x[i]
return float(np.median((y[j] - y[i])[dx > 0] / dx[dx > 0]))Sen showed that this median slope is robust against gross errors, where least squares is not. Only lines with an edge in at least 60 % of the clear years, spread over at least 25 years, get a trend. Figure 1 shows one of them.
On this line the two methods almost agree: −30.0 against −28.7 m a year. They part where a line has a few wild years, by up to 35 m a year on some lines at Bac Lieu; there the median is the safer reading, though nothing here can prove which is right.
The rate of a box is the median over its lines; the page shows the middle half of them as the spread (Figure 2).
| Box | Median | Middle half | Lines with a trend |
|---|---|---|---|
| Ca Mau, east coast | −30.0 m/yr | −46.8 to −28.6 | 119 |
| Ca Mau, west coast | −17.4 m/yr | −18.6 to −15.0 | 100 |
| Bac Lieu, sea dyke | −3.2 m/yr | −4.8 to −1.5 | 119 |
| Ca Mau Cape | −1.0 m/yr | −6.8 to +4.9 | 74 |
| Soc Trang, Vinh Chau | +37.2 m/yr | +17.1 to +47.1 | 101 |
Two results surprised. Soc Trang grows, although the research before the build expected erosion nearby; this box does not show it. And in the Cape box one side grows and the other retreats, so its median near zero hides two opposite coasts.
What others measured
Anthony et al. (2015) measured the delta’s shoreline from SPOT 5 images, 2003 to 2012, and found erosion over more than half of a shoreline over 600 km long, with no identified change in the river’s discharge or in waves and wind; they find it consistent with less mud from the river, sand mining and subsidence. Tamura et al. (2020) add the long view: on the Ca Mau peninsula, the mud supply had fallen sharply by the early 20th century, after a vast network of canals was built, and the peninsula has been eroding since. Phan, Thiel de Vries, and Stive (2015) find that a mangrove belt on the eastern coast needs on average at least 140 m to stay healthy, and that sea dykes built too close squeeze it.
The page’s own numbers do not test any of this. They measure a different edge, in different boxes and years, with 30 m pixels. Where they overlap, on the muddy east coast, both see retreat.
What the measurement cannot see
A dyke stops the edge. Where a dyke holds the line, the edge cannot move inland, so “no change” in front of a dyke is not “stable”. The page says this for the Bac Lieu box.
Planting looks like growth. New planting shows up as growth, as the page says.
30 m pixels. A single year’s step of less than about 30 m is noise; only the trend over decades means something.
One fixed threshold. NDVI 0.3 is a choice, the same for every year and every box. Spikes remain in the yearly chart (on the Ca Mau east coast, for example, in 2019), and their causes were not traced.
Boxes, not the coast. Five boxes of 9 × 9 km, chosen from the literature and the images, not a survey of the whole delta. The names of the boxes (“sea dyke”, “Vinh Chau”) rest on the research notes and the imagery, not on a map of the dykes.
An edge is not a sediment budget. The measurement says where the trees end, not how much mud came or went, nor why. The causes on the page come from the studies it cites, not from these images.
Data and sources
- Imagery: Landsat Collection 2 Level-2 images courtesy of the U.S. Geological Survey (public domain), accessed through the Microsoft Planetary Computer STAC catalogue. Processing, frames and vegetation lines: re:current_analytics.
- The studies behind the page’s causes and choices are listed on the Mekong page.
A reading guide
Seeing coasts from space. The Landsat archive (Crawford et al. 2023), a vegetation index (Tucker 1979), shorelines from satellites (Vos et al. 2019; Luijendijk et al. 2018).
Robust trends. The median of pairwise slopes (Sen 1968).
The Mekong’s coast. (Anthony et al. 2015; Tamura et al. 2020; Phan, Thiel de Vries, and Stive 2015), and the full list on the Mekong page.

