Script Library
AdvancedLand CoverAdvanced
Dynamic World LULC — Annual Change Matrix + Accuracy
10 m near-real-time land-cover, annual mode composites, transition matrix, sample-based accuracy.
Pipeline (4 steps)
- Annual mode of Dynamic World classification (9 classes)
- Build from→to transition matrix between year A and year B
- Sample 2000 random points; compare with ESA WorldCover
- Compute confusion matrix, OA, Kappa, per-class F1
Datasets
- dynamic-world
- esa-worldcover
Simulated previewPaste the script in Earth Engine for live results
Classification legend
Water
Trees
Grass
Crops
Built
Bare
Outputs the script produces
map LULC class map
table Transition matrix
chart Area change by class
export Confusion-matrix export
// ============================================================
// Dynamic World — annual mode + change matrix + accuracy
// ============================================================
var yearA = 2018, yearB = 2024;
function dwMode(y) {
var dw = ee.ImageCollection('GOOGLE/DYNAMICWORLD/V1')
.filterBounds(aoi)
.filterDate(y + '-01-01', (y+1) + '-01-01')
.select('label');
return dw.mode().rename('class_' + y);
}
var a = dwMode(yearA), b = dwMode(yearB);
var transition = a.multiply(100).add(b).rename('transition'); // ABBA pair encoding
var dwViz = {min:0, max:8, palette:['#419BDF','#397D49','#88B053','#7A87C6','#E49635','#DFC35A','#C4281B','#A59B8F','#B39FE1']};
Map.centerObject(aoi, 8);
Map.addLayer(a, dwViz, 'LULC ' + yearA);
Map.addLayer(b, dwViz, 'LULC ' + yearB);
Map.addLayer(transition.updateMask(a.neq(b)), {min:0,max:888,palette:['#fde047','#f97316','#ef4444']}, 'Change');
// Area per class (km²)
var pixelArea = ee.Image.pixelArea().divide(1e6);
[a, b].forEach(function(img, i){
var year = i === 0 ? yearA : yearB;
var areas = pixelArea.addBands(img).reduceRegion({
reducer: ee.Reducer.sum().group(1, 'class'),
geometry: aoi, scale: 30, bestEffort: true, tileScale: 4, maxPixels: 1e13
});
print('Class areas km² (' + year + '):', areas);
});
// Accuracy vs ESA WorldCover (recoded to DW classes)
var wc = ee.ImageCollection('ESA/WorldCover/v200').first().select('Map');
var dwClass = b;
var samples = dwClass.addBands(wc.rename('wc')).sample({
region: aoi, scale: 30, numPixels: 2000, seed: 42, geometries: false, tileScale: 4
});
var cm = samples.errorMatrix('wc', 'class_' + yearB);
print('Confusion matrix:', cm);
print('Overall accuracy:', cm.accuracy());
print('Kappa:', cm.kappa());
Export.image.toDrive({image: transition.clip(aoi), description: 'DW_transition',
folder: 'gee_exports', region: aoi, scale: 30, maxPixels: 1e13,
fileFormat: 'GeoTIFF', formatOptions: {cloudOptimized: true}});# Python sketch (geemap)
import ee
ee.Initialize()