-
Notifications
You must be signed in to change notification settings - Fork 0
/
GEE-land-cover
73 lines (61 loc) · 2.63 KB
/
GEE-land-cover
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Land cover map ('lc') for Polesia is available at
// https://github.com/tpfd/Polesia-Landcover
// First for some data cleaning
// Remove unclassified pixels at boundary
// First need to reclassify unclassified pixels in center of map caused by e.g., clouds
// var reclassified = lc.clip(boundary)
.remap([0], [14]);
// In the land cover map, where the reclassified map equals 14,
// replace the value in the original map with 14
//var lc = lc.where(reclassified.eq(14), 14)
// .selfMask() // Mask out pixels with a value of 0
// Simplify land cover map by grouping land cover types
// var simp = lc.remap([1,2,3,4,5,6,7,8,9,10,11,12,13,14],
[1,1,2,2,1,2,3,4,5,6,7,8,9,10]);
// Define palette for different land cover types
// var newPalette = [
// '336600', // Coniferous forest (1) - dark green
// '33cc33', // Deciduous forest (2) - bright green
// 'ffb3ff', // Meadows (3) - purple
// 'FFFF00', // Agriculture (4) - yellow
// 'cc6600', // Raised bog (5) - brown
// '808000', // Fen and transitional mire (6) - olive green
// 'F0E68C', // Scrub (7) - khaki
// '0000FF', // Water (8) - blue
// '000000', // Urban (9) - black
// 'c2c2d6', // (10) - grey
// ];
// View land cover map
// Map.addLayer(simp, {min: 1, max: 10, palette: newPalette}, 'Simple land cover');
// Name of the land covers
// var newNames = ['Coniferous forest', 'Deciduous forest',
// 'Meadows', 'Agriculture', 'Raised bog', 'Fen and transitional mire', 'Scrub',
// 'Water', 'Urban', 'Unclassified'];
// Add color and and names
// for (var i = 0; i < 10; i++) {
// legend.add(makeRow(newPalette[i], newNames[i]));
// }
// Add legend to map (alternatively you can also print the legend to the console)
// Map.add(legend);
// Explore metadata
print(lc, 'Land cover data');
// print(simp, 'Simple land cover data');
// Extract histogram of land covers within fire/non-fire grid cells
// Loop throught each grid cell as compuationally intensive
var lcFires = pixels.map(function (feature) {
return ee.Feature(feature.geometry(), lc.reduceRegion({
reducer: ee.Reducer.frequencyHistogram(),
geometry: feature.geometry(),
}))
.set('z', feature.get('z')) // Add 'z' IDs to each feature
.set('pix', feature.get('pix')) // Add grid cell 'pix' IDs to each feature
// Fires are made up of multiple grid cells which have the same 'z' ID but all 'pix' values are unique
});
// Samples all land cover pixels that have their centers within the collection grid cells
// Export as CSV
Export.table.toDrive({
collection: lcFires,
folder : "pixels",
description: 'land-cover-pixels',
selectors: ['z', 'pix', 'remapped']
});